forked from pistacheio/pistache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
230 lines (181 loc) · 7.11 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
cmake_minimum_required (VERSION 3.1.3)
project (pistache)
include(GNUInstallDirs)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-missing-field-initializers")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
endif()
option(PISTACHE_BUILD_TESTS "build tests alongside the project" OFF)
option(PISTACHE_ENABLE_NETWORK_TESTS "if tests are built, run ones needing network access" ON)
option(PISTACHE_BUILD_EXAMPLES "build examples alongside the project" OFF)
option(PISTACHE_BUILD_DOCS "build docs alongside the project" OFF)
option(PISTACHE_INSTALL "add pistache as install target (recommended)" ON)
option(PISTACHE_USE_SSL "add support for SSL server" OFF)
if (PISTACHE_BUILD_TESTS)
find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
find_program(CTEST_COVERAGE_COMMAND NAMES gcov)
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if (CMAKE_CXX_CPPCHECK)
message("-- Cppcheck found " ${CMAKE_CXX_CPPCHECK})
list(
APPEND CMAKE_CXX_CPPCHECK
"--enable=all"
"--suppress=*:${PROJECT_SOURCE_DIR}/third-party*"
"--suppress=*:${PROJECT_SOURCE_DIR}/tests*"
)
else()
message("-- Cppcheck not found")
set(CMAKE_CXX_CPPCHECK "")
endif()
INCLUDE(Dart)
add_custom_target(test_memcheck COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --test-action memcheck)
add_custom_target(coverage COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --test-action coverage)
endif()
# CMAKE version less than 3.8 does not understand the CMAKE_CXX_FLAGS
# set to 17, so a manual check if performed on older version
if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else()
set(CMAKE_CXX_STANDARD 14)
endif()
else()
# Clang exports C++17 in std::experimental namespace (tested on Clang 5 and 6).
# This gives an error on date.h external library.
# Following workaround forces Clang to compile at best with C++14
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_STANDARD 14)
elseif (CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
else()
set(CMAKE_CXX_STANDARD 17)
endif()
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (PISTACHE_USE_SSL)
add_definitions(-DPISTACHE_USE_SSL)
link_libraries(-lssl -lcrypto)
endif (PISTACHE_USE_SSL)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
# Set version...
# Retrieve from external file...
file(READ "version.txt" VERSION_FILE)
# Extract version...
# Major...
string(REGEX MATCH "VERSION_MAJOR *([0-9]*)" _ ${VERSION_FILE})
set(VERSION_MAJOR ${CMAKE_MATCH_1})
# Minor...
string(REGEX MATCH "VERSION_MINOR *([0-9]+)" _ ${VERSION_FILE})
set(VERSION_MINOR ${CMAKE_MATCH_1})
# Patch...
string(REGEX MATCH "VERSION_PATCH *([0-9]+)" _ ${VERSION_FILE})
set(VERSION_PATCH ${CMAKE_MATCH_1})
# Git date...
string(REGEX MATCH "VERSION_GIT_DATE *([0-9]+)" _ ${VERSION_FILE})
set(VERSION_GIT_DATE ${CMAKE_MATCH_1})
# Make available in a header file...
configure_file (
"include/pistache/version.h.in"
"include/pistache/version.h"
@ONLY
)
# Install version header...
if(PISTACHE_INSTALL)
install (
FILES
${CMAKE_CURRENT_BINARY_DIR}/include/pistache/version.h
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/pistache/
)
endif()
# Set libraries...
# Minimum...
set(LIBS "-lpistache -lpthread")
# If building with OpenSSL support...
if(PISTACHE_USE_SSL)
set(LIBS "${LIBS} -lssl -lcrypto")
endif(PISTACHE_USE_SSL)
# Configure the pkg-config metadata...
# Initialize the metadata variables and to support remote builds...
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}/)
set(libs ${LIBS})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}/)
set(version ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-git${VERSION_GIT_DATE})
# Perform substitutions...
configure_file (
"libpistache.pc.in"
"libpistache.pc"
@ONLY
)
# Install pkg-config metadata into standard location within the prefix...
if(PISTACHE_INSTALL)
install (
FILES
${CMAKE_CURRENT_BINARY_DIR}/libpistache.pc
DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig/
)
endif()
add_subdirectory (src)
if (PISTACHE_BUILD_EXAMPLES)
add_subdirectory (examples)
endif()
if (PISTACHE_BUILD_TESTS)
find_package(GTest)
if (GTEST_FOUND)
include_directories(${GTEST_INCLUDE_DIRS})
else()
ADD_SUBDIRECTORY (third-party/googletest)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
endif()
enable_testing()
add_subdirectory(tests)
endif()
if (PISTACHE_BUILD_DOCS)
find_package(Doxygen
REQUIRED dot
OPTIONAL_COMPONENTS mscgen dia)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs
COMMENT "Generating doxygen documentation"
VERBATIM)
message("-- Adding doxygen documentation done")
else(DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen need to be installed to generate the doxygen documentation")
endif(DOXYGEN_FOUND)
endif()
# Generate source tarball...
# Define version of source archive...
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
# Generate a .tar.bz2
set(CPACK_SOURCE_GENERATOR "TBZ2")
# Set filename...
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-git${VERSION_GIT_DATE}")
# Don't include these files in the archive...
set(CPACK_SOURCE_IGNORE_FILES
"/build/;/debian/;/prefix/;/.git*;~$;${CPACK_SOURCE_IGNORE_FILES}")
# Include the CPack module for generating the archive and add the standard
# dist target to the generated makefile...
include(CPack)
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)