-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
232 lines (195 loc) · 8.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
cmake_minimum_required(VERSION 3.24)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
# Include the common API
include(CMakeDependentOption)
cmake_dependent_option(FIFTYONE_COMMON_CXX_BUILD_TESTING "" OFF "BUILD_TESTING" OFF)
include(${CMAKE_CURRENT_LIST_DIR}/src/common-cxx/CMakeLists.txt NO_POLICY_SCOPE)
project(51DegreesDeviceDetection VERSION 4.0.1 LANGUAGES CXX C)
set(DD ${CMAKE_CURRENT_LIST_DIR}/src)
set(HASH ${CMAKE_CURRENT_LIST_DIR}/src/hash)
# Device Detection libraries
#Compute is test coverage enabled
string(TOLOWER "${CMAKE_BUILD_TYPE}" lower_CMAKE_BUILD_TYPE)
if (NOT MSVC AND "${lower_CMAKE_BUILD_TYPE}" STREQUAL "debug")
set(TESTCOVERAGE_ENABLED TRUE)
else()
set(TESTCOVERAGE_ENABLED FALSE)
endif()
message("-- TESTCOVERAGE_ENABLED=${TESTCOVERAGE_ENABLED}")
FILE(GLOB DDC_SRC ${DD}/*.c)
FILE(GLOB DDC_H ${DD}/*.h)
add_library(fiftyone-device-detection-c ${DDC_SRC} ${DDC_H})
if (MSVC)
target_link_libraries(fiftyone-device-detection-c fiftyone-common-c)
else()
target_link_libraries(fiftyone-device-detection-c fiftyone-common-c m)
endif()
FILE(GLOB DDCPP_SRC ${DD}/*.cpp)
FILE(GLOB DDCPP_H ${DD}/*.hpp)
add_library(fiftyone-device-detection-cxx ${DDCPP_SRC} ${DDCPP_H})
target_link_libraries(fiftyone-device-detection-cxx
fiftyone-device-detection-c
fiftyone-common-cxx)
set_target_properties(fiftyone-device-detection-c fiftyone-device-detection-cxx
PROPERTIES FOLDER "Device Detection")
# Hash libraries
FILE(GLOB HASHC_SRC ${HASH}/*.c)
FILE(GLOB HASHC_H ${HASH}/*.h)
add_library(fiftyone-hash-c ${HASHC_SRC} ${HASHC_H})
target_link_libraries(fiftyone-hash-c fiftyone-device-detection-c)
if (MSVC)
target_compile_options(fiftyone-hash-c PRIVATE "/D_CRT_SECURE_NO_WARNINGS" "/W4" "/WX")
else()
target_compile_options(fiftyone-hash-c PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror")
if (MINGW)
target_compile_options(fiftyone-hash-c PRIVATE "-Wa,-mbig-obj")
endif()
endif()
FILE(GLOB HASHCPP_SRC ${HASH}/*.cpp)
FILE(GLOB HASHCPP_H ${HASH}/*.hpp)
add_library(fiftyone-hash-cxx ${HASHCPP_SRC} ${HASHCPP_H})
target_link_libraries(fiftyone-hash-cxx fiftyone-hash-c fiftyone-device-detection-cxx)
if (MSVC)
target_compile_options(fiftyone-hash-cxx PRIVATE "/D_CRT_SECURE_NO_WARNINGS" "/W4" "/WX")
else()
target_compile_options(fiftyone-hash-cxx PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror")
# Test coverage instrumentation
if (TESTCOVERAGE_ENABLED)
add_library(fiftyone-device-detection-c-cov ${DDC_SRC} ${DDC_H})
target_link_libraries(fiftyone-device-detection-c-cov fiftyone-common-c m)
target_compile_options(fiftyone-device-detection-c-cov PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror" "--coverage")
add_library(fiftyone-device-detection-cxx-cov ${DDCPP_SRC} ${DDCPP_H})
target_link_libraries(fiftyone-device-detection-cxx-cov fiftyone-device-detection-c-cov fiftyone-common-cxx)
target_compile_options(fiftyone-device-detection-cxx-cov PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror" "--coverage")
add_library(fiftyone-hash-c-cov ${HASHC_SRC} ${HASHC_H})
target_link_libraries(fiftyone-hash-c-cov fiftyone-device-detection-c-cov)
target_compile_options(fiftyone-hash-c-cov PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror" "--coverage")
add_library(fiftyone-hash-cxx-cov ${HASHCPP_SRC} ${HASHCPP_H})
target_link_libraries(fiftyone-hash-cxx-cov fiftyone-hash-c-cov fiftyone-device-detection-cxx-cov)
target_compile_options(fiftyone-hash-cxx-cov PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror" "--coverage")
endif()
endif()
set_target_properties(fiftyone-hash-c fiftyone-hash-cxx
PROPERTIES FOLDER "Device Detection/Hash")
# Shared library
file(WRITE null.cpp "")
add_library(fiftyone-device-detection-complete SHARED null.cpp)
target_link_libraries(fiftyone-device-detection-complete fiftyone-hash-cxx)
if (MSVC)
target_compile_options(fiftyone-device-detection-complete PRIVATE "/D_CRT_SECURE_NO_WARNINGS" "/W4" "/WX")
else()
target_compile_options(fiftyone-device-detection-complete PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror")
endif()
set_target_properties(fiftyone-device-detection-complete PROPERTIES PUBLIC_HEADER "${HASH}/hash.h")
install(TARGETS fiftyone-device-detection-complete DESTINATION fiftyone-device-detection-complete
RUNTIME DESTINATION lib
ARCHIVE DESTINATION lib/static
PUBLIC_HEADER DESTINATION include
# Set this to optional, otherwise it will interfere with builds which
# include this CMake file.
OPTIONAL)
# Examples
MESSAGE("-- Looking for examples...")
foreach (api "Hash")
foreach (langext c cpp)
string( TOUPPER ${langext} upperlangext)
file(GLOB files ${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/*.${langext})
foreach(file ${files})
string( REPLACE ".${langext}" "" name ${file})
string( REPLACE "${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/" "" name ${name})
string( APPEND name ${api} ${upperlangext})
string( TOLOWER ${api} lowerapi)
if (NOT ${name} MATCHES ".*ExampleBase.*")
if("${langext}" STREQUAL "cpp")
MESSAGE("-- Found C++ example '${name}'")
add_executable(${name} ${file}
${CMAKE_CURRENT_LIST_DIR}/examples/C/${api}/ExampleBase.c
${CMAKE_CURRENT_LIST_DIR}/examples/C/${api}/ExampleBase.h
${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/ExampleBase.cpp
${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/ExampleBase.hpp)
if (MSVC)
target_link_libraries(${name} fiftyone-${lowerapi}-cxx)
else()
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_include_directories(${name} PRIVATE "/usr/local/include")
target_link_directories(${name} PRIVATE "/usr/local/lib")
endif()
target_link_libraries(${name} fiftyone-${lowerapi}-cxx)
endif()
elseif("${langext}" STREQUAL "c")
MESSAGE("-- Found C example '${name}'")
add_executable(${name} ${file}
${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/ExampleBase.c
${CMAKE_CURRENT_LIST_DIR}/examples/${upperlangext}/${api}/ExampleBase.h)
if (MSVC)
target_link_libraries(${name} fiftyone-${lowerapi}-c)
else()
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_include_directories(${name} PRIVATE "/usr/local/include")
target_link_directories(${name} PRIVATE "/usr/local/lib")
endif()
target_link_libraries(${name} fiftyone-${lowerapi}-c)
endif()
endif()
set_target_properties(${name}
PROPERTIES FOLDER
"Examples/Device Detection/${api}/${upperlangext}")
if (MSVC)
target_compile_options(${name} PRIVATE "/D_CRT_SECURE_NO_WARNINGS" "/W4" "/WX")
target_link_options(${name} PRIVATE "/WX")
else()
target_compile_options(${name} PRIVATE ${COMPILE_OPTION_DEBUG} "-Werror")
endif()
endif()
endforeach()
endforeach()
endforeach()
# Tests
if(BUILD_TESTING)
set(COMMON_TEST ${CMAKE_CURRENT_LIST_DIR}/src/common-cxx/tests)
set(HASH_TEST ${CMAKE_CURRENT_LIST_DIR}/test/hash)
set(DD_TEST ${CMAKE_CURRENT_LIST_DIR}/test)
FILE(GLOB DD_TEST_SRC ${DD_TEST}/*.cpp)
FILE(GLOB DD_TEST_H ${DD_TEST}/*.hpp)
FILE(GLOB HASH_TEST_SRC ${HASH_TEST}/*.cpp)
FILE(GLOB HASH_TEST_H ${HASH_TEST}/*.hpp)
add_library(fiftyone-device-detection-test-base
${DD_TEST_SRC} ${DD_TEST_H}
${COMMON_TEST}/Base.cpp
${COMMON_TEST}/EngineTests.cpp
${COMMON_TEST}/ExampleTests.cpp)
target_link_libraries(fiftyone-device-detection-test-base gtest_main)
if (NOT MSVC)
target_compile_options(fiftyone-device-detection-test-base PRIVATE ${COMPILE_OPTION_DEBUG})
endif()
set_target_properties(fiftyone-device-detection-test-base PROPERTIES FOLDER "Tests")
add_executable(HashTests
${HASH_TEST_SRC} ${HASH_TEST_H}
${CMAKE_CURRENT_LIST_DIR}/examples/CPP/Hash/ExampleBase.cpp
${CMAKE_CURRENT_LIST_DIR}/examples/CPP/Hash/ExampleBase.hpp)
if (TESTCOVERAGE_ENABLED)
target_link_libraries(HashTests fiftyone-device-detection-test-base fiftyone-hash-cxx-cov)
target_link_options(HashTests PRIVATE "-fprofile-arcs" "-ftest-coverage")
else()
target_link_libraries(HashTests fiftyone-device-detection-test-base fiftyone-hash-cxx)
endif()
gtest_discover_tests(HashTests DISCOVERY_MODE PRE_TEST)
set_target_properties(HashTests PROPERTIES FOLDER "Tests")
if (MSVC)
target_compile_options(HashTests PRIVATE "/D_CRT_SECURE_NO_WARNINGS" "/W4" "/WX")
target_link_options(HashTests PRIVATE "/WX")
else ()
target_compile_options(HashTests PRIVATE ${COMPILE_OPTION_DEBUG})
if (NOT TESTCOVERAGE_ENABLED)
target_link_options(HashTests PRIVATE "-fsanitize=address")
endif()
endif()
if (CMAKE_COMPILER_IS_GNUCC)
target_compile_options(HashTests PRIVATE "-Wall" "-Werror" "-Wno-unused-variable" "-Wno-unused-result" "-Wno-unused-but-set-variable")
if (MINGW)
target_compile_options(HashTests PRIVATE "-Wa,-mbig-obj")
endif()
endif()
endif()