forked from libxmp/libxmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
398 lines (347 loc) · 14.5 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
cmake_minimum_required(VERSION 3.4...3.5)
project(libxmp VERSION 4.6.0 LANGUAGES C)
set(LIBXMP_DEFINES)
set(LIBXMPLITE_DEFINES)
set(LIBXMP_CFLAGS)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libxmp-checks.cmake)
include(GNUInstallDirs)
# -fPIC thing
if(NOT WIN32 AND NOT EMSCRIPTEN AND NOT VITA)
option(LIBXMP_PIC "Build the static library as position-independent" OFF)
else()
set(LIBXMP_PIC OFF)
endif()
if(EMSCRIPTEN OR VITA OR PSP)
set(BUILD_SHARED_DEFAULT OFF)
else()
set(BUILD_SHARED_DEFAULT ON)
endif()
option(BUILD_STATIC "Build libXMP static library" ON)
option(BUILD_SHARED "Build libXMP shared library" ${BUILD_SHARED_DEFAULT})
option(BUILD_LITE "Build libXMP-lite library" OFF)
if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
message(FATAL_ERROR "Both static and shared builds got disabled. You must enable at least one of them.")
endif()
option(LIBXMP_DISABLE_DEPACKERS "Disable archive depackers" OFF)
option(LIBXMP_DISABLE_PROWIZARD "Disable ProWizard format loaders" OFF)
option(LIBXMP_DISABLE_IT "Disable IT format in libXMP-lite" OFF)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libxmp-sources.cmake)
if(LIBXMP_DISABLE_DEPACKERS)
list(APPEND LIBXMP_DEFINES LIBXMP_NO_DEPACKERS)
else()
list(APPEND LIBXMP_SRC_LIST ${LIBXMP_SRC_LIST_DEPACKERS})
endif()
if(LIBXMP_DISABLE_PROWIZARD)
list(APPEND LIBXMP_DEFINES LIBXMP_NO_PROWIZARD)
else()
list(APPEND LIBXMP_SRC_LIST ${LIBXMP_SRC_LIST_PROWIZARD})
endif()
#lite-only defs
list(APPEND LIBXMPLITE_DEFINES LIBXMP_CORE_PLAYER)
if(LIBXMP_DISABLE_IT)
list(APPEND LIBXMPLITE_DEFINES LIBXMP_CORE_DISABLE_IT)
endif()
if(MSVC)
list(APPEND LIBXMP_DEFINES _USE_MATH_DEFINES)
list(APPEND LIBXMPLITE_DEFINES _USE_MATH_DEFINES)
endif()
#for libxmp-lite.pc
set(libxmplite_VERSION ${libxmp_VERSION})
# extract exports:
set(XMP_EXPORTS)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/libxmp.map _XMP_EXPORTS)
foreach(export_sym ${_XMP_EXPORTS})
if(export_sym MATCHES "xmp_.*")
string(REPLACE ";" "" export_sym ${export_sym})
string(STRIP ${export_sym} export_sym)
list(APPEND XMP_EXPORTS "${export_sym}")
endif()
endforeach()
set(_XMP_EXPORTS)
list(REMOVE_DUPLICATES XMP_EXPORTS)
set(XMP_INSTALLS)
if(BUILD_STATIC)
add_library(xmp_static STATIC ${LIBXMP_SRC_LIST})
add_library(libxmp::xmp_static ALIAS xmp_static)
list(APPEND XMP_INSTALLS xmp_static)
set_target_properties(xmp_static PROPERTIES C_STANDARD 90)
if(MSVC)
set_target_properties(xmp_static PROPERTIES OUTPUT_NAME libxmp-static)
else()
set_target_properties(xmp_static PROPERTIES OUTPUT_NAME xmp)
endif()
target_compile_options(xmp_static PRIVATE ${LIBXMP_CFLAGS})
target_compile_definitions(xmp_static PRIVATE ${LIBXMP_DEFINES})
target_compile_definitions(xmp_static PUBLIC LIBXMP_STATIC)
if(LIBXMP_PIC)
target_compile_options(xmp_static PRIVATE -fPIC)
endif()
target_include_directories(xmp_static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
target_include_directories(xmp_static PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
if(LIBM_REQUIRED)
target_link_libraries(xmp_static PUBLIC ${LIBM_LIBRARY})
endif()
if(BUILD_LITE)
add_library(xmp_lite_static STATIC ${LIBXMP_SRC_LIST_LITE})
add_library(libxmp-lite::xmp_lite_static ALIAS xmp_lite_static)
list(APPEND XMP_INSTALLS xmp_lite_static)
set_target_properties(xmp_lite_static PROPERTIES C_STANDARD 90)
if(MSVC)
set_target_properties(xmp_lite_static PROPERTIES OUTPUT_NAME libxmp-lite-static)
else()
set_target_properties(xmp_lite_static PROPERTIES OUTPUT_NAME xmp-lite)
endif()
target_compile_options(xmp_lite_static PRIVATE ${LIBXMP_CFLAGS})
target_compile_definitions(xmp_lite_static PRIVATE ${LIBXMPLITE_DEFINES})
target_compile_definitions(xmp_lite_static PUBLIC LIBXMP_STATIC)
if(LIBXMP_PIC)
target_compile_options(xmp_lite_static PRIVATE -fPIC)
endif()
target_include_directories(xmp_lite_static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
target_include_directories(xmp_lite_static PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libxmp-lite>")
if(LIBM_REQUIRED)
target_link_libraries(xmp_lite_static PUBLIC ${LIBM_LIBRARY})
endif()
endif()
endif()
if(BUILD_SHARED)
add_library(xmp_shared SHARED ${LIBXMP_SRC_LIST})
add_library(libxmp::xmp_shared ALIAS xmp_shared)
list(APPEND XMP_INSTALLS xmp_shared)
set_target_properties(xmp_shared PROPERTIES C_STANDARD 90)
if(MSVC)
set_target_properties(xmp_shared PROPERTIES OUTPUT_NAME libxmp)
elseif(OS2)
set_target_properties(xmp_shared PROPERTIES OUTPUT_NAME libxmp)
set(DEF_CONTENTS "LIBRARY LIBXMP INITINSTANCE TERMINSTANCE\n")
list(APPEND DEF_CONTENTS "DATA MULTIPLE NONSHARED\n")
list(APPEND DEF_CONTENTS "EXPORTS\n")
foreach(export_sym ${XMP_EXPORTS})
list(APPEND DEF_CONTENTS " ${export_sym}\n")
endforeach()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/os2dll.def ${DEF_CONTENTS})
target_sources(xmp_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/os2dll.def)
else()
set_target_properties(xmp_shared PROPERTIES OUTPUT_NAME xmp)
endif()
if(HAVE_GCC OR HAVE_CLANG)
if(APPLE)
set_property(TARGET xmp_shared APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-undefined,error")
elseif(NOT CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
check_c_compiler_flag("" HAVE_NO_UNDEFINED)
cmake_pop_check_state()
if(HAVE_NO_UNDEFINED)
set_property(TARGET xmp_shared APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--no-undefined")
endif()
endif()
endif()
if(HAVE_VISIBILITY AND HAVE_GNU_LD AND UNIX)
target_compile_definitions(xmp_shared PRIVATE USE_VERSIONED_SYMBOLS=1)
set_property(TARGET xmp_shared APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libxmp.map")
message(STATUS "Versioned symbols: ENABLED.")
else()
message(STATUS "Versioned symbols: DISABLED")
endif()
target_compile_options(xmp_shared PRIVATE ${LIBXMP_CFLAGS})
target_compile_definitions(xmp_shared PRIVATE ${LIBXMP_DEFINES})
if(WIN32)
target_compile_definitions(xmp_shared PRIVATE BUILDING_DLL)
endif()
target_include_directories(xmp_shared PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
target_include_directories(xmp_shared PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
set_target_properties(xmp_shared PROPERTIES VERSION ${libxmp_VERSION} SOVERSION ${libxmp_VERSION_MAJOR})
if(ANDROID AND CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
target_link_libraries(xmp_shared PRIVATE log)
endif()
if(LIBM_REQUIRED)
target_link_libraries(xmp_shared PUBLIC ${LIBM_LIBRARY})
endif()
if(BUILD_LITE)
add_library(xmp_lite_shared SHARED ${LIBXMP_SRC_LIST_LITE})
add_library(libxmp-lite::xmp_lite_shared ALIAS xmp_lite_shared)
list(APPEND XMP_INSTALLS xmp_lite_shared)
set_target_properties(xmp_lite_shared PROPERTIES C_STANDARD 90)
if(MSVC)
set_target_properties(xmp_lite_shared PROPERTIES OUTPUT_NAME libxmp-lite)
elseif(OS2)
set_target_properties(xmp_lite_shared PROPERTIES OUTPUT_NAME libxmplt)
set(DEF_CONTENTS "LIBRARY LIBXMPLT INITINSTANCE TERMINSTANCE\n")
list(APPEND DEF_CONTENTS "DATA MULTIPLE NONSHARED\n")
list(APPEND DEF_CONTENTS "EXPORTS\n")
foreach(export_sym ${XMP_EXPORTS})
list(APPEND DEF_CONTENTS " ${export_sym}\n")
endforeach()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/os2lite.def ${DEF_CONTENTS})
target_sources(xmp_lite_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/os2lite.def)
else()
set_target_properties(xmp_lite_shared PROPERTIES OUTPUT_NAME xmp-lite)
endif()
if(HAVE_GCC OR HAVE_CLANG)
if(APPLE)
set_property(TARGET xmp_lite_shared APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-undefined,error")
elseif(NOT CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
check_c_compiler_flag("" HAVE_NO_UNDEFINED)
cmake_pop_check_state()
if(HAVE_NO_UNDEFINED)
set_property(TARGET xmp_lite_shared APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--no-undefined")
endif()
endif()
endif()
if(HAVE_VISIBILITY AND HAVE_GNU_LD AND UNIX)
target_compile_definitions(xmp_lite_shared PRIVATE USE_VERSIONED_SYMBOLS=1)
set_property(TARGET xmp_lite_shared APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libxmp.map")
endif()
target_compile_options(xmp_lite_shared PRIVATE ${LIBXMP_CFLAGS})
target_compile_definitions(xmp_lite_shared PRIVATE ${LIBXMPLITE_DEFINES})
if(WIN32)
target_compile_definitions(xmp_lite_shared PRIVATE BUILDING_DLL)
endif()
target_include_directories(xmp_lite_shared PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
target_include_directories(xmp_lite_shared PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libxmp-lite>")
set_target_properties(xmp_lite_shared PROPERTIES VERSION ${libxmp_VERSION} SOVERSION ${libxmp_VERSION_MAJOR})
if(ANDROID AND CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
target_link_libraries(xmp_lite_shared PRIVATE log)
endif()
if(LIBM_REQUIRED)
target_link_libraries(xmp_lite_shared PUBLIC ${LIBM_LIBRARY})
endif()
endif()
endif()
add_library(XMP_IF INTERFACE)
if(NOT BUILD_SHARED)
target_link_libraries(XMP_IF INTERFACE xmp_static)
else()
target_link_libraries(XMP_IF INTERFACE xmp_shared)
endif()
if(BUILD_LITE)
add_library(XMPLITE_IF INTERFACE)
if(NOT BUILD_SHARED)
target_link_libraries(XMPLITE_IF INTERFACE xmp_lite_static)
else()
target_link_libraries(XMPLITE_IF INTERFACE xmp_lite_shared)
endif()
endif()
# === Unit tests ====
option(WITH_UNIT_TESTS "Enable unit testing" OFF)
if(WITH_UNIT_TESTS)
enable_testing()
add_subdirectory(test)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test-dev/")
add_subdirectory(test-dev)
endif()
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt")
add_subdirectory(examples)
endif()
# === Documentation ====
add_subdirectory(docs)
# === Install ====
include(CMakePackageConfigHelpers)
if(WIN32)
set(cmake_install_cmakdir "cmake")
set(cmake_install_cmakdir_lite "cmake")
else()
set(cmake_install_cmakdir "${CMAKE_INSTALL_LIBDIR}/cmake/libxmp")
set(cmake_install_cmakdir_lite "${CMAKE_INSTALL_LIBDIR}/cmake/libxmp-lite")
endif()
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libxmp.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libxmp.pc" @ONLY
)
write_basic_package_version_file(libxmp-config-version.cmake
COMPATIBILITY AnyNewerVersion
)
if(TARGET xmp_shared)
install(TARGETS xmp_shared EXPORT libxmp_shared_exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT libxmp_shared_exports
DESTINATION "${cmake_install_cmakdir}"
FILE "libxmp-shared-targets.cmake"
NAMESPACE "libxmp::"
)
endif()
if(TARGET xmp_static)
install(TARGETS xmp_static EXPORT libxmp_static_exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT libxmp_static_exports
DESTINATION "${cmake_install_cmakdir}"
FILE "libxmp-static-targets.cmake"
NAMESPACE "libxmp::"
)
endif()
install(FILES
libxmp-config.cmake
"${CMAKE_CURRENT_BINARY_DIR}/libxmp-config-version.cmake"
DESTINATION "${cmake_install_cmakdir}"
)
install(FILES
include/xmp.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxmp.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
if(BUILD_LITE)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/lite/libxmp-lite.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libxmp-lite.pc" @ONLY
)
write_basic_package_version_file(libxmp-lite-config-version.cmake
COMPATIBILITY AnyNewerVersion
)
if(TARGET xmp_lite_shared)
install(TARGETS xmp_lite_shared EXPORT libxmp_lite_shared_exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT libxmp_lite_shared_exports
DESTINATION "${cmake_install_cmakdir_lite}"
FILE "libxmp-lite-shared-targets.cmake"
NAMESPACE "libxmp-lite::"
)
endif()
if(TARGET xmp_lite_static)
install(TARGETS xmp_lite_static EXPORT libxmp_lite_static_exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(EXPORT libxmp_lite_static_exports
DESTINATION "${cmake_install_cmakdir_lite}"
FILE "libxmp-lite-static-targets.cmake"
NAMESPACE "libxmp-lite::"
)
endif()
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/lite/libxmp-lite-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libxmp-lite-config-version.cmake"
DESTINATION "${cmake_install_cmakdir_lite}"
)
install(FILES
include/xmp.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxmp-lite
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libxmp-lite.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
endif()