-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
161 lines (139 loc) · 5.81 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
cmake_minimum_required(VERSION 2.8.7)
project(libsettings)
################################################################################
# Build Controls
################################################################################
# Only apply defaults when this is the top level project
################################################################################
if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
# When not explicitly provided, default to building shared libraries where possible.
set(BUILD_SHARED_LIBS ON CACHE BOOL "If set, build shared libraries where possible.")
# When not explicitly provided, default to debug release build.
#
# NOTE: CMake project generation sets the cache variable to the empty string on
# initialization. In order to account for this, it is necessary to use the
# explicit 'if' statement in conjunction with the 'FORCE' directive.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"Choose one: None Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE)
endif(NOT CMAKE_BUILD_TYPE)
# Enable static stack analyzer, defaults to off.
option(ENABLE_STACK_ANALYSIS "Enable stack analysis. Requires gcc." OFF)
# Selectively enable python support, defaults to on.
option(libsettings_ENABLE_PYTHON "Enable building of python module" ON)
endif()
################################################################################
# Include Modules
################################################################################
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common")
include(GNUInstallDirs)
include(CCache)
include(SwiftCmakeOptions)
if(MSVC)
message(STATUS "Skipping unit tests, MSVC detected")
set(disable_tests TRUE)
elseif(SKIP_UNIT_TESTS)
message(STATUS "Skipping unit tests requested")
set(disable_tests TRUE)
else()
set(disable_tests FALSE)
endif()
swift_create_project_options(
HAS_TESTS
DISABLE_TEST_COMPONENTS ${disable_tests}
TEST_PACKAGES "Googletest"
)
include(ClangFormat)
swift_setup_clang_format()
include(OldClangTidy)
swift_setup_clang_tidy(PATTERNS "src/*.c")
################################################################################
# Source Code Configuration
################################################################################
################################################################################
# Third party.
################################################################################
################################################################################
# Compilation Settings
################################################################################
# Build-type dependent flags.
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -s")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -s")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_CXX_STANDARD 11)
# Setup flags for Code Coverage build mode
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} --coverage" CACHE STRING
"Flags used by the C compiler for building with code coverage."
FORCE)
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage" CACHE STRING
"Flags used for linking binaries with code coverage."
FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage" CACHE STRING
"Flags used by the shared libraries linker during builds with code coverage."
FORCE)
mark_as_advanced(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
# Set project version using Git tag and hash.
execute_process(
COMMAND git describe --dirty --tags --always
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_VERSION_FOUND
ERROR_QUIET
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_VERSION_FOUND)
set(VERSION "unknown")
else (GIT_VERSION_FOUND)
set(VERSION ${GIT_VERSION})
endif (GIT_VERSION_FOUND)
# Some compiler options used globally
if (NOT MSVC)
set(CMAKE_C_FLAGS
"-Wall -Wextra -Wno-strict-prototypes -Werror -fno-unwind-tables \
-fno-asynchronous-unwind-tables -Wimplicit -Wshadow -Wswitch-default \
-Wswitch-enum -Wundef -Wuninitialized -Wcast-align -Wformat=2 \
-Wimplicit-function-declaration -Wredundant-decls -Wformat-security \
-ggdb ${CMAKE_C_FLAGS}")
endif (NOT MSVC)
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-warning-option -Wno-error=typedef-redefinition")
if (CMAKE_C_FLAGS MATCHES "-fsanitize=")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/sanitize-ignorelist.txt")
endif()
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_FLAGS MATCHES "-fsanitize=")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/sanitize-ignorelist.txt")
endif()
endif()
if (ENABLE_STACK_ANALYSIS AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "Enabling stack analysis.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-usage -fstack-check")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-usage -fstack-check")
endif ()
################################################################################
# Targets
################################################################################
option(libsbp_ENABLE_TESTS "" OFF)
option(libsbp_ENABLE_DOCS "" OFF)
find_package(Sbp REQUIRED)
option(libswiftnav_ENABLE_TESTS "" OFF)
option(libswiftnav_ENABLE_TEST_LIBS "" OFF)
find_package(Swiftnav REQUIRED)
add_subdirectory(src)
if(libsettings_ENABLE_PYTHON)
add_subdirectory(python)
endif()
if(libsettings_BUILD_TESTS)
add_subdirectory(tests)
endif()