1
- cmake_minimum_required (VERSION 3.0 )
1
+ cmake_minimum_required (VERSION 3.10 )
2
2
3
- if (UNIX )
4
- # Ninja creates too many problems while maintaining
5
- # compatibility with old and new versions of Linux/Cmake
6
- set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
7
- endif ()
3
+ # if (UNIX)
4
+ # # Ninja creates too many problems while maintaining
5
+ # # compatibility with old and new versions of Linux/Cmake
6
+ # set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
7
+ # endif()
8
8
9
9
if (DEFINED ENV{RESTC_CPP_VERSION})
10
10
set (RESTC_CPP_VERSION $ENV{RESTC_CPP_VERSION} )
11
11
endif ()
12
12
13
13
if (NOT DEFINED RESTC_CPP_VERSION)
14
- set (RESTC_CPP_VERSION 0.99 .0)
14
+ set (RESTC_CPP_VERSION 0.100 .0)
15
15
endif ()
16
16
17
17
if (NOT DEFINED RESTC_BOOST_VERSION)
@@ -22,6 +22,12 @@ project (restc-cpp VERSION ${RESTC_CPP_VERSION})
22
22
23
23
message (STATUS "Building restc-cpp version ${PROJECT_VERSION} " )
24
24
25
+ include (CheckCXXCompilerFlag)
26
+
27
+ check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
28
+ check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
29
+
30
+
25
31
if (NOT DEFINED INSTALL_RAPIDJSON_HEADERS)
26
32
option (INSTALL_RAPIDJSON_HEADERS "Install rapidjson headers when make install is executed" ON )
27
33
endif ()
@@ -32,6 +38,28 @@ option(RESTC_CPP_AUTORUN_UNIT_TESTS "Run Unit Tests automatically after build" O
32
38
33
39
option (RESTC_CPP_WITH_FUNCTIONALT_TESTS "Enable Functional Testing" ON )
34
40
41
+ set (GTEST_TAG "main" CACHE STRING "Gtest branch to use. Required on older Linux versions because newer gtest requure newer cmake!" )
42
+ set (LOGFAULT_TAG "master" CACHE STRING "Logfault branch to use. Required on older Linux versions because newer gtest requure newer cmake!" )
43
+
44
+ find_package (RapidJSON QUIET )
45
+
46
+ if (NOT RapidJSON_FOUND AND INSTALL_RAPIDJSON_HEADERS)
47
+ message (STATUS "Rapidjson not found. Adding it as an external project." )
48
+ set (RESTC_CPP_EXTERNAL_DEPS ${RESTC_CPP_EXTERNAL_DEPS} externalRapidJson)
49
+ set (restc_cpp_add_rapidjson ON )
50
+ endif ()
51
+
52
+ if (RESTC_CPP_LOG_WITH_LOGFAULT)
53
+ find_path (LOGFAULT logfault/logfault.h)
54
+ if (LOGFAULT)
55
+ message ("Using existing logfault" )
56
+ else ()
57
+ message ("Embedding logfault header only library" )
58
+ set (RESTC_CPP_EXTERNAL_DEPS ${RESTC_CPP_EXTERNAL_DEPS} externalLogfault)
59
+ set (restc_cpp_add_logfault ON )
60
+ endif ()
61
+ endif ()
62
+
35
63
include (cmake_scripts/external-projects.cmake)
36
64
37
65
if (EXISTS ${CMAKE_BINARY_DIR} /conanbuildinfo.cmake)
@@ -68,7 +96,26 @@ option(RESTC_CPP_LOG_JSON_SERIALIZATION "Enable trace logging for json serializa
68
96
69
97
option (RESTC_CPP_WITH_ZLIB "Use zlib" ON )
70
98
71
- option (RESTC_CPP_USE_CPP17 "Use the C++17 standard" ON )
99
+ option (RESTC_CPP_USE_CPP14 "Use the C++14 standard" OFF )
100
+
101
+ option (RESTC_CPP_USE_CPP17 "Use the C++17 standard" OFF )
102
+
103
+ option (RESTC_CPP_USE_CPP20 "Use the C++20 standard" OFF )
104
+
105
+ if (NOT RESTC_CPP_USE_CPP14 AND NOT RESTC_CPP_USE_CPP17 AND NOT RESTC_CPP_USE_CPP20)
106
+ # Check if GCC 12 is being used and default it to C++17
107
+ # https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1887728.html
108
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
109
+ message (STATUS "GCC 12 detected, defaulting to C++17" )
110
+ set (RESTC_CPP_USE_CPP17 ON )
111
+ elseif (COMPILER_SUPPORTS_CXX20)
112
+ set (RESTC_CPP_USE_CPP20 ON )
113
+ elseif (COMPILER_SUPPORTS_CXX17)
114
+ set (RESTC_CPP_USE_CPP17 ON )
115
+ else ()
116
+ set (RESTC_CPP_USE_CPP14 ON )
117
+ endif ()
118
+ endif ()
72
119
73
120
option (RESTC_CPP_THREADED_CTX "Allow asio contextx with multiple therads. Enables thread-safe internal access." OFF )
74
121
@@ -139,7 +186,10 @@ endif()
139
186
message (STATUS "Using ${CMAKE_CXX_COMPILER} " )
140
187
141
188
macro (SET_CPP_STANDARD target )
142
- if (RESTC_CPP_USE_CPP17)
189
+ if (RESTC_CPP_USE_CPP20)
190
+ message (STATUS "Using C++ 20 for ${target} " )
191
+ set_property (TARGET ${target} PROPERTY CXX_STANDARD 20)
192
+ elseif (RESTC_CPP_USE_CPP17)
143
193
message (STATUS "Using C++ 17 for ${target} " )
144
194
set_property (TARGET ${target} PROPERTY CXX_STANDARD 17)
145
195
else ()
@@ -182,7 +232,6 @@ endif()
182
232
if (WIN32 )
183
233
include (cmake_scripts/pch.cmake)
184
234
ADD_MSVC_PRECOMPILED_HEADER(restc-cpp/restc-cpp.h src/pch.cpp ACTUAL_SOURCES)
185
- add_definitions (-DWAR_PCH)
186
235
set (SOURCES ${ACTUAL_SOURCES} src/pch.cpp ${HEADERS} ${RESFILES} )
187
236
else ()
188
237
set (SOURCES ${ACTUAL_SOURCES} )
@@ -199,21 +248,18 @@ target_include_directories(${PROJECT_NAME}
199
248
200
249
SET_CPP_STANDARD(${PROJECT_NAME} )
201
250
202
- if (RESTC_CPP_LOG_WITH_LOGFAULT)
203
- find_path (LOGFAULT logfault/logfault.h)
204
- if (LOGFAULT)
205
- message ("Using existing logfault" )
206
- else ()
207
- message ("Embedding logfault header only library" )
208
- set (RESTC_CPP_EXTERNAL_DEPS ${RESTC_CPP_EXTERNAL_DEPS} externalLogfault)
209
- endif ()
251
+ if (NOT "${RESTC_CPP_EXTERNAL_DEPS} " STREQUAL "" )
252
+ add_dependencies (${PROJECT_NAME} ${RESTC_CPP_EXTERNAL_DEPS} )
210
253
endif ()
211
254
212
- add_dependencies (${PROJECT_NAME} externalRapidJson ${RESTC_CPP_EXTERNAL_DEPS} )
213
-
214
255
if (NOT EMBEDDED_RESTC_CPP)
215
- #set(Boost_USE_MULTITHREADED ON)
216
- find_package (Boost ${RESTC_BOOST_VERSION} REQUIRED COMPONENTS
256
+
257
+ if (CMAKE_VERSION VERSION_GREATER "3.28" )
258
+ set (restc_cpp_boost_find_config CONFIG)
259
+ message ("Using new Boost find config" )
260
+ endif ()
261
+
262
+ find_package (Boost ${RESTC_BOOST_VERSION} REQUIRED ${restc_cpp_boost_find_config} COMPONENTS
217
263
system
218
264
program_options
219
265
filesystem
@@ -223,6 +269,9 @@ if (NOT EMBEDDED_RESTC_CPP)
223
269
chrono
224
270
${BOOST_LOG_DEP}
225
271
)
272
+
273
+ message (STATUS "Boost version found: ${Boost_VERSION} " )
274
+
226
275
target_include_directories (${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS} )
227
276
target_link_libraries (${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES} )
228
277
target_compile_definitions (${PROJECT_NAME} PUBLIC -DBOOST_COROUTINE_NO_DEPRECATION_WARNING=1)
@@ -264,7 +313,7 @@ if (NOT EMBEDDED_RESTC_CPP)
264
313
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO" )
265
314
endif ()
266
315
267
- set (LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR } /lib CACHE PATH "Destination location" )
316
+ set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR } /lib CACHE PATH "Destination location" )
268
317
link_directories (${LIBRARY_OUTPUT_PATH} )
269
318
270
319
include (cmake_scripts/doxygen.cmake)
0 commit comments