11cmake_minimum_required (VERSION 3.1)
22project ("cc_tutorial" )
33
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+ #####################################################
813
914set (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 " )
1116
1217include (GNUInstallDirs)
1318
1419find_package (Boost REQUIRED COMPONENTS system )
1520
16- if (FORCE_EXTRA_BOOST_LIBS )
21+ if (OPT_FORCE_EXTRA_BOOST_LIBS )
1722 set (EXTRA_BOOST_TARGETS Boost::date_time Boost::regex )
1823 find_package (Boost COMPONENTS REQUIRED date_time regex )
1924endif ()
@@ -34,29 +39,24 @@ set (COMMON_CLIENT_LIB "common_client")
3439
3540set (cc_compile_file ${LibComms_DIR} /CC_Compile.cmake)
3641if (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)
4045 endif ()
4146
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 ()
4552 endif ()
4653
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 ()
5057
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} )
6060endif ()
6161
6262#######################################################
@@ -117,7 +117,7 @@ function (bin_server type name)
117117 target_link_libraries (
118118 ${bin_name} PRIVATE ${COMMON_SERVER_LIB} cc::comms Boost::system Boost::boost ${CMAKE_THREAD_LIBS_INIT} )
119119
120- if (FORCE_EXTRA_BOOST_LIBS )
120+ if (OPT_FORCE_EXTRA_BOOST_LIBS )
121121 target_link_libraries (
122122 ${bin_name} PRIVATE ${EXTRA_BOOST_TARGETS} )
123123 endif ()
@@ -133,19 +133,11 @@ function (bin_server type name)
133133 ${bin_name} PRIVATE ${PROJECT_SOURCE_DIR} /${type} /${name} /include )
134134
135135 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>
138138 $<$<CXX_COMPILER_ID:MSVC >:-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS>
139139 )
140140
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-
149141 install (TARGETS ${bin_name}
150142 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
151143 )
@@ -159,7 +151,7 @@ function (bin_client type name)
159151 target_link_libraries (
160152 ${bin_name} PRIVATE ${COMMON_CLIENT_LIB} cc::comms Boost::system Boost::boost ${CMAKE_THREAD_LIBS_INIT} )
161153
162- if (FORCE_EXTRA_BOOST_LIBS )
154+ if (OPT_FORCE_EXTRA_BOOST_LIBS )
163155 target_link_libraries (
164156 ${bin_name} PRIVATE ${EXTRA_BOOST_TARGETS} )
165157 endif ()
0 commit comments