-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
204 lines (178 loc) · 5.15 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
cmake_minimum_required(VERSION 3.12)
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project(BonDriver_EPGStation LANGUAGES C CXX)
# main project checking
# determine if BonDriver_EPGStation is built as a subproject (using add_subdirectory) or if it is the main project
set(MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
endif()
option(BONDRIVER_EPGSTATION_BUILD_TEST "Build test program." ${MAIN_PROJECT})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
endif()
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Disable yaml-cpp contrib")
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Disable yaml-cpp build tools")
set(YAML_MSVC_SHARED_RT OFF CACHE BOOL "Use static linked runtime for yaml-cpp")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build cpr as static library")
set(BUILD_CPR_TESTS OFF CACHE BOOL "Disable cpr tests building")
if(WIN32)
set(USE_SYSTEM_CURL OFF)
set(USE_OPENSSL OFF)
set(USE_WINSSL ON)
set(CURL_STATICLIB true)
add_definitions(-DCURL_STATICLIB)
else()
find_package(CURL)
if(CURL_FOUND)
set(USE_SYSTEM_CURL ON CACHE BOOL "Use the system curl for faster builds")
endif()
endif()
add_subdirectory(thirdparty/cpr)
add_subdirectory(thirdparty/json)
add_subdirectory(thirdparty/yaml-cpp)
add_library(BonDriver_EPGStation
SHARED
include/IBonDriver.h
include/IBonDriver2.h
include/min_win32_typedef.hpp
include/export.hpp
src/blocking_buffer.cpp
src/blocking_buffer.hpp
src/bon_driver.cpp
src/bon_driver.hpp
src/config.cpp
src/config.hpp
src/epgstation_api.cpp
src/epgstation_api.hpp
src/epgstation_models.hpp
src/epgstation_models_deserialize.hpp
src/library.cpp
src/library.hpp
src/log.cpp
src/log.hpp
src/noncopyable.hpp
src/scope_guard.hpp
src/speed_sampler.cpp
src/speed_sampler.hpp
src/stream_loader.cpp
src/stream_loader.hpp
src/string_utils.cpp
src/string_utils.hpp
)
# Remove "lib" prefix for dll filename
if(WIN32)
set_target_properties(BonDriver_EPGStation PROPERTIES PREFIX "")
endif()
# Copy yaml config file to binary output directory
add_custom_command(
TARGET
BonDriver_EPGStation
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/BonDriver_EPGStation.yml ${CMAKE_BINARY_DIR}/
)
# On Windows, Set Character set (TCHAR) to Unicode
if(WIN32)
target_compile_definitions(BonDriver_EPGStation
PRIVATE
UNICODE
_UNICODE
)
endif()
# Platform-specific compiler macro / flags
if(MSVC)
# For MSVC, static link runtime library (MultiThreaded)
if(${CMAKE_VERSION} VERSION_LESS "3.15")
target_compile_options(BonDriver_EPGStation
PUBLIC
$<$<CONFIG:Debug>:-MTd>
$<$<CONFIG:Release>:-MT>
$<$<CONFIG:RelWithDebInfo>:-MT>
$<$<CONFIG:MinSizeRel>:-MT>
)
else()
set_property(
TARGET
BonDriver_EPGStation
PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
endif()
# For MSVC, disable CRT secure warnings
target_compile_definitions(BonDriver_EPGStation
PRIVATE
_CRT_SECURE_NO_WARNINGS=1
)
elseif(MINGW)
# For MinGW, static linking runtime library
target_compile_options(BonDriver_EPGStation
PUBLIC
-static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive -Wl,-Bdynamic
)
endif()
# Macros
target_compile_definitions(BonDriver_EPGStation
PRIVATE
BONDRIVER_EPGSTATION_EXPORTS=1
)
# Include directories
target_include_directories(BonDriver_EPGStation
PRIVATE
${CPR_INCLUDE_DIRS}
${JSON_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Link directories
#target_link_directories(BonDriver_EPGStation
# PRIVATE
#)
# Linking
target_link_libraries(BonDriver_EPGStation
PRIVATE
${CPR_LIBRARIES}
nlohmann_json::nlohmann_json
yaml-cpp
)
if(MSVC)
# library linkage for MSVC
target_link_libraries(BonDriver_EPGStation
PRIVATE
# libraries
)
elseif(MINGW)
# library linkage for MinGW: Enable full static link
target_link_libraries(BonDriver_EPGStation
PRIVATE
-Wl,-Bstatic
# libraries
-Wl,-Bdynamic
)
else()
# library linkage for other platforms: dynamic link by default
target_link_libraries(BonDriver_EPGStation
PRIVATE
# libraries
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# pthread is needed for gcc
target_link_libraries(BonDriver_EPGStation
PRIVATE
pthread
)
endif()
if(WIN32)
target_link_libraries(BonDriver_EPGStation
PRIVATE
Version
Ws2_32
)
endif()
if(BONDRIVER_EPGSTATION_BUILD_TEST)
add_subdirectory(test)
endif()