-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
154 lines (121 loc) · 3.33 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
cmake_minimum_required(VERSION 3.10.0)
project(Skity)
set(SKITY_VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DSKITY_RELEASE)
endif()
set(SKITY_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
if (UNIX AND NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
# define library
if (EMSCRIPTEN)
add_library(skity STATIC)
else()
add_library(skity SHARED)
endif()
# public header include
target_include_directories(skity PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(skity PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(
skity PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>
)
add_library(skity::skity ALIAS skity)
# default config
include(GNUInstallDirs)
# platform
include(cmake/Platform.cmake)
# options
include(cmake/Options.cmake)
# pack all shader files
include(cmake/Shader.cmake)
# third party deps
include(cmake/ThirdPartyDep.cmake)
if(${ENABLE_LOG})
set(SKITY_LOG 1)
# no exception
add_definitions(-DSPDLOG_NO_EXCEPTIONS)
endif()
if(${VULKAN_BACKEND})
set(SKITY_VULKAN 1)
endif()
if(${OPENGL_BACKEND})
set(SKITY_OPENGL 1)
endif()
if(${CPU_BACKEND})
set(SKITY_CPU 1)
endif()
# svg module
if(${BUILD_SVG_MODULE})
add_subdirectory(module/svg)
endif()
if(${BUILD_CODEC_MODULE})
if (${SKITY_VCPKG})
find_package(libpng CONFIG REQUIRED)
find_package(libjpeg-turbo CONFIG REQUIRED)
else()
if(NOT WIN32)
set(PNG_SHARED ON CACHE INTERNAL "build shared libpng" FORCE)
add_subdirectory(third_party/libpng)
endif()
set(WITH_SIMD OFF CACHE INTERNAL "disable simd build" FORCE)
add_subdirectory(third_party/libjpeg-turbo)
endif()
add_subdirectory(module/codec)
endif()
# header files
add_subdirectory(include)
# source files
add_subdirectory(src)
# source group for Xcode and Visual Studio
get_target_property(SKITY_SRC skity SOURCES)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SKITY_SRC})
if (${BUILD_TEST} OR ${BUILD_EXAMPLE})
add_subdirectory(third_party/glfw)
endif()
if(${BUILD_TEST} AND CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(third_party/gtest)
add_subdirectory(test)
endif()
if(${BUILD_EXAMPLE})
add_subdirectory(example)
endif()
# package config file
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/skityConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/skity
)
# version
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/skityConfigVersion.cmake
VERSION ${SKITY_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/skityConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/skityConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/skity
)
# install library
install(
TARGETS skity EXPORT skity-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# install config file
install(
EXPORT skity-targets
FILE skityTargets.cmake
NAMESPACE skity::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/skity
)