-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
198 lines (166 loc) · 6.78 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
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(${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
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")
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)
target_link_libraries(HashTests
fiftyone-device-detection-test-base
fiftyone-hash-cxx)
gtest_discover_tests(HashTests)
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})
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()