-
Notifications
You must be signed in to change notification settings - Fork 54
/
CMakeLists.txt
108 lines (84 loc) · 3.07 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
cmake_minimum_required(VERSION 3.5)
project(tmx VERSION 1.10.0 LANGUAGES C)
add_subdirectory(doc) # Sphinx documentation
# -- Options
set(API_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(BUILD_VERSION "${PROJECT_VERSION}")
option(WANT_ZLIB "use zlib (ability to decompress layers data) ?" On)
option(WANT_ZSTD "use zstd (ability to decompress layers data) ?" Off)
option(BUILD_SHARED_LIBS "Build shared libraries (dll / so)" Off)
option(ZSTD_PREFER_STATIC "use the static build of zstd ?" On)
set(EMSCRIPTEN False)
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(EMSCRIPTEN True)
endif()
# -- Target
add_library(tmx
"src/tmx.c"
"src/tmx_utils.c"
"src/tmx_err.c"
"src/tmx_xml.c"
"src/tmx_mem.c"
"src/tmx_hash.c")
set(HEADERS "src/tmx.h")
set_target_properties(tmx PROPERTIES VERSION ${BUILD_VERSION})
# -- Dependencies
include(CheckIncludeFiles)
CHECK_INCLUDE_FILES("stdint.h" STDINT_H)
if(NOT STDINT_H)
message(FATAL_ERROR "error: required header stdint.h not found")
endif()
if(WANT_ZLIB AND EMSCRIPTEN)
target_link_options(tmx INTERFACE "SHELL:-s USE_ZLIB=1")
elseif(WANT_ZLIB)
target_compile_definitions(tmx PRIVATE WANT_ZLIB)
include(FindZLIB)
find_package(ZLIB REQUIRED)
target_link_libraries(tmx ZLIB::ZLIB)
else()
message("Zlib not wanted")
endif()
if(WANT_ZSTD)
target_compile_definitions(tmx PRIVATE WANT_ZSTD)
find_package(zstd REQUIRED)
if (ZSTD_PREFER_STATIC)
target_link_libraries(tmx zstd::libzstd_static)
else()
target_link_libraries(tmx zstd::libzstd_shared)
endif()
else()
message("zstd not wanted")
endif()
find_package(LibXml2 REQUIRED)
target_link_libraries(tmx LibXml2::LibXml2)
# -- Build
if(MSVC)
# disable warning on _strncpy (spams the output)
target_compile_definitions(tmx PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
if(BUILD_SHARED_LIBS)
if(MSVC OR CYGWIN OR MINGW)
target_compile_definitions(tmx
PRIVATE "TMXEXPORT=__declspec(dllexport)"
INTERFACE "TMXEXPORT=__declspec(dllimport)")
endif()
set_target_properties(tmx PROPERTIES SOVERSION ${API_VERSION})
set_target_properties(tmx PROPERTIES VERSION ${BUILD_VERSION})
endif()
# -- Installation
target_include_directories(tmx INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> $<INSTALL_INTERFACE:include>)
configure_file("tmxConfig.cmake.in" "tmxConfig.cmake" @ONLY)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("tmxConfigVersion.cmake" COMPATIBILITY AnyNewerVersion)
include(GNUInstallDirs)
install(TARGETS tmx
EXPORT tmx_exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT tmx_exports
FILE "tmxExports.cmake"
DESTINATION "lib/cmake/tmx")
install(FILES "${CMAKE_BINARY_DIR}/tmxConfig.cmake" "${CMAKE_BINARY_DIR}/tmxConfigVersion.cmake"
DESTINATION "lib/cmake/tmx")