-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
206 lines (174 loc) · 7.65 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(snt VERSION 0.13.1 LANGUAGES C)
# Build shared/dynamic library option
OPTION(BUILD_SHARED_LIBS "Build package with shared libraries." ON)
IF(NOT BUILD_SHARED_LIBS)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
SET(LINK_SEARCH_START_STATIC TRUE)
ENDIF()
OPTION(BUILD_WITH_COVERAGE "Enable profiling and coverage report analysis." OFF)
OPTION(BUILD_WITH_PROFILER "Enable profiling." OFF)
OPTION(BUILD_WITH_INSTALL "Disable this if you want to use as a submodule." ON)
OPTION(BUILD_WITH_UBSAN "" OFF)
OPTION(BUILD_WITH_ASAN "Enable AddressSanitizer." OFF)
OPTION(BUILD_OPT_BUILD_PACKAGES "Set to ON to generate CPack configuration files and packaging targets" OFF)
OPTION(BUILD_WITH_DEBUG_BOUNDSCHECK "Array/Pointer BoundsChecking, buffer overflow protection. Used in debug only." OFF)
OPTION(BUILD_WITH_TEST "Enable Testing." OFF)
IF(MSVC)
OPTION(BUILD_INSTALL_PDB
"Install MSVC debug files."
ON
)
IF(NOT(MSVC_VERSION LESS 1900))
# Multibyte character set is deprecated since at least MSVC2015 (possibly earlier)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
ENDIF()
ENDIF()
# Set version of the project.
SET(SNT_VERSION_MAJOR 0)
SET(SNT_VERSION_MINOR 13)
SET(SNT_VERSION_REVISION 1)
SET(SNT_VERSION_STATE b)
SET(VERSION ${SNT_VERSION_MAJOR}.${SNT_VERSION_MINOR}${SNT_VERSION_STATE}${SNT_VERSION_REVISION})
SET(PROJECT_VERSION "${VERSION}")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
SET(LIBSNT_COMPONENT "libsnt${SNT_VERSION_MAJOR}.${SNT_VERSION_MINOR}.${SNT_VERSION_REVISION}")
SET(LIBSNT-DEV_COMPONENT "libsnt${SNT_VERSION_MAJOR}.${SNT_VERSION_MINOR}.${SNT_VERSION_REVISION}-dev")
SET(CPACK_COMPONENTS_ALL ${LIBSNT_COMPONENT} ${LIBSNT-DEV_COMPONENT} snt-dev)
# GCC compiler flag options.
IF((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT CMAKE_COMPILER_IS_MINGW)
IF(BUILD_SHARED_LIBS AND CMAKE_SIZEOF_VOID_P EQUAL 8) # -fPIC is only required
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ENDIF()
ADD_DEFINITIONS(-DSNT_MAJOR=${SNT_VERSION_MAJOR} -DSNT_MINOR=${SNT_VERSION_MINOR})
ADD_DEFINITIONS(-DSNT_STR_VERSION="${VERSION}")
ADD_DEFINITIONS(-Werror)
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
MESSAGE(STATUS "Compile for release.")
ADD_DEFINITIONS(-DNDEBUG=1)
ADD_DEFINITIONS(-O3)
SET(CMAKE_RELEASE TRUE)
ELSE()
MESSAGE(STATUS "Compile for debug.")
ADD_DEFINITIONS(-D_DEBUG)
ADD_DEFINITIONS(-g3 -O0)
SET(CMAKE_DEBUG TRUE)
#
IF(BUILD_WITH_UBSAN)
MESSAGE(STATUS "Undefined Behavior sanitizer enabled")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
ENDIF()
ENDIF()
#
IF(BUILD_WITH_COVERAGE)
MESSAGE(STATUS "Building with coverage")
SET(GCC_COVERAGE_COMPILE_FLAGS "--coverage -fprofile-arcs -ftest-coverage")
SET(GCC_COVERAGE_LINK_FLAGS "-lgcov")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
ENDIF()
#
IF(BUILD_WITH_PROFILER)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
ENDIF()
#
IF(BUILD_WITH_ASAN)
MESSAGE(STATUS "AddressSanitizer enabled")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
ENDIF()
ELSEIF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long ${CMAKE_CXX_FLAGS}")
SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}")
ELSEIF(MSVC)
# Enable multi-core compilation with MSVC
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # clang-cl
ADD_COMPILE_OPTIONS(/bigobj /W4 /WX)
ELSE() # msvc
ADD_COMPILE_OPTIONS(/MP /bigobj /W4 /WX)
ENDIF()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /Zi /Od")
ELSEIF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET(CMAKE_CXX_FLAGS "-g -fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long ${CMAKE_CXX_FLAGS}")
SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}")
ELSEIF(CMAKE_COMPILER_IS_MINGW)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -Wa,-mbig-obj ${CMAKE_CXX_FLAGS}")
SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}")
ADD_DEFINITIONS(-U__STRICT_ANSI__)
ELSE()
ENDIF()
# Define all file lists.
FILE(GLOB SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
FILE(GLOB HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
SET(SNT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
FIND_PACKAGE(ZLIB)
IF(ZLIB_FOUND)
MESSAGE(STATUS "libz found: ${ZLIB_LIBRARIES}.")
ELSE()
ENDIF()
FIND_PACKAGE(OpenSSL)
IF(OPENSSL_FOUND)
MESSAGE(STATUS "OpenSSL found: ${OPENSSL_LIBRARIES}.")
ELSE()
ENDIF()
# Main exectuable program.
ADD_EXECUTABLE(snt ${SOURCE_FILES} ${HEADER_FILES})
TARGET_LINK_LIBRARIES(snt m ${OPENSSL_CRYPTO_LIBRARY} lz4 pthread ${ZLIB_LIBRARIES} ${OPENSSL_SSL_LIBRARY} bz2)
#
SET_TARGET_PROPERTIES(snt PROPERTIES
COMPILE_FLAGS "${ZIP_CFLAGS_OTHER}")
TARGET_INCLUDE_DIRECTORIES(snt PRIVATE ${ZLIB_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} PUBLIC ${SNT_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES(snt PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
IF(BUILD_WITH_INSTALL)
INSTALL(TARGETS snt DESTINATION bin)
ENDIF()
IF(UNIX)
# make cert
# make install_cert
# install_wireshark
ENDIF()
# SNT_OPT_BUILD_PACKAGES
IF(CMAKE_CPACK_COMMAND AND UNIX)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "valdemar lindberg") # required
# Packing information
SET(CPACK_PACKAGE_NAME "snt${SNT_VERSION_MAJOR}.${SNT_VERSION_MINOR}")
SET(CPACK_PACKAGE_CONTACT "" CACHE STRING "Package maintainer and PGP signer.")
SET(CPACK_PACKAGE_VENDOR "https://github.com/voldien/snt")
SET(CPACK_PACKAGE_DISPLAY_NAME "snt ${SNT_VERSION_MAJOR}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY " - snt")
SET(CPACK_PACKAGE_VERSION "${SNT_VERSION_MAJOR}.${SNT_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_MAJOR "${SNT_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${SNT_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${SNT_VERSION_REVISION}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "snt${SNT_VERSION_MINOR}.${SNT_VERSION_MINOR}")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
STRING(TOUPPER ${LIBSNT_COMPONENT} "LIBSNT_COMPONENT_UPPER")
STRING(TOUPPER ${LIBSNT-DEV_COMPONENT} "LIBSNT-DEV_COMPONENT_UPPER")
SET(CPACK_COMPONENT_${LIBSNT_COMPONENT_UPPER}_DISPLAY_NAME "libraries")
SET(CPACK_COMPONENT_${LIBSNT-DEV_COMPONENT_UPPER}_DISPLAY_NAME "common headers and installs")
SET(CPACK_COMPONENT_${LIBSNT-DEV_COMPONENT_UPPER}_DEPENDS $ "{LIBSNT_COMPONENT}")
SET(CPACK_COMPONENT_SNT-DEV_DISPLAY_NAME "${CPACK_COMPONENT_${LIBSNT-DEV_COMPONENT}_DISPLAY_NAME}")
SET(CPACK_COMPONENT_SNT-DEV_DEPENDS "${LIBSNT-DEV_COMPONENT}")
SET(CPACK_DEBIAN_BUILD_DEPENDS debhelper cmake zlib1g-dev pkg-config)
# debian
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
SET(CPACK_DEBIAN_CMAKE_OPTIONS "-DBUILD_WITH_DOCS=OFF -DBUILD_TEST=OFF")
SET(CPACK_DEBIAN_PACKAGE_SECTION "libs")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_COMPONENTS_ALL}")
SET(CPACK_DEBIAN_PACKAGE_SUGGESTS)
SET(cPACK_DEBIAN_PACKAGE_NAME "snt")
SET(CPACK_DEBIAN_PACKAGE_REMOVE_SOURCE_FILES workspaces test docs obj packaging)
SET(CPACK_DEBIAN_PACKAGE_SOURCE_COPY svn export --force)
SET(CPACK_DEBIAN_CHANGELOG)
SET(DPUT_HOST "" CACHE STRING "PPA repository to upload the debian sources")
INCLUDE(DebSourcePPA)
INCLUDE(CPack)
ENDIF()