-
Notifications
You must be signed in to change notification settings - Fork 48
/
CMakeLists.txt
199 lines (170 loc) · 6.1 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
cmake_minimum_required(VERSION 3.16.3)
project(Forge VERSION 1.1.0 LANGUAGES C CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")
list(APPEND CMAKE_PREFIX_PATH "${Forge_BINARY_DIR}/cmake")
include(ForgeBuildType)
include(ForgeInstallDirs)
include(ForgeInternalUtils)
include(ForgePlatformSetup)
include(ForgeVersion)
include(ForgeConfigureDepsVars)
set_policies(TYPE NEW POLICIES CMP0072 CMP0077)
option(BUILD_SHARED_LIBS "Build shared/static library" ON)
find_package(Boost REQUIRED)
find_package(Doxygen QUIET)
find_package(FontConfig QUIET)
find_package(FreeImage QUIET)
find_package(Freetype REQUIRED)
find_package(Sphinx QUIET)
find_package(glad CONFIG QUIET)
find_package(glm CONFIG QUIET)
if(UNIX)
dependency_check(FontConfig_FOUND
"FontConfig is required on non-windows OS")
endif()
option(FG_BUILD_DOCS
"Build Documentation" $<AND:${DOXYGEN_FOUND},${Sphinx_FOUND}>)
option(FG_BUILD_EXAMPLES
"Build Examples" ON)
option(FG_WITH_FREEIMAGE
"Use FreeImage to add support for saving framebuffer to disk"
${FreeImage_FOUND})
option(FG_USE_STATIC_FREEIMAGE
"Use static version of freeimage" OFF)
option(FG_USE_STATIC_CPPFLAGS
"Use static libstdc++ & libgcc for generating forge library" OFF)
set(FG_USE_WINDOW_TOOLKIT "glfw3" CACHE STRING "Choose Window toolkit")
set_property(CACHE FG_USE_WINDOW_TOOLKIT PROPERTY STRINGS "glfw3" "sdl2")
set(FG_RENDERING_BACKEND "OpenGL" CACHE STRING "Choose Rendering Backend")
set_property(CACHE FG_RENDERING_BACKEND PROPERTY STRINGS "OpenGL")
mark_as_advanced(
FG_USE_STATIC_FREEIMAGE
FG_USE_STATIC_CPPFLAGS)
fg_deprecate(BUILD_DOCS FG_BUILD_DOCS)
fg_deprecate(BUILD_EXAMPLES FG_BUILD_EXAMPLES)
fg_deprecate(WITH_FREEIMAGE FG_WITH_FREEIMAGE)
fg_deprecate(USE_STATIC_FREEIMAGE FG_USE_STATIC_FREEIMAGE)
fg_deprecate(WITH_TOOLKIT FG_USE_WINDOW_TOOLKIT)
if(Boost_FOUND AND NOT TARGET Boost::boost)
add_library(Boost::boost INTERFACE IMPORTED)
set_property(TARGET Boost::boost
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
endif(Boost_FOUND AND NOT TARGET Boost::boost)
if(NOT TARGET glad::glad) # find_package(glad) failed
fg_dep_check_and_populate(${glad_prefix}
URI https://github.com/arrayfire/glad.git
REF obj_lib
)
add_subdirectory(${${glad_prefix}_SOURCE_DIR} ${${glad_prefix}_BINARY_DIR})
add_library(forge_glad STATIC $<TARGET_OBJECTS:glad_obj_lib>)
target_link_libraries(forge_glad PUBLIC ${CMAKE_DL_LIBS})
target_include_directories(forge_glad
PUBLIC
$<BUILD_INTERFACE:$<TARGET_PROPERTY:glad_obj_lib,INTERFACE_INCLUDE_DIRECTORIES>>
)
else()
add_library(forge_glad ALIAS glad::glad)
endif()
add_library(forge_glm INTERFACE)
if(TARGET glm::glm)
target_include_directories(forge_glm
SYSTEM INTERFACE
$<TARGET_PROPERTY:glm::glm,INTERFACE_INCLUDE_DIRECTORIES>
)
else() # find_package(glm) failed
fg_dep_check_and_populate(${glm_prefix}
URI https://github.com/g-truc/glm.git
REF 0.9.9.8
)
target_include_directories(forge_glm INTERFACE "${${glm_prefix}_SOURCE_DIR}")
endif()
add_subdirectory(src/backend/common)
add_subdirectory(src/backend/glsl_shaders)
add_subdirectory(src/api/c)
add_subdirectory(src/api/cpp)
add_subdirectory(src/backend)
#--------------------------------------------------------------------
# Install include folder, docs, examples etc.
#--------------------------------------------------------------------
install(DIRECTORY include/
DESTINATION ${FG_INSTALL_INC_DIR}
COMPONENT forge_dev
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN ".gitignore" EXCLUDE)
install(FILES ${Forge_BINARY_DIR}/include/fg/version.h
DESTINATION "${FG_INSTALL_INC_DIR}/fg/"
COMPONENT forge_dev)
# install the examples irrespective of the FG_BUILD_EXAMPLES value
# only the examples source files are installed, so the installation of these
# source files does not depend on FG_BUILD_EXAMPLES
# when FG_BUILD_EXAMPLES is OFF, the examples source is installed without
# building the example executables
install(DIRECTORY examples/ #NOTE The slash at the end is important
DESTINATION ${FG_INSTALL_EXAMPLE_DIR}
COMPONENT forge_dev)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${Forge_BINARY_DIR}/ForgeConfigVersion.cmake"
COMPATIBILITY SameMajorVersion)
# export install config file
set(INCLUDE_DIRS include)
set(CMAKE_DIR ${FG_INSTALL_CMAKE_DIR})
configure_package_config_file(
"${Forge_SOURCE_DIR}/CMakeModules/ForgeConfig.cmake.in"
"cmake_install/ForgeConfig.cmake"
INSTALL_DESTINATION "${FG_INSTALL_CMAKE_DIR}"
PATH_VARS INCLUDE_DIRS CMAKE_DIR
)
install(FILES ${Forge_BINARY_DIR}/cmake_install/ForgeConfig.cmake
${Forge_BINARY_DIR}/ForgeConfigVersion.cmake
DESTINATION ${FG_INSTALL_CMAKE_DIR}
COMPONENT forge_dev
)
install(EXPORT ForgeTargets
NAMESPACE Forge::
DESTINATION ${FG_INSTALL_CMAKE_DIR}
COMPONENT forge_dev
)
# export build tree targets config file
set(INCLUDE_DIRS "${Forge_SOURCE_DIR}/include" "${Forge_BINARY_DIR}/include")
set(CMAKE_DIR "${Forge_BINARY_DIR}")
configure_package_config_file(
"${Forge_SOURCE_DIR}/CMakeModules/ForgeConfig.cmake.in"
"ForgeConfig.cmake"
INSTALL_DESTINATION "${Forge_BINARY_DIR}"
PATH_VARS INCLUDE_DIRS CMAKE_DIR
INSTALL_PREFIX "${Forge_BINARY_DIR}"
)
export(EXPORT ForgeTargets
NAMESPACE Forge::
FILE ForgeTargets.cmake
)
conditional_directory(FG_BUILD_DOCS docs)
conditional_directory(FG_BUILD_EXAMPLES examples)
mark_as_advanced(
pkgcfg_lib_FontConfigPkg_freetype
pkgcfg_lib_FontConfigPkg_fontconfig
Boost_INCLUDE_DIR
SPHINX_EXECUTABLE
VCPKG_APPLOCAL_DEPS
VCPKG_BOOTSTRAP_OPTIONS
VCPKG_INSTALL_OPTIONS
VCPKG_MANIFEST_DIR
VCPKG_MANIFEST_INSTALL
VCPKG_MANIFEST_MODE
VCPKG_OVERLAY_PORTS
VCPKG_OVERLAY_TRIPLETS
VCPKG_TARGET_TRIPLET
X_VCPKG_APPLOCAL_DEPS_INSTALL
X_VCPKG_APPLOCAL_DEPS_SERIALIZED
Z_VCPKG_BUILTIN_POWERSHELL_PATH
Z_VCPKG_PWSH_PATH
Z_VCPKG_CL
_VCPKG_INSTALLED_DIR
glm_DIR
glad_DIR
)
include(ForgeCPackConfig)