forked from Chlumsky/msdfgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
180 lines (149 loc) · 5.71 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
cmake_minimum_required(VERSION 3.10)
project(msdfgen VERSION 1.7.1 LANGUAGES CXX)
option(MSDFGEN_BUILD_MSDFGEN_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(FREETYPE_WITH_PNG "Link libpng and zlib because FreeType is configured to require it" OFF)
option(FREETYPE_WITH_HARFBUZZ "Link HarfBuzz because FreeType is configured to require it" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Freetype REQUIRED)
#----------------------------------------------------------------
# Gathering File
#----------------------------------------------------------------
file(GLOB_RECURSE msdfgen_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"core/*.h"
"core/*.hpp"
)
file(GLOB_RECURSE msdfgen_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"core/*.cpp"
)
file(GLOB_RECURSE msdfgen-ext_PUBLIC_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"ext/*.h"
"ext/*.hpp"
)
file(GLOB_RECURSE msdfgen-ext_PRIVATE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"include/*.h"
)
file(GLOB_RECURSE msdfgen-ext_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"ext/*.cpp"
"lib/*.cpp"
"lib/*.cpp"
)
# Build the library (aliased name because it's the same target name the exe)
include(folderize)
folderize_sources(msdfgen_HEADERS ${CMAKE_SOURCE_DIR})
folderize_sources(msdfgen_SOURCES ${CMAKE_SOURCE_DIR})
folderize_sources(msdfgen-ext_PUBLIC_HEADERS ${CMAKE_SOURCE_DIR})
folderize_sources(msdfgen-ext_PRIVATE_HEADERS ${CMAKE_SOURCE_DIR})
folderize_sources(msdfgen-ext_SOURCES ${CMAKE_SOURCE_DIR})
#----------------------------------------------------------------
# Target configuration
#----------------------------------------------------------------
add_library(msdfgen ${msdfgen_SOURCES} ${msdfgen_HEADERS} "./msdfgen.h")
add_library(msdfgen::msdfgen ALIAS msdfgen)
set_target_properties(msdfgen PROPERTIES PUBLIC_HEADER "${msdfgen_HEADERS}")
target_include_directories(msdfgen INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
)
if(MSDFGEN_USE_CPP11)
target_compile_features(msdfgen PUBLIC cxx_std_11)
target_compile_definitions(msdfgen PUBLIC MSDFGEN_USE_CPP11)
endif()
if(MSDFGEN_USE_OPENMP)
# Note: Clang doesn't support OpenMP by default...
find_package(OpenMP REQUIRED COMPONENTS CXX)
target_link_libraries(msdfgen PRIVATE OpenMP::OpenMP_CXX)
target_compile_definitions(msdfgen PRIVATE MSDFGEN_USE_OPENMP)
endif()
add_library(msdfgen-ext ${msdfgen-ext_SOURCES} ${msdfgen-ext_PUBLIC_HEADERS} ${msdfgen-ext_PRIVATE_HEADERS} "./msdfgen-ext.h")
add_library(msdfgen::msdfgen-ext ALIAS msdfgen-ext)
set_target_properties(msdfgen-ext PROPERTIES
PUBLIC_HEADER "${msdfgen-ext_PUBLIC_HEADERS}"
)
target_link_libraries(msdfgen-ext PUBLIC msdfgen::msdfgen Freetype::Freetype)
target_include_directories(msdfgen-ext
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
if(MSDFGEN_USE_CPP11)
target_compile_features(msdfgen-ext PUBLIC cxx_std_11)
target_compile_definitions(msdfgen-ext PUBLIC MSDFGEN_USE_CPP11)
endif()
# Build the executable if requested
if(MSDFGEN_BUILD_MSDFGEN_STANDALONE)
add_executable(msdfgen-standalone main.cpp)
set_target_properties(msdfgen-standalone PROPERTIES ARCHIVE_OUTPUT_DIRECTORY archive OUTPUT_NAME msdfgen)
target_compile_definitions(msdfgen-standalone PRIVATE MSDFGEN_STANDALONE)
target_link_libraries(msdfgen-standalone PRIVATE msdfgen::msdfgen msdfgen::msdfgen-ext)
if(FREETYPE_WITH_PNG)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
target_link_libraries(msdfgen-standalone PRIVATE ZLIB::ZLIB PNG::PNG)
endif()
if(FREETYPE_WITH_HARFBUZZ)
# No FindHarfBuzz.cmake available so falling back to CMAKE_LIBRARY_PATH
find_library(FREETYPE_HARFBUZZ_LIB "harfbuzz")
target_link_libraries(msdfgen-standalone PRIVATE "${FREETYPE_HARFBUZZ_LIB}")
endif()
endif()
#----------------------------------------------------------------
# Installation and exportation of the libraries
#----------------------------------------------------------------
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 EXPORT msdfgenTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
FRAMEWORK DESTINATION lib
PUBLIC_HEADER DESTINATION include/msdfgen/core
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen.h" "${CMAKE_CURRENT_SOURCE_DIR}/msdfgen-ext.h" DESTINATION include/msdfgen)
install(TARGETS msdfgen-ext EXPORT msdfgenTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
FRAMEWORK DESTINATION lib
PUBLIC_HEADER DESTINATION include/msdfgen/ext
)
if(MSDFGEN_BUILD_MSDFGEN_STANDALONE)
install(TARGETS msdfgen-standalone EXPORT msdfgenTargets RUNTIME DESTINATION bin)
endif()
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${MSDFGEN_CONFIG_PATH}/msdfgenConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/msdfgenConfigVersion.cmake"
DESTINATION ${MSDFGEN_CONFIG_PATH}
)
export(
EXPORT msdfgenTargets
NAMESPACE msdfgen::
FILE "${CMAKE_CURRENT_BINARY_DIR}/msdfgenTargets.cmake"
)
install(
EXPORT msdfgenTargets FILE msdfgenTargets.cmake
NAMESPACE msdfgen::
DESTINATION ${MSDFGEN_CONFIG_PATH}
)