-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathCMakeLists.txt
122 lines (112 loc) · 3.87 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
###
### project properties
###
cmake_minimum_required (VERSION 2.6.2)
project (cppworkshop)
set (APPLICATION_NAME "C++11/14 Workshop")
set (APPLICATION_CODENAME "${PROJECT_NAME}")
set (APPLICATION_COPYRIGHT_YEARS "2016")
set (APPLICATION_VERSION_MAJOR 0)
set (APPLICATION_VERSION_MINOR 1)
set (APPLICATION_VERSION_PATCH 0)
set (APPLICATION_VERSION_TYPE RELEASE)
set (APPLICATION_VERSION_STRING "${APPLICATION_VERSION_MAJOR}")
set (APPLICATION_VERSION_STRING "${APPLICATION_VERSION_STRING}.${APPLICATION_VERSION_MINOR}")
set (APPLICATION_VERSION_STRING "${APPLICATION_VERSION_STRING}.${APPLICATION_VERSION_PATCH}")
set (APPLICATION_VERSION "${APPLICATION_VERSION_STRING}")
set (APPLICATION_VERSION_STRING "${APPLICATION_VERSION_STRING}-${APPLICATION_VERSION_TYPE}")
set (APPLICATION_VENDOR_ID "com.intracom-telecom")
set (APPLICATION_VENDOR_NAME "Intracom Telecom")
set (APPLICATION_VENDOR_URL "www.intracom-telecom.com")
set (APPLICATION_ID "${APPLICATION_VENDOR_ID}.${CMAKE_PROJECT_NAME}")
###
### create verbose makefile
###
set (CMAKE_VERBOSE_MAKEFILE 0)
###
### project executable/library/install paths
###
set (MAINFOLDER ${PROJECT_SOURCE_DIR})
set (BINDIR $ENV{BINDIR})
get_filename_component (BINDIR ${BINDIR} ABSOLUTE)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BINDIR}")
set (LIBDIR $ENV{LIBDIR})
get_filename_component (LIBDIR ${LIBDIR} ABSOLUTE)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${LIBDIR}")
set (INSTALLDIR $ENV{INSTALLDIR})
get_filename_component (INSTALLDIR ${INSTALLDIR} ABSOLUTE)
set (CMAKE_INSTALL_PREFIX "${INSTALLDIR}")
set (INSTALLDIR_BIN $ENV{INSTALLDIR_BIN})
set (INSTALLDIR_LIB $ENV{INSTALLDIR_LIB})
###
### project cmake search directories
###
set (CMAKE_PREFIX_PATH "${MAINFOLDER}")
set (CMAKE_MODULE_PATH "${MAINFOLDER}/tools/share/cmake")
###
### project include directories
###
include_directories ("${MAINFOLDER}/include")
###
### compiler requirements/options
###
# assert C++14 support (CMAKE_CXX_STANDARD* not working on travis)
#set (CMAKE_CXX_STANDARD 14)
#set (CMAKE_CXX_STANDARD_REQUIRED on)
include (CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG ("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG ("-std=gnu++14" COMPILER_SUPPORTS_GNUXX14)
if (COMPILER_SUPPORTS_CXX14)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif (COMPILER_SUPPORTS_GNUXX14)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
else ()
message (FATAL_ERROR "${CMAKE_CXX_COMPILER} lacks C++14 support.")
endif ()
# common flags
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall -Werror -g")
# address sanitizer for debug builds
find_package (ASan)
if (HAVE_ADDRESS_SANITIZER)
set (CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_ASAN}")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CMAKE_EXE_LINKER_FLAGS_ASAN}")
endif ()
# add -fstack-protector-strong
CHECK_CXX_COMPILER_FLAG ("-fstack-protector-strong" COMPILER_SUPPORTS_FSP)
if (COMPILER_SUPPORTS_FSP)
set (CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector-strong")
endif ()
# add -D_FORTIFY_SOURCE=2
CHECK_CXX_COMPILER_FLAG ("-D_FORTIFY_SOURCE=2" COMPILER_SUPPORTS_FORTIFY_SRC)
if (COMPILER_SUPPORTS_FORTIFY_SRC)
set (CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -D_FORTIFY_SOURCE=2")
endif ()
# generate compile_commands.json
set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
###
### visibility of library symbols
###
#set (CMAKE_CXX_VISIBILITY_PRESET hidden)
#set (CMAKE_VISIBILITY_INLINES_HIDDEN ON)
###
### find required packages
###
find_package (Threads REQUIRED)
###
### add build targets
###
enable_testing ()
add_subdirectory (src)
###
### uninstall targets
###
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/tools/share/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target (uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)