-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
162 lines (131 loc) · 6.26 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
162
# This project aims to follow modern cmake guidelines, e.g.
# https://cliutils.gitlab.io/modern-cmake
# Required for Apple Silicon support.
cmake_minimum_required(VERSION 3.19)
include(CMakeDependentOption)
project(
LaunchDarklyCPPSDKs
VERSION 0.1
DESCRIPTION "LaunchDarkly C++ SDK Monorepo (Server/Client)"
LANGUAGES CXX C
)
# Allow BOOST_ROOT to be set by CI without warnings.
if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif ()
if (POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif ()
include(GNUInstallDirs)
option(BUILD_TESTING "Top-level switch for testing. Turn off to disable unit and contract tests." ON)
option(LD_BUILD_SHARED_LIBS "Build the SDKs as shared libraries" OFF)
cmake_dependent_option(LD_DYNAMIC_LINK_BOOST
"Dynamically link boost instead of building with its static libraries"
ON # Default to dynamically linking boost, because we can't provide static libs on all platforms that
# are position-independent.
"LD_BUILD_SHARED_LIBS" # only relevant if building SDK as shared lib
OFF # If not building shared libs, then static link boost instead.
)
cmake_dependent_option(LD_BUILD_UNIT_TESTS
"Build the C++ unit tests."
ON # default to enabling unit tests
"BUILD_TESTING;NOT LD_BUILD_SHARED_LIBS" # only exposed if top-level switch is on, and also only when building
# static libs. This is because we have hidden visibility of symbols by default (to only expose our C API.)
OFF # otherwise, off
)
# If you want to run the unit tests with valgrind, then LD_TESTING_SANITIZERS must of OFF.
cmake_dependent_option(LD_TESTING_SANITIZERS
"Enable sanitizers for unit tests."
ON # default to enabling sanitizers
"LD_BUILD_UNIT_TESTS" # only expose if unit tests enabled..
OFF # otherwise, off
)
cmake_dependent_option(LD_BUILD_CONTRACT_TESTS
"Build contract test service."
OFF # default to disabling contract tests, since they require running a service
"BUILD_TESTING;NOT LD_BUILD_SHARED_LIBS" # only expose if top-level switch is on and using static libs, since C++ symbols needed would be hidden.
OFF # otherwise, off
)
# The general strategy is to produce a fat artifact containing all of our dependencies so users
# only have a single thing to link. We should support this either being a static or shared library.
# Because OpenSSL is a large, and security relevant dependency, we should have a separate option
# to link against that statically or dynamically.
option(LD_DYNAMIC_LINK_OPENSSL
"Dynamically link OpenSSL instead of building with its static library"
OFF # default to linking OpenSSL statically
)
option(LD_BUILD_EXAMPLES "Build hello-world examples." ON)
option(LD_BUILD_REDIS_SUPPORT "Build redis support." OFF)
# If using 'make' as the build system, CMake causes the 'install' target to have a dependency on 'all', meaning
# it will cause a full build. This disables that, allowing us to build piecemeal instead. This is useful
# so that we only need to build the client or server for a given release (if only the client or server were affected.)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
# All projects in this repo should share the same version of 3rd party depends.
# It's the only way to remain sane.
set(CMAKE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (LD_BUILD_UNIT_TESTS)
message(STATUS "LaunchDarkly: building unit tests")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
add_compile_definitions(LAUNCHDARKLY_USE_ASSERT)
if (LD_TESTING_SANITIZERS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=leak")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak")
endif ()
endif ()
include(${CMAKE_FILES}/googletest.cmake)
enable_testing()
endif ()
if (LD_DYNAMIC_LINK_OPENSSL)
message(STATUS "LaunchDarkly: searching for shared OpenSSL library")
set(OPENSSL_USE_STATIC_LIBS OFF)
else ()
message(STATUS "LaunchDarkly: searching for static OpenSSL library")
set(OPENSSL_USE_STATIC_LIBS ON)
endif ()
find_package(OpenSSL REQUIRED)
message(STATUS "LaunchDarkly: using OpenSSL v${OPENSSL_VERSION}")
if (LD_DYNAMIC_LINK_BOOST)
message(STATUS "LaunchDarkly: searching for shared Boost libraries")
set(Boost_USE_STATIC_LIBS OFF)
else ()
message(STATUS "LaunchDarkly: searching for static Boost libraries")
set(Boost_USE_STATIC_LIBS ON)
endif ()
if (LD_BUILD_SHARED_LIBS)
# When building a shared library we hide all symbols
# aside from this we have specifically exported for the C-API.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif ()
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.81 REQUIRED COMPONENTS json url coroutine)
message(STATUS "LaunchDarkly: using Boost v${Boost_VERSION}")
include(${CMAKE_FILES}/certify.cmake)
add_subdirectory(vendor/foxy)
# Common, internal, and server-sent-events are built as "object" libraries.
add_subdirectory(libs/common)
add_subdirectory(libs/internal)
add_subdirectory(libs/server-sent-events)
if (LD_BUILD_REDIS_SUPPORT)
message("LaunchDarkly: building server-side redis support")
add_subdirectory(libs/server-sdk-redis-source)
endif ()
# Built as static or shared depending on LD_BUILD_SHARED_LIBS variable.
# This target "links" in common, internal, and sse as object libraries.
add_subdirectory(libs/client-sdk)
add_subdirectory(libs/server-sdk)
if (LD_BUILD_CONTRACT_TESTS)
message(STATUS "LaunchDarkly: building contract tests")
add_subdirectory(contract-tests)
endif ()
if (LD_BUILD_EXAMPLES)
message(STATUS "LaunchDarkly: building examples")
add_subdirectory(examples)
endif ()