-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
154 lines (131 loc) · 5.03 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.21...3.28)
# Not ideal to use this global variable, but necessary to make sure that tooling and projects use
# the same version
set(CMAKE_CXX_STANDARD 17)
# strongly encouraged to enable this globally to avoid conflicts between -Wpedantic being enabled
# and -std=c++20 and -std=gnu++20 for example when compiling with PCH enabled
set(CMAKE_CXX_EXTENSIONS NO)
# XXX include(before_project_setup OPTIONAL)
# ===============================
project(
tftpd # ORIG: netkit-tftp v0.17.6
VERSION 1.0.0.1
LANGUAGES CXX
)
# ===============================
# XXX include(build_options OPTIONAL)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include(GNUInstallDirs)
#---------------------------------------------------------------------------------------
# search required packages and libs
#---------------------------------------------------------------------------------------
# find_package(
# Boost 1.81 CONFIG
# COMPONENTS filesystem asio headers
# REQUIRED
# )
# ---- Add other dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info
include(cmake/CPM.cmake)
option(BUILD_SHARED_LIBS "Build shared libraries" YES)
set(BOOST_INCLUDE_LIBRARIES filesystem asio headers)
CPMAddPackage("gh:ClausKlein/[email protected]")
# PackageProject.cmake will be used to make our target installable
# XXX done with boost-cmake! CPMAddPackage("gh:TheLartians/[email protected]")
# see https://github.com/aminya/project_options for more info
CPMAddPackage("gh:aminya/[email protected]")
# XXX list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR})
add_library(
tftpd # FIXME(CK) STATIC
async_tftpd_server.cpp
async_tftpd_server.hpp
tftpd.hpp
tftpd_utils.cpp
tftpd_options.cpp
tftp_subs.cpp
tftp/tftpsubs.h
)
list(TRANSFORM BOOST_INCLUDE_LIBRARIES PREPEND Boost:: OUTPUT_VARIABLE BOOST_TARGETS)
target_link_libraries(${PROJECT_NAME} PUBLIC ${BOOST_TARGETS})
target_compile_definitions(${PROJECT_NAME} PUBLIC BOOST_ASIO_NO_DEPRECATED)
target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Debug")
project_options(
PREFIX
${PROJECT_NAME}
ENABLE_CACHE
ENABLE_COVERAGE
ENABLE_CLANG_TIDY
ENABLE_SANITIZER_ADDRESS
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_LEAK
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
# XXX NO! WARNINGS_AS_ERRORS
# ENABLE_INCLUDE_WHAT_YOU_USE
)
target_link_libraries(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_NAME}_project_warnings>
$<BUILD_INTERFACE:${PROJECT_NAME}_project_options>
)
else()
include(cmake/WarningsAsErrors.cmake)
endif()
#---------------------------------------------------------------------------------------
# Install and export tftpd-targets
#---------------------------------------------------------------------------------------
if(NOT CMAKE_SKIP_INSTALL_RULES)
packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
NAMESPACE ${PROJECT_NAME}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include
INCLUDE_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
# VERSION_HEADER ${VERSION_HEADER_LOCATION}
# EXPORT_HEADER ${EXPORT_HEADER_LOCATION}
COMPATIBILITY SameMajorVersion
DISABLE_VERSION_SUFFIX YES
DEPENDENCIES "Boost 1.81"
)
# NOTE: implicit done! add_library(tftpd::tftpd ALIAS tftpd)
install(FILES async_tftpd_server.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(BUILD_SHARED_LIBS)
install(IMPORTED_RUNTIME_ARTIFACTS ${PROJECT_NAME} RUNTIME_DEPENDENCY_SET
_dependency_set
)
install(
RUNTIME_DEPENDENCY_SET
_dependency_set
POST_EXCLUDE_REGEXES
"${CMAKE_INSTALL_PREFIX}/lib"
RUNTIME
DESTINATION
lib
)
endif()
include(CPack)
endif()
#---------------------------------------------------------------------------------------
# ctest
#---------------------------------------------------------------------------------------
option(NETKIT_TFTP_TESTS "Build test target." ${PROJECT_IS_TOP_LEVEL})
if(NETKIT_TFTP_TESTS)
enable_testing()
add_executable(option_test option_test.cpp async_tftpd_server.hpp)
#NO! CK target_include_directories(option_test SYSTEM PRIVATE include)
target_link_libraries(option_test PRIVATE tftpd)
add_test(NAME option_test COMMAND option_test)
add_executable(tftpd_test tftpd_test.cpp async_tftpd_server.hpp)
target_link_libraries(tftpd_test PRIVATE tftpd)
if(UNIX)
add_test(
NAME tftpd_test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif()
endif()