1
1
cmake_minimum_required (VERSION 3.1)
2
2
project ("cc_tutorial" )
3
3
4
- option (WARN_AS_ERR "Treat warnings as error" ON )
5
- option (UNIX_USE_CCACHE "Treat warnings as error" ON )
6
- option (FORCE_EXTRA_BOOST_LIBS "Force linking to extra boost libraries" OFF )
7
- option (USE_SANITIZERS "Compile with sanitizers." OFF )
4
+ option (OPT_WARN_AS_ERR "Treat warnings as error" ON )
5
+ option (OPT_USE_CCACHE "Use ccache" OFF )
6
+ option (OPT_FORCE_EXTRA_BOOST_LIBS "Force linking to extra boost libraries" OFF )
7
+ option (OPT_USE_SANITIZERS "Compile with sanitizers." OFF )
8
+
9
+ # Extra configuration variables
10
+ # OPT_CCACHE_EXECUTABLE - Custom ccache executable
11
+
12
+ #####################################################
8
13
9
14
set (CMAKE_CXX_STANDARD 11 CACHE STRING "The C++ standard to use" )
10
- set (MIN_COMMSDSL_VERSION "6.3" )
15
+ set (MIN_COMMSDSL_VERSION "6.3.3 " )
11
16
12
17
include (GNUInstallDirs)
13
18
14
19
find_package (Boost REQUIRED COMPONENTS system )
15
20
16
- if (FORCE_EXTRA_BOOST_LIBS )
21
+ if (OPT_FORCE_EXTRA_BOOST_LIBS )
17
22
set (EXTRA_BOOST_TARGETS Boost::date_time Boost::regex )
18
23
find_package (Boost COMPONENTS REQUIRED date_time regex )
19
24
endif ()
@@ -34,29 +39,24 @@ set (COMMON_CLIENT_LIB "common_client")
34
39
35
40
set (cc_compile_file ${LibComms_DIR} /CC_Compile.cmake)
36
41
if (EXISTS ${cc_compile_file} )
37
- set (warn_as_err_opt )
38
- if (WARN_AS_ERR )
39
- set (warn_as_err_opt WARN_AS_ERR)
42
+ set (extra_opts )
43
+ if (OPT_WARN_AS_ERR )
44
+ list ( APPEND extra_opts WARN_AS_ERR)
40
45
endif ()
41
46
42
- set (ccache_opt)
43
- if (UNIX_USE_CCACHE)
44
- set (ccache_opt USE_CCACHE)
47
+ if (OPT_USE_CCACHE)
48
+ list (APPEND extra_opts USE_CCACHE)
49
+ if (NOT "${OPT_CCACHE_EXECUTABLE} " STREQUAL "" )
50
+ list (APPEND extra_opts CCACHE_EXECTUABLE "${OPT_CCACHE_EXECUTABLE} " )
51
+ endif ()
45
52
endif ()
46
53
47
- include ( ${cc_compile_file} )
48
- cc_compile( ${warn_as_err_opt} ${ccache_opt} )
49
- endif ()
54
+ if (OPT_USE_SANITIZERS )
55
+ list ( APPEND extra_opts DEFAULT_SANITIZERS )
56
+ endif ()
50
57
51
- set (CC_TUTORIAL_SANITIZER_OPTS)
52
- if (USE_SANITIZERS AND (NOT ${CMAKE_VERSION} VERSION_LESS "3.13" ) AND
53
- ((CMAKE_COMPILER_IS_GNUCC) OR ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )))
54
- set (CC_TUTORIAL_SANITIZER_OPTS
55
- -fno-omit-frame-pointer
56
- -fno-sanitize-recover=address
57
- -fsanitize=address
58
- -fno-sanitize-recover=undefined
59
- -fsanitize=undefined)
58
+ include (${cc_compile_file} )
59
+ cc_compile(${extra_opts} )
60
60
endif ()
61
61
62
62
#######################################################
@@ -117,7 +117,7 @@ function (bin_server type name)
117
117
target_link_libraries (
118
118
${bin_name} PRIVATE ${COMMON_SERVER_LIB} cc::comms Boost::system Boost::boost ${CMAKE_THREAD_LIBS_INIT} )
119
119
120
- if (FORCE_EXTRA_BOOST_LIBS )
120
+ if (OPT_FORCE_EXTRA_BOOST_LIBS )
121
121
target_link_libraries (
122
122
${bin_name} PRIVATE ${EXTRA_BOOST_TARGETS} )
123
123
endif ()
@@ -133,19 +133,11 @@ function (bin_server type name)
133
133
${bin_name} PRIVATE ${PROJECT_SOURCE_DIR} /${type} /${name} /include )
134
134
135
135
target_compile_options (${bin_name} PRIVATE
136
- $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-string -conversion ${CC_TUTORIAL_SANITIZER_OPTS} >
137
- $<$<CXX_COMPILER_ID:Clang>:-Wno-old-style-cast -Wno-string -conversion ${CC_TUTORIAL_SANITIZER_OPTS} >
136
+ $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-string -conversion>
137
+ $<$<CXX_COMPILER_ID:Clang>:-Wno-old-style-cast -Wno-string -conversion>
138
138
$<$<CXX_COMPILER_ID:MSVC >:-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS>
139
139
)
140
140
141
-
142
- if (NOT "${CC_TUTORIAL_SANITIZER_OPTS} " STREQUAL "" )
143
- target_link_options (${bin_name} PRIVATE
144
- $<$<CXX_COMPILER_ID:GNU>:${CC_TUTORIAL_SANITIZER_OPTS} >
145
- $<$<CXX_COMPILER_ID:Clang>:${CC_TUTORIAL_SANITIZER_OPTS} >
146
- )
147
- endif ()
148
-
149
141
install (TARGETS ${bin_name}
150
142
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
151
143
)
@@ -159,7 +151,7 @@ function (bin_client type name)
159
151
target_link_libraries (
160
152
${bin_name} PRIVATE ${COMMON_CLIENT_LIB} cc::comms Boost::system Boost::boost ${CMAKE_THREAD_LIBS_INIT} )
161
153
162
- if (FORCE_EXTRA_BOOST_LIBS )
154
+ if (OPT_FORCE_EXTRA_BOOST_LIBS )
163
155
target_link_libraries (
164
156
${bin_name} PRIVATE ${EXTRA_BOOST_TARGETS} )
165
157
endif ()
0 commit comments