forked from Chlumsky/msdfgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
173 lines (149 loc) · 7.17 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
cmake_minimum_required(VERSION 3.15)
option(MSDFGEN_CORE_ONLY "Only build the core library with no dependencies" OFF)
option(MSDFGEN_DISABLE_RTTI "Disable the use of RTTI" OFF)
option(MSDFGEN_BUILD_STANDALONE "Build the msdfgen standalone executable" ON)
option(MSDFGEN_USE_OPENMP "Build with OpenMP support for multithreaded code" OFF)
option(MSDFGEN_USE_CPP11 "Build with C++11 enabled" ON)
option(MSDFGEN_USE_SKIA "Build with the Skia library" OFF)
option(MSDFGEN_INSTALL "Generate installation target" ON)
if(MSDFGEN_CORE_ONLY AND MSDFGEN_BUILD_STANDALONE)
message(WARNING "Option MSDFGEN_CORE_ONLY ignored - extensions are required for standalone executable")
set(MSDFGEN_CORE_ONLY OFF)
endif()
project(msdfgen VERSION 1.9 LANGUAGES CXX)
if(NOT CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
get_directory_property(MSDFGEN_HAS_PARENT PARENT_DIRECTORY)
if(MSDFGEN_HAS_PARENT)
set(CMAKE_MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY} PARENT_SCOPE)
endif()
endif()
if(NOT TARGET Freetype::Freetype)
find_package(Freetype REQUIRED)
endif()
file(GLOB_RECURSE MSDFGEN_CORE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "core/*.h" "core/*.hpp")
file(GLOB_RECURSE MSDFGEN_CORE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "core/*.cpp")
file(GLOB_RECURSE MSDFGEN_EXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ext/*.h" "ext/*.hpp")
file(GLOB_RECURSE MSDFGEN_EXT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "ext/*.cpp" "lib/*.cpp")
# Core library
add_library(msdfgen-core "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" ${MSDFGEN_CORE_HEADERS} ${MSDFGEN_CORE_SOURCES})
add_library(msdfgen::msdfgen-core ALIAS msdfgen-core)
set_target_properties(msdfgen-core PROPERTIES PUBLIC_HEADER "${MSDFGEN_CORE_HEADERS}")
#set_property(TARGET msdfgen-core PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_include_directories(msdfgen-core INTERFACE
$<INSTALL_INTERFACE:include/msdfgen>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen-core)
if(MSDFGEN_DISABLE_RTTI)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(msdfgen-core PUBLIC /GR-)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(msdfgen-core PUBLIC -fno-rtti)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(msdfgen-core PUBLIC -fno-rtti)
endif()
target_compile_definitions(msdfgen-core PUBLIC MSDFGEN_NO_RTTI)
endif()
if(MSDFGEN_USE_CPP11)
target_compile_features(msdfgen-core PUBLIC cxx_std_11)
target_compile_definitions(msdfgen-core PUBLIC MSDFGEN_USE_CPP11)
endif()
if(MSDFGEN_USE_OPENMP)
# Note: Clang doesn't support OpenMP by default...
find_package(OpenMP REQUIRED COMPONENTS CXX)
target_compile_definitions(msdfgen-core PUBLIC MSDFGEN_USE_OPENMP)
target_link_libraries(msdfgen-core PUBLIC OpenMP::OpenMP_CXX)
endif()
# Extensions library
if(NOT MSDFGEN_CORE_ONLY)
add_library(msdfgen-ext "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" ${MSDFGEN_EXT_HEADERS} ${MSDFGEN_EXT_SOURCES})
add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext)
set_target_properties(msdfgen-ext PROPERTIES PUBLIC_HEADER "${MSDFGEN_EXT_HEADERS}")
target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen-core Freetype::Freetype)
target_include_directories(msdfgen-ext
PUBLIC
$<INSTALL_INTERFACE:include/msdfgen>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen-ext)
if(MSDFGEN_USE_SKIA)
find_package(Skia REQUIRED)
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_SKIA)
target_link_libraries(msdfgen-ext PUBLIC Skia::Skia)
endif()
add_library(msdfgen-all INTERFACE)
add_library(msdfgen::msdfgen ALIAS msdfgen-all)
target_link_libraries(msdfgen-all INTERFACE msdfgen::msdfgen-core msdfgen::msdfgen-ext)
endif()
# Standalone executable
if(MSDFGEN_BUILD_STANDALONE)
set(MSDFGEN_STANDALONE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
if(MSVC)
set(MSDFGEN_STANDALONE_SOURCES ${MSDFGEN_STANDALONE_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.rc")
endif()
add_executable(msdfgen ${MSDFGEN_STANDALONE_SOURCES})
target_compile_definitions(msdfgen PUBLIC MSDFGEN_STANDALONE)
target_link_libraries(msdfgen PUBLIC msdfgen::msdfgen)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT msdfgen)
endif()
# Installation
if(MSDFGEN_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(MSDFGEN_CONFIG_PATH "lib/cmake/msdfgen")
# install tree package config
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
cmake/msdfgenConfig.cmake.in
${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake
INSTALL_DESTINATION ${MSDFGEN_CONFIG_PATH}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# build tree package config
configure_file(
cmake/msdfgenConfig.cmake.in
msdfgenConfig.cmake
@ONLY
)
install(TARGETS msdfgen-core EXPORT msdfgenTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/msdfgen/core
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" DESTINATION include/msdfgen)
if(NOT MSDFGEN_CORE_ONLY)
install(TARGETS msdfgen-ext EXPORT msdfgenTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/msdfgen/ext
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" DESTINATION include/msdfgen)
install(TARGETS msdfgen-all EXPORT msdfgenTargets)
endif()
export(EXPORT msdfgenTargets NAMESPACE msdfgen:: FILE "${CMAKE_CURRENT_BINARY_DIR}/msdfgenTargets.cmake")
install(EXPORT msdfgenTargets FILE msdfgenTargets.cmake NAMESPACE msdfgen:: DESTINATION ${MSDFGEN_CONFIG_PATH})
if(MSDFGEN_BUILD_STANDALONE)
install(TARGETS msdfgen EXPORT msdfgenBinaryTargets DESTINATION ${CMAKE_INSTALL_BINDIR})
export(EXPORT msdfgenBinaryTargets NAMESPACE msdfgen-standalone:: FILE "${CMAKE_CURRENT_BINARY_DIR}/msdfgenBinaryTargets.cmake")
install(EXPORT msdfgenBinaryTargets FILE msdfgenBinaryTargets.cmake NAMESPACE msdfgen-standalone:: DESTINATION ${MSDFGEN_CONFIG_PATH})
endif()
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake"
DESTINATION ${MSDFGEN_CONFIG_PATH}
)
endif()