forked from launchdarkly/c-client-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
208 lines (161 loc) · 5.62 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0048 NEW)
file(READ "include/launchdarkly/api.h" HeaderVersionFile)
string(REGEX MATCH
"#define LD_SDK_VERSION \"([0-9\\.]+).*\""
_
${HeaderVersionFile}
)
message("Extracted version: ${CMAKE_MATCH_1}")
project(ldclientapi VERSION ${CMAKE_MATCH_1})
option(BUILD_BENCHMARKS "Also build benchmarks" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles")
include(CTest)
if(BUILD_TESTING)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
configure_file(CMakeLists.txt.in
${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
execute_process(COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
enable_testing()
add_subdirectory(tests)
endif()
include(generate_product_version)
if (COVERAGE)
include(CMakeFiles/CodeCoverage.cmake)
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_html(NAME coverage)
endif (COVERAGE)
find_package(CURL REQUIRED)
if(NOT DEFINED MSVC)
set(LD_LIBRARIES pthread m)
endif()
generate_product_version(
WindowsVersionInfo
NAME "ldclientapi"
COMPANY_NAME "Catamorphic"
VERSION_MAJOR ${PROJECT_VERSION_MAJOR}
VERSION_MINOR ${PROJECT_VERSION_MINOR}
VERSION_PATCH ${PROJECT_VERSION_PATCH}
)
set(LD_INCLUDE_PATHS
"src"
"include"
"third-party/include"
"c-sdk-common/include"
"c-sdk-common/src"
${CURL_INCLUDE_DIR}
)
if(APPLE)
set(LD_INCLUDE_PATHS ${LD_INCLUDE_PATHS} "/usr/local/include")
set(LD_PUBLIC_LIBRARIES "-framework CoreFoundation" "-framework IOKit")
endif(APPLE)
file(GLOB SOURCES "src/*" "c-sdk-common/src/*" "third-party/src/*")
if(DEFINED MSVC)
list(APPEND SOURCES "${WindowsVersionInfo}")
endif()
set(LD_LIBRARIES ${LD_LIBRARIES} ${CURL_LIBRARIES})
configure_file(include/launchdarkly/api.h include/launchdarkly/api.h)
# ldclientapi target -----------------------------------------------------------
add_library(ldclientapi ${SOURCES})
target_link_libraries(ldclientapi
PUBLIC ${LD_PUBLIC_LIBRARIES}
PRIVATE ${LD_LIBRARIES}
)
target_include_directories(ldclientapi
PUBLIC "include"
"c-sdk-common/include"
"c-sdk-common/src"
PRIVATE ${LD_INCLUDE_PATHS}
)
target_compile_definitions(ldclientapi
PRIVATE -D LAUNCHDARKLY_CONCURRENCY_ABORT
-D LAUNCHDARKLY_USE_ASSERT
-D LAUNCHDARKLY_DEFENSIVE
)
if(MSVC)
target_compile_definitions(ldclientapi
PRIVATE -D CURL_STATICLIB
-D PCRE_STATIC
-D _CRT_SECURE_NO_WARNINGS
)
else()
target_compile_definitions(ldclientapi
PRIVATE -D __USE_XOPEN
-D _GNU_SOURCE
)
message(STATUS "Extra compile options: ${EXTRA_COMPILE_OPTIONS}")
target_compile_options(ldclientapi
PRIVATE -fno-omit-frame-pointer
-pedantic
-Wall
-Wextra
-Werror
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
-std=c89
${EXTRA_COMPILE_OPTIONS}
)
endif(MSVC)
if(BUILD_SHARED_LIBS)
set_property(TARGET ldclientapi PROPERTY C_VISIBILITY_PRESET hidden)
endif(BUILD_SHARED_LIBS)
if(NOT SKIP_BASE_INSTALL)
INSTALL(
TARGETS ldclientapi
DESTINATION lib
)
INSTALL(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h*"
)
INSTALL(
DIRECTORY ${PROJECT_SOURCE_DIR}/c-sdk-common/include/
DESTINATION include
FILES_MATCHING PATTERN "*.h*"
)
endif()
# ldclientapicpp target --------------------------------------------------------
if(DEFINED MSVC)
add_library(ldclientapicpp "cpp/api.cpp" "${WindowsVersionInfo}")
else()
add_library(ldclientapicpp "cpp/api.cpp")
endif()
target_include_directories(ldclientapicpp PUBLIC "cpp/include")
target_link_libraries(ldclientapicpp PUBLIC ldclientapi)
# test targets -----------------------------------------------------------------
if(BUILD_TESTING)
file(GLOB TEST_UTILS_SRC "test-utils/src/*" "c-sdk-common/test-utils/src/*")
add_library(test-utils STATIC ${TEST_UTILS_SRC})
target_link_libraries(test-utils ldclientapi)
target_include_directories(test-utils
PUBLIC ${LD_INCLUDE_PATHS}
"test-utils/include"
"c-sdk-common/test-utils/include"
)
target_compile_definitions(test-utils
PRIVATE -D LAUNCHDARKLY_USE_ASSERT
-D LAUNCHDARKLY_CONCURRENCY_ABORT
)
endif()
# benchmark targets ------------------------------------------------------------
if(BUILD_BENCHMARKS)
file(GLOB BENCHMARKS "benchmarks/benchmark-*")
foreach(benchmarksource ${BENCHMARKS})
get_filename_component(benchmarksourceleaf ${benchmarksource} NAME)
string(REPLACE ".c" "" benchmarkexe ${benchmarksourceleaf})
add_executable(${benchmarkexe} ${benchmarksource})
target_link_libraries(${benchmarkexe} ldclientapi)
target_include_directories(${benchmarkexe} PRIVATE ${LD_INCLUDE_PATHS})
target_compile_definitions(${benchmarkexe}
PRIVATE -D LAUNCHDARKLY_USE_ASSERT
-D LAUNCHDARKLY_CONCURRENCY_ABORT
)
endforeach(benchmarksource)
endif()