@@ -13,6 +13,53 @@ nbl_create_ext_library_project(ExamplesAPI "" "${CMAKE_CURRENT_SOURCE_DIR}/src/n
13
13
set_target_properties (${LIB_NAME} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF )
14
14
target_precompile_headers (${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR} /include/nbl/examples/PCH.hpp" )
15
15
16
+ function (REGISTER_COMMON_BUILTINS )
17
+ cmake_parse_arguments (EX "" "TARGET;ARCHIVE_ABS_ENTRY;ARCHIVE_NAMESPACE" "GLOB_RGX" ${ARGN} )
18
+
19
+ get_filename_component (INPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} " ABSOLUTE )
20
+ get_filename_component (OUTPUT_SRC "${CMAKE_CURRENT_BINARY_DIR} /builtin/${EX_TARGET} /src" ABSOLUTE )
21
+ get_filename_component (OUTPUT_INCLUDE "${CMAKE_CURRENT_BINARY_DIR} /builtin/${EX_TARGET} /include" ABSOLUTE )
22
+
23
+ set (KEYS_ENTRY "${INPUT_DIRECTORY} /${EX_ARCHIVE_ABS_ENTRY} " )
24
+ list (TRANSFORM EX_GLOB_RGX PREPEND "${KEYS_ENTRY} /" )
25
+ file (GLOB_RECURSE KEYS RELATIVE "${KEYS_ENTRY} " CONFIGURE_DEPENDS ${EX_GLOB_RGX} )
26
+
27
+ #[[
28
+ note we do force you to specify full globbing expressions relative to keys entry which we do not filter
29
+ because if runtime outputs .spv compilation artifacts/shader cache preprocessed.hlsl(s) to source you will hit CMake
30
+ reconfiguration each time the file content or timestampts change and it could lead to embeding intermediate trash
31
+ ]]
32
+
33
+ unset (EXAMPLES_RESOURCES_TO_EMBED )
34
+ foreach (KEY IN LISTS KEYS )
35
+ LIST_BUILTIN_RESOURCE (EXAMPLES_RESOURCES_TO_EMBED "${KEY} " )
36
+ endforeach ()
37
+
38
+ ADD_CUSTOM_BUILTIN_RESOURCES (${EX_TARGET} EXAMPLES_RESOURCES_TO_EMBED "${INPUT_DIRECTORY} " "${EX_ARCHIVE_ABS_ENTRY} " "${EX_ARCHIVE_NAMESPACE} " "${OUTPUT_INCLUDE} " "${OUTPUT_SRC} " )
39
+
40
+ # even though builtin target is static library its still valid to reuse common PCH to boost its build speed to not preprocess entire Nabla again
41
+ set_target_properties (${EX_TARGET} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF )
42
+ target_precompile_headers (${EX_TARGET} REUSE_FROM "${LIB_NAME} " )
43
+
44
+ target_include_directories (${EX_TARGET} PUBLIC "${INPUT_DIRECTORY} /include" )
45
+ target_link_libraries (${EX_TARGET} INTERFACE ${LIB_NAME} )
46
+ endfunction ()
47
+
48
+ #! common example API builtins as static library targets linked to each example
49
+ if (NBL_EMBED_BUILTIN_RESOURCES )
50
+ REGISTER_COMMON_BUILTINS (TARGET NblExtExamplesAPIBuiltinsSource
51
+ ARCHIVE_ABS_ENTRY src/nbl/examples
52
+ ARCHIVE_NAMESPACE nbl::builtin::examples::src
53
+ GLOB_RGX *.hlsl *.txt
54
+ )
55
+
56
+ REGISTER_COMMON_BUILTINS (TARGET NblExtExamplesAPIBuiltinsInclude
57
+ ARCHIVE_ABS_ENTRY include /nbl/examples
58
+ ARCHIVE_NAMESPACE nbl::builtin::examples::include
59
+ GLOB_RGX *.hpp *.h *.hlsl *.txt
60
+ )
61
+ endif ()
62
+
16
63
#! Examples API common libraries
17
64
#[[
18
65
The rule is to avoid creating additional libraries as part of the examples' common
@@ -24,7 +71,8 @@ target_precompile_headers(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/includ
24
71
but If you have a good reason to create library because you cannot make it header only
25
72
AND you *can REUSE* the examples' PCH then go ahead anyway and put it under `src/nbl/examples`,
26
73
otherwise keep it header only - a good example would be to use our embedded-whatever-you-want tool
27
- which does create library but can reuse example's PCH
74
+ which does create library but can reuse example's PCH (see NblExtExamplesAPIBuiltinsSource
75
+ and NblExtExamplesAPIBuiltinsInclude targets)
28
76
]]
29
77
30
78
#! NOTE: as I write it we don't have any targets there yet
@@ -35,7 +83,7 @@ list(REMOVE_ITEM TARGETS ${LIB_NAME})
35
83
36
84
# the Examples API proxy library CMake target name
37
85
#[[
38
- this one gets linked to each executable automatically
86
+ this one gets linked to each executable automatically with its interface libraries
39
87
]]
40
88
set (NBL_EXAMPLES_API_TARGET ${LIB_NAME} PARENT_SCOPE )
41
89
@@ -45,4 +93,6 @@ set(NBL_EXAMPLES_API_TARGET ${LIB_NAME} PARENT_SCOPE)
45
93
then you must target_link_libraries() the lib you want as we
46
94
don't link all those libraries to each executable automatically
47
95
]]
48
- set (NBL_EXAMPLES_API_LIBRARIES ${TARGETS} PARENT_SCOPE )
96
+ set (NBL_EXAMPLES_API_LIBRARIES ${TARGETS} PARENT_SCOPE )
97
+
98
+ NBL_ADJUST_FOLDERS (common )
0 commit comments