Skip to content

Commit bb68b7b

Browse files
committed
create REGISTER_COMMON_BUILTINS, register example API source & include archives, update common/include/nbl/examples/common/BuiltinResourcesApplication.hpp and test on 09 example
1 parent 1b3c19c commit bb68b7b

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ if(NBL_BUILD_EXAMPLES)
9595
target_link_libraries(${T} PUBLIC ${NBL_EXAMPLES_API_TARGET})
9696
target_include_directories(${T} PUBLIC $<TARGET_PROPERTY:${NBL_EXAMPLES_API_TARGET},INCLUDE_DIRECTORIES>)
9797
target_precompile_headers(${T} REUSE_FROM "${NBL_EXAMPLES_API_TARGET}")
98+
LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsSource)
99+
LINK_BUILTIN_RESOURCES_TO_TARGET(${T} NblExtExamplesAPIBuiltinsInclude)
98100
endforeach()
99101

100102
NBL_ADJUST_FOLDERS(examples)

common/CMakeLists.txt

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,53 @@ nbl_create_ext_library_project(ExamplesAPI "" "${CMAKE_CURRENT_SOURCE_DIR}/src/n
1313
set_target_properties(${LIB_NAME} PROPERTIES DISABLE_PRECOMPILE_HEADERS OFF)
1414
target_precompile_headers(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/nbl/examples/PCH.hpp")
1515

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+
1663
#! Examples API common libraries
1764
#[[
1865
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
2471
but If you have a good reason to create library because you cannot make it header only
2572
AND you *can REUSE* the examples' PCH then go ahead anyway and put it under `src/nbl/examples`,
2673
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)
2876
]]
2977

3078
#! NOTE: as I write it we don't have any targets there yet
@@ -35,7 +83,7 @@ list(REMOVE_ITEM TARGETS ${LIB_NAME})
3583

3684
# the Examples API proxy library CMake target name
3785
#[[
38-
this one gets linked to each executable automatically
86+
this one gets linked to each executable automatically with its interface libraries
3987
]]
4088
set(NBL_EXAMPLES_API_TARGET ${LIB_NAME} PARENT_SCOPE)
4189

@@ -45,4 +93,6 @@ set(NBL_EXAMPLES_API_TARGET ${LIB_NAME} PARENT_SCOPE)
4593
then you must target_link_libraries() the lib you want as we
4694
don't link all those libraries to each executable automatically
4795
]]
48-
set(NBL_EXAMPLES_API_LIBRARIES ${TARGETS} PARENT_SCOPE)
96+
set(NBL_EXAMPLES_API_LIBRARIES ${TARGETS} PARENT_SCOPE)
97+
98+
NBL_ADJUST_FOLDERS(common)

common/include/nbl/examples/common/BuiltinResourcesApplication.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include "nbl/application_templates/MonoAssetManagerApplication.hpp"
1010

1111
#ifdef NBL_EMBED_BUILTIN_RESOURCES
12-
// TODO: the include/header `nbl/examples` archive
13-
// TODO: the source `nbl/examples` archive
14-
// TODO: the build `nbl/examples` archive
12+
#include "nbl/builtin/examples/include/CArchive.h"
13+
#include "nbl/builtin/examples/src/CArchive.h"
14+
// TODO: the build `nbl/examples` archive
1515
#if __has_include("nbl/this_example/builtin/CArchive.h")
1616
#include "nbl/this_example/builtin/CArchive.h"
1717
#endif
@@ -42,7 +42,10 @@ class BuiltinResourcesApplication : public virtual application_templates::MonoAs
4242

4343
smart_refctd_ptr<system::IFileArchive> examplesHeaderArch,examplesSourceArch,examplesBuildArch,thisExampleArch;
4444
#ifdef NBL_EMBED_BUILTIN_RESOURCES
45-
// TODO: the 3 examples archives
45+
examplesHeaderArch = core::make_smart_refctd_ptr<nbl::builtin::examples::include::CArchive>(smart_refctd_ptr(m_logger));
46+
examplesSourceArch = core::make_smart_refctd_ptr<nbl::builtin::examples::src::CArchive>(smart_refctd_ptr(m_logger));
47+
// TODO: the build archive
48+
4649
#ifdef _NBL_THIS_EXAMPLE_BUILTIN_C_ARCHIVE_H_
4750
thisExampleArch = make_smart_refctd_ptr<nbl::this_example::builtin::CArchive>(smart_refctd_ptr(m_logger));
4851
#endif

0 commit comments

Comments
 (0)