@@ -26,22 +26,39 @@ class IApplicationFramework : public core::IReferenceCounted
2626 static bool GlobalsInit ()
2727 {
2828 // TODO: update CMake and rename "DLL" in all of those defines here to "MODULE" or "RUNTIME"
29-
30- auto getEnvInstallDirectory = []()
29+ auto resolveDir = [](const char * value)
3130 {
32- const char * sdk = std::getenv (" NBL_INSTALL_DIRECTORY" );
31+ if (!value || (value[0 ] == ' \0 ' ))
32+ return system::path (" " );
3333
34- if (sdk)
35- {
36- const auto directory = system::path (sdk);
37-
38- if (std::filesystem::exists (directory))
39- return directory;
40- }
34+ const auto candidate = system::path (value);
35+ if (std::filesystem::exists (candidate))
36+ return candidate;
4137
4238 return system::path (" " );
4339 };
4440
41+ auto readEnvFlag = [](const char * key)
42+ {
43+ const char * value = std::getenv (key);
44+ if (!value || (value[0 ] == ' \0 ' ))
45+ return false ;
46+
47+ const std::string_view v (value);
48+ return (v != " 0" ) && (v != " false" ) && (v != " off" ) && (v != " no" );
49+ };
50+
51+ const auto sdk = resolveDir (std::getenv (" NBL_INSTALL_DIRECTORY" ));
52+
53+ #ifdef NBL_RELOCATABLE_PACKAGE
54+ // Relocatable package consumers must use install lookups only.
55+ const bool useInstallLookups = true ;
56+ #else
57+ // Build-interface binaries select lookup mode at runtime via NBL_RUN_FROM_BUILD_INTERFACE.
58+ // This is required because the same host-built executable can later be run from an install package.
59+ const bool useInstallLookups = !readEnvFlag (" NBL_RUN_FROM_BUILD_INTERFACE" );
60+ #endif // NBL_RELOCATABLE_PACKAGE
61+
4562 constexpr struct
4663 {
4764 std::string_view nabla, dxc;
@@ -56,8 +73,6 @@ class IApplicationFramework : public core::IReferenceCounted
5673 " dxcompiler"
5774 };
5875
59- const auto sdk = getEnvInstallDirectory ();
60-
6176 struct
6277 {
6378 system::path nabla, dxc;
@@ -70,6 +85,7 @@ class IApplicationFramework : public core::IReferenceCounted
7085 install.dxc = std::filesystem::absolute (system::path (_NABLA_INSTALL_DIR_) / NBL_CPACK_PACKAGE_DXC_DLL_DIR_ABS_KEY);
7186 #endif
7287
88+ // ! ABS key is full key to file inside relocatable package
7389 env.nabla = sdk / NBL_CPACK_PACKAGE_NABLA_DLL_DIR_ABS_KEY;
7490 env.dxc = sdk / NBL_CPACK_PACKAGE_DXC_DLL_DIR_ABS_KEY;
7591 #endif
@@ -83,6 +99,7 @@ class IApplicationFramework : public core::IReferenceCounted
8399 build.dxc = path (_DXC_DLL_).parent_path ();
84100 #endif
85101
102+ // ! consumer can set this as relative path between exe & DLLs
86103 #ifdef NBL_CPACK_PACKAGE_NABLA_DLL_DIR
87104 rel.nabla = NBL_CPACK_PACKAGE_NABLA_DLL_DIR;
88105 #endif
@@ -91,7 +108,8 @@ class IApplicationFramework : public core::IReferenceCounted
91108 rel.dxc = NBL_CPACK_PACKAGE_DXC_DLL_DIR;
92109 #endif
93110
94- auto load = [](std::string_view moduleName, const std::vector<system::path>& searchPaths)
111+ using RV = const std::vector<system::path>;
112+ auto load = [](std::string_view moduleName, const RV& searchPaths)
95113 {
96114 #ifdef _NBL_PLATFORM_WINDOWS_
97115 const bool isAlreadyLoaded = GetModuleHandleA (moduleName.data ());
@@ -114,19 +132,11 @@ class IApplicationFramework : public core::IReferenceCounted
114132 return true ;
115133 };
116134
117- #ifdef NBL_RELOCATABLE_PACKAGE
118- if (not load (module .dxc , { env.dxc , rel.dxc , install.dxc }))
119- #else
120- if (not load (module .dxc , { build.dxc }))
121- #endif
135+ if (not load (module .dxc , useInstallLookups ? RV{ rel.dxc , env.dxc , install.dxc } : RV{ build.dxc }))
122136 return false ;
123137
124138 #ifdef _NBL_SHARED_BUILD_
125- #ifdef NBL_RELOCATABLE_PACKAGE
126- if (not load (module .nabla , { env.nabla , rel.nabla , install.nabla }))
127- #else
128- if (not load (module .nabla , { build.nabla }))
129- #endif
139+ if (not load (module .nabla , useInstallLookups ? RV{ rel.nabla , env.nabla , install.nabla } : RV{ build.nabla }))
130140 return false ;
131141 #endif
132142
0 commit comments