forked from xsco/libdjinterop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
295 lines (260 loc) · 10.6 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
cmake_minimum_required(VERSION 3.10)
project(libdjinterop
VERSION 0.19.2
DESCRIPTION "C++ library providing access to DJ record libraries")
set(PROJECT_HOMEPAGE_URL "https://github.com/xsco/libdjinterop")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(POLICY CMP0074)
# CMP0074: find_package() uses <PackageName>_ROOT variables.
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0076)
# CMP0076: target_sources() command converts relative paths to absolute.
cmake_policy(SET CMP0076 NEW)
endif()
# Require C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(MSVC)
add_compile_options("/W4" "$<$<CONFIG:RELEASE>:/O2>")
# Ask MSVC to populate the __cplusplus macro properly.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
else()
add_compile_options("-Wall" "$<$<CONFIG:RELEASE>:-O3>")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options("-stdlib=libc++")
endif()
endif()
# Build shared a library by default.
option(BUILD_SHARED_LIBS "Build shared library" ON)
# Option to use either system SQLite or embedded SQLite.
option(SYSTEM_SQLITE "Use system installation of SQLite" ON)
# Require zlib >= 1.2.8
set(ZLIB_MIN_VERSION 1.2.8)
find_package(ZLIB ${ZLIB_MIN_VERSION} REQUIRED)
add_library(
DjInterop
src/djinterop/impl/crate_impl.cpp
src/djinterop/impl/database_impl.cpp
src/djinterop/impl/track_impl.cpp
src/djinterop/engine/encode_decode_utils.cpp
src/djinterop/engine/engine.cpp
src/djinterop/engine/schema/schema_1_6_0.cpp
src/djinterop/engine/schema/schema_1_7_1.cpp
src/djinterop/engine/schema/schema_1_9_1.cpp
src/djinterop/engine/schema/schema_1_11_1.cpp
src/djinterop/engine/schema/schema_1_13_0.cpp
src/djinterop/engine/schema/schema_1_13_1.cpp
src/djinterop/engine/schema/schema_1_13_2.cpp
src/djinterop/engine/schema/schema_1_15_0.cpp
src/djinterop/engine/schema/schema_1_17_0.cpp
src/djinterop/engine/schema/schema_1_18_0_desktop.cpp
src/djinterop/engine/schema/schema_1_18_0_os.cpp
src/djinterop/engine/schema/schema_2_18_0.cpp
src/djinterop/engine/schema/schema_2_20_1.cpp
src/djinterop/engine/schema/schema_2_20_2.cpp
src/djinterop/engine/schema/schema_2_20_3.cpp
src/djinterop/engine/schema/schema.cpp
src/djinterop/engine/v1/engine_crate_impl.cpp
src/djinterop/engine/v1/engine_database_impl.cpp
src/djinterop/engine/v1/engine_storage.cpp
src/djinterop/engine/v1/engine_track_impl.cpp
src/djinterop/engine/v1/performance_data_format.cpp
src/djinterop/engine/v2/beat_data_blob.cpp
src/djinterop/engine/v2/change_log_table.cpp
src/djinterop/engine/v2/crate_impl.cpp
src/djinterop/engine/v2/database_impl.cpp
src/djinterop/engine/v2/engine_library.cpp
src/djinterop/engine/v2/information_table.cpp
src/djinterop/engine/v2/loops_blob.cpp
src/djinterop/engine/v2/overview_waveform_data_blob.cpp
src/djinterop/engine/v2/playlist_table.cpp
src/djinterop/engine/v2/playlist_entity_table.cpp
src/djinterop/engine/v2/quick_cues_blob.cpp
src/djinterop/engine/v2/track_data_blob.cpp
src/djinterop/engine/v2/track_table.cpp
src/djinterop/engine/v2/track_impl.cpp
src/djinterop/crate.cpp
src/djinterop/database.cpp
src/djinterop/track.cpp
src/djinterop/util/chrono.cpp
src/djinterop/util/filesystem.cpp
src/djinterop/util/random.cpp)
set_target_properties(DjInterop PROPERTIES
OUTPUT_NAME "djinterop"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
target_compile_definitions(DjInterop PUBLIC DJINTEROP_SOURCE)
get_target_property(DJINTEROP_LIBRARY_TYPE DjInterop TYPE)
if(DJINTEROP_LIBRARY_TYPE STREQUAL "STATIC_LIBRARY")
set(DJINTEROP_STATIC ON)
endif()
# Generate config.hpp based on build-time environment.
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(optional DJINTEROP_STD_OPTIONAL)
CHECK_INCLUDE_FILE_CXX(experimental/optional DJINTEROP_STD_EXPERIMENTAL_OPTIONAL)
configure_file(
include/djinterop/config.hpp.in
include/djinterop/config.hpp)
include(GNUInstallDirs)
set(DJINTEROP_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/djinterop")
target_include_directories(
DjInterop PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${DJINTEROP_INSTALL_INCLUDEDIR}>)
target_include_directories(
DjInterop PRIVATE
${ZLIB_INCLUDE_DIRS}
ext/sqlite_modern_cpp
ext/date
src)
target_link_libraries(
DjInterop PUBLIC
${ZLIB_LIBRARIES})
if(SYSTEM_SQLITE)
# Search for system installation of SQLite and use that.
set(SQLITE_MIN_VERSION 3.11)
find_package(SQLite3 ${SQLITE_MIN_VERSION} REQUIRED)
target_include_directories(
DjInterop PRIVATE
${SQLite3_INCLUDE_DIRS})
target_link_libraries(
DjInterop PUBLIC
${SQLite3_LIBRARIES})
else()
# Use embedded SQLite amalgamation sources.
message(STATUS "Using embedded SQLite")
target_sources(
DjInterop PRIVATE
ext/sqlite-amalgamation/sqlite3.c)
target_compile_definitions(
DjInterop PUBLIC
SQLITE_OMIT_LOAD_EXTENSION)
target_include_directories(
DjInterop PRIVATE
ext/sqlite-amalgamation)
endif()
set_target_properties(DjInterop PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(DjInterop PROPERTIES CXX_VISIBILITY_PRESET hidden)
install(TARGETS DjInterop
EXPORT DjInteropTargets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES
include/djinterop/album_art.hpp
${CMAKE_CURRENT_BINARY_DIR}/include/djinterop/config.hpp
include/djinterop/crate.hpp
include/djinterop/database.hpp
include/djinterop/djinterop.hpp
include/djinterop/exceptions.hpp
include/djinterop/musical_key.hpp
include/djinterop/optional.hpp
include/djinterop/pad_color.hpp
include/djinterop/performance_data.hpp
include/djinterop/semantic_version.hpp
include/djinterop/stream_helper.hpp
include/djinterop/track.hpp
include/djinterop/track_snapshot.hpp
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}")
install(FILES
include/djinterop/engine/engine.hpp
include/djinterop/engine/engine_version.hpp
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}/engine")
install(FILES
include/djinterop/engine/v2/beat_data_blob.hpp
include/djinterop/engine/v2/change_log_table.hpp
include/djinterop/engine/v2/engine_library.hpp
include/djinterop/engine/v2/information_table.hpp
include/djinterop/engine/v2/loops_blob.hpp
include/djinterop/engine/v2/overview_waveform_data_blob.hpp
include/djinterop/engine/v2/playlist_entity_table.hpp
include/djinterop/engine/v2/playlist_table.hpp
include/djinterop/engine/v2/quick_cues_blob.hpp
include/djinterop/engine/v2/track_data_blob.hpp
include/djinterop/engine/v2/track_table.hpp
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}/engine/v2")
if (UNIX)
set(PKGCONFIG_TARGET djinterop)
if (SYSTEM_SQLITE)
set(PKGCONFIG_REQUIRES "zlib >= ${ZLIB_MIN_VERSION}, sqlite3 >= ${SQLITE_MIN_VERSION}")
else()
set(PKGCONFIG_REQUIRES "zlib >= ${ZLIB_MIN_VERSION}")
endif()
configure_file(djinterop.pc.in djinterop.pc @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/djinterop.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
# CMake package config export.
include(CMakePackageConfigHelpers)
set(DJINTEROP_INSTALL_CMAKEDIR "lib/cmake/DjInterop")
install(EXPORT DjInteropTargets
FILE DjInteropTargets.cmake
NAMESPACE DjInterop::
DESTINATION "${DJINTEROP_INSTALL_CMAKEDIR}")
configure_package_config_file(
DjInteropConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DjInteropConfig.cmake"
INSTALL_DESTINATION "${DJINTEROP_INSTALL_CMAKEDIR}")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/DjInteropConfigVersion.cmake"
VERSION "${CMAKE_PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/DjInteropConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/DjInteropConfigVersion.cmake"
cmake/FindPackageHandleStandardArgs.cmake
cmake/FindPackageMessage.cmake
cmake/FindSQLite3.cmake
DESTINATION "${DJINTEROP_INSTALL_CMAKEDIR}")
# Example programs demonstrating usage.
function(add_djinterop_example example_name)
add_executable(example_${example_name} example/${example_name}.cpp)
target_include_directories(example_${example_name} PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/include
include)
target_link_libraries(example_${example_name} PUBLIC DjInterop)
endfunction()
add_djinterop_example(engine_prime)
add_djinterop_example(engine_library_v2_low_level)
# Unit tests.
include(CTest)
find_package(Boost 1.65.1 QUIET COMPONENTS filesystem system)
if (Boost_FOUND)
set(TESTDATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/testdata")
function(add_djinterop_test test_dir test_name)
string(REPLACE "/" "_" test_executable_name ${test_dir}${test_name})
add_executable(${test_executable_name}
test/djinterop/${test_dir}${test_name}.cpp)
target_compile_definitions(${test_executable_name} PUBLIC
-DTESTDATA_DIR=${TESTDATA_DIR})
if (MSVC)
# Some unit tests are rather large and exceed max sections on VC++.
target_compile_options(${test_executable_name} PRIVATE /bigobj)
endif()
target_include_directories(${test_executable_name} PUBLIC
${Boost_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}/include
include)
target_link_libraries(${test_executable_name} PUBLIC
DjInterop
${Boost_LIBRARIES})
add_test(NAME ${test_executable_name} COMMAND ${test_executable_name})
endfunction()
add_djinterop_test("" semantic_version_test)
add_djinterop_test(engine/ crate_test)
add_djinterop_test(engine/ database_reference_test)
add_djinterop_test(engine/ database_test)
add_djinterop_test(engine/ engine_test)
add_djinterop_test(engine/ track_test)
add_djinterop_test(engine/v2/ track_table_test)
add_djinterop_test(engine/v2/ playlist_entity_table_test)
add_djinterop_test(engine/v2/ playlist_table_test)
else()
message(STATUS "Unit tests not available, as Boost cannot be found")
endif()
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
include(CPack)