-
Notifications
You must be signed in to change notification settings - Fork 42
/
CMakeLists.txt.island_prolog.in
365 lines (279 loc) · 15.8 KB
/
CMakeLists.txt.island_prolog.in
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
# Hot-reloading is enabled by default for debug target,
# whilst release target are built as statically linked
# binaries by default.
# This can be changed on a project-by-project basis, as
# we only set initial default settings here.
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# we enable hot-reloading by default for debug target
set(PLUGINS_DYNAMIC ON CACHE BOOL "Use dynamic linking for all plugins")
else()
# we disdable hot-reloading by default for release target
set(PLUGINS_DYNAMIC OFF CACHE BOOL "Use dynamic linking for all plugins")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# manually set that we want to use libc pthread - there seems to be an
# issue with detecting Thread support, otherwise.
set (CMAKE_HAVE_LIBC_PTHREAD TRUE)
# use lld linker for clang-compiled binary - it's faster than gnu ld,
# and you don't have to worry about the linking order for libraries.
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-fuse-ld=lld -Wno-unused-command-line-argument")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-fuse-ld=lld -Wno-unused-command-line-argument")
endif()
set ( STATIC_LIBRARIES "" CACHE INTERNAL "static_libraries" )
set ( DEPENDENCY_DEPTH 0 CACHE INTERNAL "current depth in dependency hierarchy" )
set(CMAKE_DEBUG_POSTFIX "" CACHE STRING "Suffix for debug builds" FORCE)
set ( PLUGIN_LIBS_DEPENDENCIES "" CACHE INTERNAL "plugins_libs_dependencies" )
set ( PLUGIN_LINK_DIRS "")
set ( CMAKE_DEBUG_POSTFIX "" CACHE STRING "Suffix for debug builds" FORCE )
# specify output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE PATH "" FORCE )
set(CMAKE_MODULE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modules" CACHE PATH "" FORCE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modules" CACHE PATH "archive output directory" FORCE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modules" CACHE PATH "" FORCE )
# get git commit version for island framework
execute_process(COMMAND
git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty
WORKING_DIRECTORY "${ISLAND_BASE_DIR}"
OUTPUT_VARIABLE ISLAND_GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
function (link_resources param_target param_link_name)
# create a link to local resources
if (WIN32)
if (EXISTS "${param_link_name}")
message(STATUS "local resources exists ${param_link_name}")
else()
get_filename_component(real_path "${param_link_name}" REALPATH)
string(REPLACE "/" "\\" target_path "${real_path}")
get_filename_component(real_path "${param_target}" REALPATH)
string(REPLACE "/" "\\" src_path "${real_path}")
execute_process(COMMAND cmd /C mklink /J "${target_path}" "${src_path}"
RESULT_VARIABLE link_result
OUTPUT_VARIABLE link_output)
message(STATUS "created symbolic link ${target_path} ${src_path} ${link_output} ${link_result}")
endif()
else()
if (EXISTS "${param_link_name}")
message(STATUS "Link already exists: '${param_link_name}'")
else()
get_filename_component( tmp_link_dir "${param_link_name}" DIRECTORY )
execute_process(COMMAND mkdir -p "${tmp_link_dir}" )
execute_process(COMMAND ln -sfn "${param_target}" "${param_link_name}" )
message(STATUS "Created symbolic link '${param_link_name}' → '${param_target}'" )
endif()
endif()
endfunction(link_resources)
# Adds a directory to the modules locations
macro(add_island_module_location MODULE_LOCATION)
set( MODULE_LOCATIONS_LIST ${MODULE_LOCATIONS_LIST} ${MODULE_LOCATION} CACHE INTERNAL "module_locations_list" )
# include_directories( "${MODULE_LOCATIONS_LIST}")
endmacro()
function(include_using_absolute_path TMP_INCLUDE_PATH)
get_filename_component(TMP_INCLUDE_PATH_ABS ${TMP_INCLUDE_PATH} REALPATH BASE_DIR ${ISLAND_BASE_DIR})
include_directories(${TMP_INCLUDE_PATH_ABS})
endfunction()
# include the island base directory
include_using_absolute_path("${ISLAND_BASE_DIR}")
include_using_absolute_path("${ISLAND_BASE_DIR}/modules/le_core")
# We will store all possible module locations in this list, if the same module exists in multiple locations, the last one will be used
set ( MODULE_LOCATIONS_LIST CACHE INTERNAL "module_locations_list")
# Set default island module location
add_island_module_location("${ISLAND_BASE_DIR}/modules")
# We will store all loaded module names in this global list, so that we can make sure that modules don't get loaded more than once.
set ( LOADED_MODULES_LIST CACHE INTERNAL "loaded_modules_list" )
# We will store all requested module names in this global list, to keep track of all modules which have been requested.
# once this list is empty we know there are no more modules which need to be loaded.
set ( REQUESTED_MODULES_LIST CACHE INTERNAL "requested_modules_list" )
# These modules are always loaded - they control the plugin system.
set ( ISLAND_LOADER_MODULES le_log;le_file_watcher;le_core )
# These modules from the renderer - if you want to draw graphics, you want these.
# Note that order matters: dependent modules must be named before their dependencies.
set ( CORE_ISLAND_MODULES le_pipeline_builder;le_window;le_backend_vk;le_renderer;le_swapchain_vk;le_jobs;le_shader_compiler)
if (REQUIRES_ISLAND_CORE)
# add glm include directory to includes search path
include_using_absolute_path("${ISLAND_BASE_DIR}/3rdparty/src/glm/")
# create a link to project specific resources in runtime output directory
if (EXISTS ${PROJECT_SOURCE_DIR}/resources)
link_resources("${PROJECT_SOURCE_DIR}/resources" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/local_resources")
endif()
# create a link to shared resources
link_resources(${ISLAND_BASE_DIR}/resources ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources )
# Check if a local copy of the Vulkan SDK exists, and the environment VULKAN_SDK points to it.
# If yes, use this directory for header includes, and linking.
#
set (VULKAN_SDK_ENV $ENV{VULKAN_SDK})
if (EXISTS ${VULKAN_SDK_ENV})
#include vulkan from SDK installation directory
include_directories(${VULKAN_SDK_ENV}/include/)
# NOTE: We're linking Vulkan from this system's Vulkan SDK directory
link_directories(${VULKAN_SDK_ENV}/lib)
endif(EXISTS ${VULKAN_SDK_ENV})
endif()
# Add required modules to modules list based on user flags
#
if (REQUIRES_ISLAND_LOADER)
list (APPEND REQUESTED_MODULES_LIST ${ISLAND_LOADER_MODULES})
endif()
if (REQUIRES_ISLAND_CORE)
list (APPEND REQUESTED_MODULES_LIST ${CORE_ISLAND_MODULES})
endif()
# ----------------------------------------------------------------------
macro(add_static_lib LIB_NAME)
if (NOT ${LIB_NAME} IN_LIST STATIC_LIBRARIES})
set ( STATIC_LIBRARIES ${LIB_NAME} $CACHE{STATIC_LIBRARIES} CACHE INTERNAL "static_libraries" )
# message( STATUS "${TMP_INDENT}>>> Static libs: ${STATIC_LIBRARIES}")
else()
# set (STATIC_LIBRARIES ${STATIC_LIBRARIES} PARENT_SCOPE)
message( STATUS "[ NOTE ] Rejecting extra static lib addition: `${LIB_NAME}` - lib already present." )
endif()
endmacro(add_static_lib LIB_NAME)
# ----------------------------------------------------------------------
macro(print_current_includes)
message(STATUS "${TMP_INDENT}includes for ${CMAKE_CURRENT_SOURCE_DIR}:")
get_directory_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "${TMP_INDENT}include='${dir}'")
endforeach()
message(STATUS "${TMP_INDENT}\n")
endmacro()
# ----------------------------------------------------------------------
# find module - set MODULE_LOCATION in the function's parent scope to
# any found location. MODULE_LOCATION is set to "" if nothing is found.
function(find_module MODULE_LOCATION MODULE_NAME )
# look for the module in all given locations
set( MODULE_LOCATION "" PARENT_SCOPE)
foreach( LOCATION ${MODULE_LOCATIONS_LIST} )
set( CURRENT_LOCATION "${LOCATION}/${MODULE_NAME}" )
if( EXISTS ${CURRENT_LOCATION} )
get_filename_component(CURRENT_LOCATION ${CURRENT_LOCATION} REALPATH BASE_DIR ${ISLAND_BASE_DIR})
set( MODULE_LOCATION ${CURRENT_LOCATION} PARENT_SCOPE)
endif()
endforeach()
endfunction()
# ----------------------------------------------------------------------
# Loads a requested module - note that this may recursively
# trigger loading more modules, as modules are added via
# add_subdirectory, which evaluates their cmake.txt file.
macro(include_island_module MODULE_NAME SHOULD_ADD)
find_module(MODULE_LOCATION ${MODULE_NAME} ) # sets MODULE_LOCATION
# message(STATUS "${TMP_INDENT}Module location : ${MODULE_LOCATION}")
if( MODULE_LOCATION )
set ( TMP_INDENT "")
string(REPEAT " " ${DEPENDENCY_DEPTH} TMP_INDENT)
get_directory_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} INCLUDE_DIRECTORIES)
if (NOT ${MODULE_LOCATION} IN_LIST dirs)
# message(STATUS "${TMP_INDENT}Loading module : ${MODULE_NAME}")
include_directories( "${MODULE_LOCATION}")
# message(STATUS "${TMP_INDENT}+++ Adding include : ${MODULE_LOCATION}")
endif()
# set_directory_properties()
if ( ${SHOULD_ADD} )
message(STATUS "${TMP_INDENT} ${MODULE_NAME}")
add_subdirectory( ${MODULE_LOCATION} ${MODULE_NAME} )
endif()
# print_current_includes()
else()
message( SEND_ERROR "Module not found : ${MODULE_NAME}")
endif()
endmacro()
# ----------------------------------------------------------------------
# Call this macro from other modules to establish a dependency.
# Adds a module name to list of requested modules,
# checks whether a module was already requested to prevent duplicates.
macro(request_island_module MODULE_NAME)
if (NOT ${MODULE_NAME} IN_LIST LOADED_MODULES_LIST)
# prepend module name to loaded_modules_list in global scope
set( REQUESTED_MODULES_LIST ${MODULE_NAME} ${REQUESTED_MODULES_LIST} CACHE INTERNAL "requested modules_list" )
include_island_module( ${MODULE_NAME} FALSE )
else()
include_island_module( ${MODULE_NAME} FALSE )
# message(STATUS "[ NOTE ] Rejecting add_island_module request: `${MODULE_NAME}` - Module already present." )
endif()
endmacro(request_island_module)
# ----------------------------------------------------------------------
# Call this macro from other modules to establish a dependency.
# Adds a module name to list of requested modules,
# checks whether a module was already requested to prevent duplicates.
macro(load_island_module MODULE_NAME)
if (NOT ${MODULE_NAME} IN_LIST LOADED_MODULES_LIST)
# prepend module name to loaded_modules_list in global scope
set( LOADED_MODULES_LIST ${LOADED_MODULES_LIST} ${MODULE_NAME} CACHE INTERNAL "loaded_modules_list" )
include_island_module( ${MODULE_NAME} TRUE )
else()
include_island_module( ${MODULE_NAME} FALSE )
message(STATUS "[ NOTE ] Rejecting load_island_module request: `${MODULE_NAME}` - Module already present." )
endif()
endmacro(load_island_module)
# ----------------------------------------------------------------------
macro (depends_on_island_module MODULE_NAME)
math( EXPR TMP_DEPENDENCY_DEPTH "$CACHE{DEPENDENCY_DEPTH}+1")
set ( DEPENDENCY_DEPTH ${TMP_DEPENDENCY_DEPTH} CACHE INTERNAL "current depth in dependency hierarchy" )
set ( TMP_INDENT "")
string(REPEAT " " ${DEPENDENCY_DEPTH} TMP_INDENT)
get_filename_component(THIS_MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE )
message(STATUS "${TMP_INDENT} ${THIS_MODULE_NAME} ← ${MODULE_NAME}")
request_island_module(${MODULE_NAME})
math( EXPR TMP_DEPENDENCY_DEPTH "$CACHE{DEPENDENCY_DEPTH}-1")
set ( DEPENDENCY_DEPTH ${TMP_DEPENDENCY_DEPTH} CACHE INTERNAL "current depth in dependency hierarchy" )
endmacro(depends_on_island_module)
# ----------------------------------------------------------------------
macro(add_dynamic_linker_flags)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# IMPORTANT: --no-gnu-unique for gcc compiler
#
# This compiler flag is neccesary as otherwise the library may get compiled
# with some symbols exported as UNIQUE, which implicitly makes this library
# un-closeable. This means, any calls to `dlclose` on this library, once
# loaded, will have no effect, and autoreload for this library will not work
# as the first version of the library will remain resident.
target_compile_options (${TARGET} PUBLIC --no-gnu-unique)
endif()
if (WIN32 AND NOT ${TARGET} MATCHES "le_core")
# On windows, when hot-reloading, we must make sure we can actually write
# our artifacts even if the program is running. To be sure, we attempt to
# first move any old artifacts which may still be in use by renaming them.
#
set(TARGET_ARTIFACT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}")
add_custom_command(TARGET ${TARGET}
PRE_LINK
COMMAND ${CMAKE_COMMAND}
-DFileToCheck=${TARGET_ARTIFACT}.dll
-DMethod=Rename
-P ${ISLAND_BASE_DIR}/CMakeLists.txt.rename_artifact.in
COMMENT "Checking if ${TARGET_ARTIFACT}.dll exists...")
add_custom_command(TARGET ${TARGET}
PRE_LINK
COMMAND ${CMAKE_COMMAND}
-DFileToCheck=${TARGET_ARTIFACT}.pdb
-DMethod=Rename
-P ${ISLAND_BASE_DIR}/CMakeLists.txt.rename_artifact.in
COMMENT "Checking if ${TARGET_ARTIFACT}.pdb exists...")
# To signal to the hot-reloading file watcher that a re-compile has occured,
# we touch a flag file which shares the same basename as the artifact, and
# has the file ending ".flag" - We want to update this only at the very end
# of the build process to make sure that all file writing operations have
# completed - if we watch the .dll directly there is a chance that the hot-
# reloading mechanism gets triggered mutliple times because the .dll may get
# accessed a couple of times during the build process.
#
# by using a flag file which we touch only once at the end of the build we
# whould have a fairly atomic marker by which to tell whether the build
# process has truly completed.
add_custom_command(TARGET ${TARGET}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DFileToCheck=${TARGET_ARTIFACT}.flag
-DMethod=Touch
-P ${ISLAND_BASE_DIR}/CMakeLists.txt.rename_artifact.in
COMMENT "Touchting ${TARGET_ARTIFACT}.flag")
# additionally, we don't want incremental linking, because that will
# fail anyway, for it won't be able to find the last version of the .dll,
# since we've just removed it.
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/INCREMENTAL:NO")
# on windows we must link all libaries with le_core so that they can find
# le_core's exported functions which are used for loading module apis.
target_link_libraries(${TARGET} PRIVATE "le_core" )
endif()
endmacro(add_dynamic_linker_flags)
# ----------------------------------------------------------------------
set( REQUESTED_MODULES_LIST ${REQUESTED_MODULES_LIST} ${MODULE_NAME} CACHE INTERNAL "requested modules_list" )