forked from jkuhlmann/cgltf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
97 lines (77 loc) · 2.76 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
cmake_minimum_required(VERSION 3.0)
project(cgltf LANGUAGES C CXX VERSION 1.12)
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
option(BUILD_AS_LIBRARY "Build library" FALSE)
option(BUILD_SHARED_LIBS "Build shared libraries" FALSE)
option(BUILD_TESTS "Build tests" FALSE)
if(MSVC AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
set(CGLTF_SRC_LIST cgltf.c)
set(CGLTF_HDR_LIST cgltf.h cgltf_write.h)
if(BUILD_AS_LIBRARY)
if(BUILD_SHARED_LIBS)
add_library(cgltf SHARED ${CGLTF_SRC_LIST} ${CGLTF_HDR_LIST})
else()
add_library(cgltf STATIC ${CGLTF_SRC_LIST} ${CGLTF_HDR_LIST})
endif()
else()
add_library(cgltf INTERFACE)
endif()
target_include_directories(cgltf INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
)
if(BUILD_TESTS)
add_subdirectory(test)
endif()
set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(VERSION_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(PROJECT_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}Config.cmake")
set(GENERATED_CGLTF_HEADER "${GENERATED_DIR}/cgltf.h")
set(GENERATED_CGLTF_WRITE_HEADER "${GENERATED_DIR}/cgltf_write.h")
if(BUILD_AS_LIBRARY)
target_compile_definitions(cgltf INTERFACE CGLTF_USE_HUNTER)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/cgltf.h" CGLTF_HEADER_STRING)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/header.template.in" "${GENERATED_CGLTF_HEADER}")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/cgltf_write.h" CGLTF_HEADER_STRING)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/header.template.in" "${GENERATED_CGLTF_WRITE_HEADER}")
set(CGLTF_HDR_LIST "${GENERATED_CGLTF_HEADER}" "${GENERATED_CGLTF_WRITE_HEADER}")
endif()
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(NAMESPACE "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${VERSION_CONFIG}" COMPATIBILITY ExactVersion
)
configure_package_config_file(
"cmake/Config.cmake.in"
"${PROJECT_CONFIG}"
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
)
install(
TARGETS cgltf
EXPORT "${TARGETS_EXPORT_NAME}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(
FILES ${CGLTF_HDR_LIST}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
install(
FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}"
DESTINATION "${CONFIG_INSTALL_DIR}"
)
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${NAMESPACE}"
DESTINATION "${CONFIG_INSTALL_DIR}"
)