forked from zeromq/zproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
273 lines (234 loc) · 9.73 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8.12)
project(zproject)
enable_language(C)
enable_testing()
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Select flags
if(MSVC)
SET(CMAKE_C_FLAGS_RELEASE "/O2")
else()
SET(CMAKE_C_FLAGS_RELEASE "-O3")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
# Will be used to add flags to pkg-config useful when apps want to statically link
set(pkg_config_libs_private "")
set(pkg_config_names_private "")
########################################################################
# options
########################################################################
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
IF (ENABLE_DRAFTS)
ADD_DEFINITIONS (-DZPROJECT_BUILD_DRAFT_API)
ENDIF (ENABLE_DRAFTS)
########################################################################
# platform.h
########################################################################
include(CheckIncludeFile)
CHECK_INCLUDE_FILE("linux/wireless.h" HAVE_LINUX_WIRELESS_H)
CHECK_INCLUDE_FILE("net/if_media.h" HAVE_NET_IF_MEDIA_H)
include(CheckFunctionExists)
CHECK_FUNCTION_EXISTS("getifaddrs" HAVE_GETIFADDRS)
CHECK_FUNCTION_EXISTS("freeifaddrs" HAVE_FREEIFADDRS)
include(CheckIncludeFiles)
check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H)
if (NOT HAVE_NET_IF_H)
CHECK_INCLUDE_FILE("net/if.h" HAVE_NET_IF_H)
endif()
file(REMOVE "${SOURCE_DIR}/src/platform.h")
file(WRITE "${PROJECT_BINARY_DIR}/platform.h.in" "
#cmakedefine HAVE_LINUX_WIRELESS_H
#cmakedefine HAVE_NET_IF_H
#cmakedefine HAVE_NET_IF_MEDIA_H
#cmakedefine HAVE_GETIFADDRS
#cmakedefine HAVE_FREEIFADDRS
")
configure_file("${PROJECT_BINARY_DIR}/platform.h.in" "${PROJECT_BINARY_DIR}/platform.h")
if (WIN32)
#The MSVC C compiler is too out of date,
#so the sources have to be compiled as c++
if (MSVC AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
enable_language(CXX)
file(GLOB sources "${SOURCE_DIR}/src/*.c")
set_source_files_properties(
${sources}
PROPERTIES LANGUAGE CXX
)
endif()
set(MORE_LIBRARIES ws2_32 Rpcrt4 Iphlpapi)
endif()
# specific case of windows UWP
if( "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND "${CMAKE_SYSTEM_VERSION}" STREQUAL "10.0")
ADD_DEFINITIONS(-DZMQ_HAVE_WINDOWS_UWP)
ADD_DEFINITIONS(-D_WIN32_WINNT=_WIN32_WINNT_WIN10)
endif()
# required libraries for mingw
if (MINGW)
set(MORE_LIBRARIES -lws2_32 -lrpcrt4 -liphlpapi)
endif()
# required libraries for cygwin
if (CYGWIN)
set(MORE_LIBRARIES)
endif()
list(APPEND CMAKE_MODULE_PATH "${SOURCE_DIR}")
set(OPTIONAL_LIBRARIES)
set(OPTIONAL_LIBRARIES_STATIC)
########################################################################
# GSL dependency
########################################################################
find_package(gsl REQUIRED)
IF (GSL_FOUND)
ELSE (GSL_FOUND)
message( FATAL_ERROR "gsl not found." )
ENDIF (GSL_FOUND)
########################################################################
# version
########################################################################
set(ZPROJECT_VERSION_MAJOR 1)
set(ZPROJECT_VERSION_MINOR 1)
set(ZPROJECT_VERSION_PATCH 0)
set(ZPROJECT_VERSION "${ZPROJECT_VERSION_MAJOR}.${ZPROJECT_VERSION_MINOR}.${ZPROJECT_VERSION_PATCH}")
message(STATUS "Detected ZPROJECT Version - ${ZPROJECT_VERSION}")
########################################################################
# includes
########################################################################
set (zproject_headers
)
source_group ("Header Files" FILES ${zproject_headers})
install(FILES ${zproject_headers} DESTINATION include)
########################################################################
# executables
########################################################################
########################################################################
# tests
########################################################################
set(CLASSTEST_TIMEOUT 60 CACHE STRING "Timeout of the selftest of a class")
set(TOTAL_TIMEOUT 600 CACHE STRING "Timout of the total testsuite")
if(UNIX)
find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-reachable=yes
--error-exitcode=1
--suppressions=src/.valgrind.supp")
endif()
set(TEST_CLASSES
)
if (NOT TARGET copy-selftest-ro)
add_custom_target(
copy-selftest-ro ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/src/selftest-ro ${PROJECT_BINARY_DIR}/src/selftest-ro
)
endif()
if (NOT TARGET make-selftest-rw)
add_custom_target(
make-selftest-rw ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/src/selftest-rw
)
endif()
set_directory_properties(
PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_BINARY_DIR}/src/selftest-ro;${PROJECT_BINARY_DIR}/src/selftest-rw"
)
foreach(TEST_CLASS ${TEST_CLASSES})
add_test(
NAME ${TEST_CLASS}
COMMAND zproject_selftest --continue --verbose --test ${TEST_CLASS}
)
IF (WIN32 AND CMAKE_PREFIX_PATH)
file(TO_NATIVE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH_WIN)
set_tests_properties(
${TEST_CLASS}
PROPERTIES ENVIRONMENT "PATH=%PATH%\;${CMAKE_PREFIX_PATH_WIN}\\bin"
)
ENDIF (WIN32 AND CMAKE_PREFIX_PATH)
set_tests_properties(
${TEST_CLASS}
PROPERTIES TIMEOUT ${CLASSTEST_TIMEOUT}
)
set_tests_properties(
${TEST_CLASS}
PROPERTIES DEPENDS "copy-selftest-ro;make-selftest-rw"
)
endforeach(TEST_CLASS)
include(CTest)
########################################################################
# cleanup
########################################################################
if (NOT TARGET distclean)
add_custom_target (distclean @echo Cleaning for source distribution)
endif()
set(cmake_generated ${PROJECT_BINARY_DIR}/CMakeCache.txt
${PROJECT_BINARY_DIR}/cmake_install.cmake
${PROJECT_BINARY_DIR}/Makefile
${PROJECT_BINARY_DIR}/CMakeFiles
${PROJECT_BINARY_DIR}/CTestTestfile.cmake
${PROJECT_BINARY_DIR}/DartConfiguration.tcl
${PROJECT_BINARY_DIR}/Testing
${PROJECT_BINARY_DIR}/compile_commands.json
${PROJECT_BINARY_DIR}/platform.h
${PROJECT_BINARY_DIR}/src/libzproject.pc
${PROJECT_BINARY_DIR}/src/libzproject.so
${PROJECT_BINARY_DIR}/src/zproject_selftest
)
add_custom_command(
DEPENDS clean
COMMENT "distribution clean"
COMMAND rm
ARGS -rf CMakeTmp ${cmake_generated}
TARGET distclean
)
include(ClangFormat OPTIONAL)
########################################################################
# summary
########################################################################
message ("")
message (STATUS "******************* Configuration Summary *******************")
message (STATUS "General:")
message (STATUS " Version : ${VERSION}")
message (STATUS " System : ${CMAKE_SYSTEM_NAME}")
message (STATUS " C compiler : ${CMAKE_C_COMPILER}")
message (STATUS " Debug C flags : ${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS}")
message (STATUS " Release C flags : ${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS}")
message (STATUS " Build type : ${CMAKE_BUILD_TYPE}")
message (STATUS " Static build : ${ZPROJECT_BUILD_STATIC}")
message (STATUS " Shared build : ${ZPROJECT_BUILD_SHARED}")
IF (ENABLE_DRAFTS)
message (STATUS " Draft API : Yes")
ELSE (ENABLE_DRAFTS)
message (STATUS " Draft API : No")
ENDIF (ENABLE_DRAFTS)
message (STATUS "")
message (STATUS "Dependencies:")
include(FeatureSummary)
feature_summary (WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
message (STATUS "")
message (STATUS "Install:")
message (STATUS " Install prefix :" "${CMAKE_INSTALL_PREFIX}")
message (STATUS "")
message (STATUS "************************* Options ***************************")
message (STATUS "Options:")
message (STATUS " Use the Draft API (default = yes):")
message (STATUS " -DENABLE-DRAFTS=[yes|no]")
message (STATUS "")
message (STATUS "*************************************************************")
message (STATUS "Configuration complete! Now procced with:")
message (STATUS " 'make' compile the project")
message (STATUS " 'make test' run the project's selftest")
message (STATUS " 'make install' install the project to ${CMAKE_INSTALL_PREFIX}")
message (STATUS "")
message (STATUS "Further options are:")
message (STATUS " 'ctest -V run test with verbose logging")
message (STATUS " 'ctest -R <test_name>' run a specific test")
message (STATUS " 'ctest -T memcheck' run the project's selftest with")
message (STATUS " valgrind to check for memory leaks")
message (STATUS "")
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################