-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
226 lines (202 loc) · 9.33 KB
/
CMakeLists.txt
File metadata and controls
226 lines (202 loc) · 9.33 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
cmake_minimum_required(VERSION 3.30.0..4.3.0)
project(Nostalgia
VERSION 0.20.0
LANGUAGES CXX C)
option(BUILD_SHARED_LIBS "Build the shared version of Nostalgia (Linux only)" OFF)
option(NOSTALGIA_GENERATE_COMPILE_COMMANDS "Generate a compile_commands.json file, fix it, and export it to the source directory" OFF)
option(BUILD_EDITOR "Build the editor/testing app" ON)
option(NOSTALGIA_INSTALL "Generate install targets" ON)
option(NOSTALGIA_INCLUDE_GLM_HEADERS "When installing Nostalgia's headers, include Nostalgia/thirdparty/glm" ON)
option(NOSTALGIA_INCLUDE_JOLT_HEADERS "When installing Nostalgia's headers, include Nostalgia/thirdparty/Jolt" ON)
if(NOT MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
option(NOSTALGIA_USE_ADDRESS_SANITIZER "Use address sanitizer when building Nostalgia and the included testing apps" OFF)
endif()
option(NOSTALGIA_DISABLE_PIC "Disable position independant code (-fPIC)" OFF)
mark_as_advanced(NOSTALGIA_DISABLE_PIC)
if(NOT MSVC AND BUILD_SHARED_LIBS)
option(EDITOR_AND_APPS_USE_GLOBAL_LIBRARY "When building the editor and/or testing apps, link against the version of Nostalgia found in the global install directory (typically '/usr/local/lib')" OFF)
endif()
# Always enable PIC unless otherwise specified
# This makes sure you don't have to re-compile everything when switching between static and shared library builds
if(NOT NOSTALGIA_DISABLE_PIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# Testapp Options
# option(BUILD_TEST "Build test" ON)
if(MSVC OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Append this to the debug library's name")
endif()
if(MSVC)
if(BUILD_SHARED_LIBS)
message(FATAL_ERROR "Sorry, but building Nostalgia as a DLL is not supported yet; feel free to try and do it yourself, though (and if you can get it working, make a pull request!)")
endif()
set(NOSTALGIA_JPH_DEFINITIONS JPH_PROFILE_ENABLED JPH_USE_DX12)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_CURRENT_BINARY_DIR}/NostalgiaHeaderFiles)
message(STATUS "Available Configurations: Debug, Release")
else()
set(NOSTALGIA_JPH_DEFINITIONS JPH_PROFILE_ENABLED JPH_USE_VK)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
endif()
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")
endif()
if(NOT CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ${NOSTALGIA_GENERATE_COMPILE_COMMANDS})
endif()
if(CMAKE_EXPORT_COMPILE_COMMANDS)
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json)
include(FixCompileCommands.cmake)
fix_compile_commands()
else()
message(STATUS "NOTE:: If you want to fix cmake's \"compile_commands.json\" file (and copy it to the source directory) please re-run the previous cmake command (or press either \"configure\" or \"generate\" if using cmake-gui)")
endif()
endif()
set(NOSTALGIA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Nostalgia)
set(NOSTALGIA_PCH_SRC ${NOSTALGIA_ROOT}/Nostalgia.hpp)
set(NOSTALGIA_EMBED_FILES fonts.hpp images.hpp models.hpp shaders.hpp)
add_custom_command(OUTPUT ${NOSTALGIA_EMBED_FILES}
COMMAND ${CMAKE_COMMAND}
ARGS -D_EMBED_NOSTALGIA=ON -DSOURCE_DIR=${NOSTALGIA_ROOT}/embedded -P ${NOSTALGIA_ROOT}/embedded/EmbedAssets.cmake)
include(Sources.cmake)
include(Thirdparty.cmake)
add_library(Nostalgia ${NOSTALGIA_SRC_FILES} ${NOSTALGIA_OBJ_FILES} ${NOSTALGIA_HEADERS} ${NOSTALGIA_EMBED_FILES})
add_dependencies(Nostalgia
freetype-object
zlib-object
bz2-object
brotlicommon-object
brotlidec-object
brotlienc-object
png-object
glfw-object
Jolt-object)
target_compile_definitions(Nostalgia PUBLIC
${NOSTALGIA_VERSION_DEFINITION}
${NOSTALGIA_JPH_DEFINITIONS}
$<$<CONFIG:Debug>:NOSTALGIA_DEBUGGING>)
target_compile_options(Nostalgia
PUBLIC $<$<CONFIG:Debug>:-Wall -O0>
PUBLIC $<$<BOOL:${NOSTALGIA_USE_ADDRESS_SANITIZER}>:-g -fsanitize=address>)
target_link_libraries(Nostalgia PRIVATE
freetype-object
zlib-object
bz2-object
brotlicommon-object
brotlidec-object
brotlienc-object
png-object
glfw-object
Jolt-object)
target_precompile_headers(Nostalgia PUBLIC
"$<$<COMPILE_LANGUAGE:CXX>:${NOSTALGIA_PCH_SRC}>"
"$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>")
target_include_directories(Nostalgia
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC ${NOSTALGIA_ROOT}
PRIVATE ${NOSTALGIA_ROOT}/thirdparty
PRIVATE ${NOSTALGIA_ROOT}/thirdparty/glfw/include
PRIVATE ${NOSTALGIA_ROOT}/thirdparty/freetype/include)
if(MSVC)
target_compile_features(Nostalgia PUBLIC cxx_std_23)
target_compile_options(Nostalgia PUBLIC -EHsc)
set_property(TARGET Nostalgia PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(TARGET Jolt PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
target_compile_features(Nostalgia PUBLIC cxx_std_26)
endif()
if(NOSTALGIA_INCLUDE_GLM_HEADERS)
set(NOSTALGIA_HEADERS ${NOSTALGIA_HEADERS} ${NOSTALGIA_GLM_HEADERS})
endif()
if(NOSTALGIA_INCLUDE_JOLT_HEADERS)
set(NOSTALGIA_HEADERS ${NOSTALGIA_HEADERS} ${NOSTALGIA_JOLT_HEADERS})
endif()
if(NOSTALGIA_INSTALL)
# Stolen from JoltPhysics/Build/CMakeLists.txt:338-345
foreach(HEADER_FILE ${NOSTALGIA_HEADERS})
string(REPLACE ${NOSTALGIA_ROOT} "Nostalgia" RELATIVE_HEADER_FILE ${HEADER_FILE})
get_filename_component(DESTINATION_PATH ${RELATIVE_HEADER_FILE} DIRECTORY)
cmake_path(SET DST_FILE NORMALIZE "${CMAKE_INSTALL_INCLUDEDIR}/${DESTINATION_PATH}")
install(FILES ${HEADER_FILE} DESTINATION ${DST_FILE})
endforeach()
# Install the engine last; this lets users install headers without building the library
# it also lets the more important build message show up at the bottom.
if(NOT MSVC)
install(TARGETS Nostalgia DESTINATION lib)
endif()
endif()
################
#### EDITOR ####
################
set(EDITOR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Editor)
if(EDITOR_AND_APPS_USE_GLOBAL_LIBRARY)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
find_library(NOSTALGIA_LIB Nostalgia)
else()
find_library(NOSTALGIA_LIB Nostalgiad)
endif()
endif()
if(BUILD_EDITOR)
set(_EMBED_EDITOR ON)
set(_EMBED_NOSTALGIA OFF)
set(EDITOR_ASSET_FILES editor_icons.hpp editor_models.hpp)
add_custom_command(OUTPUT ${EDITOR_ASSET_FILES}
COMMAND ${CMAKE_COMMAND}
ARGS -D_EMBED_EDITOR=ON -DSOURCE_DIR=${EDITOR_ROOT}/assets -P ${NOSTALGIA_ROOT}/embedded/EmbedAssets.cmake)
add_executable(NostalgiaGoggles ${EDITOR_SRC_FILES} ${EDITOR_ASSET_FILES})
add_dependencies(NostalgiaGoggles Nostalgia)
target_compile_definitions(NostalgiaGoggles PUBLIC $<$<CONFIG:Debug>:NOSTALGIA_DEBUGGING>)
target_compile_options(NostalgiaGoggles
PUBLIC $<$<CONFIG:Debug>:-Wall -O0>
PUBLIC $<$<BOOL:${NOSTALGIA_USE_ADDRESS_SANITIZER}>:-g -fsanitize=address>)
target_include_directories(NostalgiaGoggles
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${EDITOR_ROOT}/thirdparty/freetype ${EDITOR_ROOT}/thirdparty/DearImGui
PUBLIC ${EDITOR_ROOT} ${EDITOR_ROOT}/thirdparty ${NOSTALGIA_ROOT}/thirdparty ${NOSTALGIA_ROOT}/thirdparty/glfw/include)
target_link_libraries(NostalgiaGoggles PUBLIC
$<IF:$<BOOL:${EDITOR_AND_APPS_USE_GLOBAL_LIBRARY}>,${NOSTALGIA_LIB},$<TARGET_FILE:Nostalgia>>)
target_link_options(NostalgiaGoggles
PUBLIC $<$<BOOL:${NOSTALGIA_USE_ADDRESS_SANITIZER}>:-g -fsanitize=address>)
if(MSVC)
target_compile_features(NostalgiaGoggles PUBLIC cxx_std_23)
target_compile_options(NostalgiaGoggles PUBLIC -EHsc)
set_property(TARGET NostalgiaGoggles PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
target_compile_features(NostalgiaGoggles PUBLIC cxx_std_26)
endif()
endif()
##############
## TESTAPPS ##
##############
set(TESTAPP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Tests)
set(TESTAPP_MAIN ${TESTAPP_DIR}/shared_main.cpp)
function(add_test_target TARGET_NAME)
add_dependencies(${TARGET_NAME} Nostalgia)
target_link_libraries(${TARGET_NAME} PUBLIC
$<IF:$<BOOL:${EDITOR_AND_APPS_USE_GLOBAL_LIBRARY}>,${NOSTALGIA_LIB},$<TARGET_FILE:Nostalgia>>)
target_compile_definitions(${TARGET_NAME}
PUBLIC $<$<CONFIG:Debug>:NOSTALGIA_DEBUGGING>)
target_compile_options(${TARGET_NAME}
PUBLIC $<$<CONFIG:Debug>:-Wall -O0>
PUBLIC $<$<BOOL:${NOSTALGIA_USE_ADDRESS_SANITIZER}>:-g -fsanitize=address>)
target_link_options(${TARGET_NAME}
PUBLIC $<$<BOOL:${NOSTALGIA_USE_ADDRESS_SANITIZER}>:-g -fsanitize=address>)
target_include_directories(${TARGET_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${NOSTALGIA_ROOT}/thirdparty)
if(MSVC)
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_23)
target_compile_options(${TARGET_NAME} PUBLIC -EHsc)
set_property(TARGET ${TARGET_NAME} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_26)
endif()
endfunction()
# if(BUILD_TEST)
# add_executable(TestApp ${TESTAPP_MAIN} ${TESTAPP_DIR}/test_app.cpp)
# add_test_target(TestApp)
# endif()