You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using bgfx in a setup where it is first built and installed on the system. In my project, I then attempt to import it with:
find_package(bgfx)
This approach allows me to use bgfx::* targets (e.g. bgfx::shaderc) within the same CMake project where find_package(bgfx) is called. However, if I call find_package(bgfx) within a subdirectory, I cannot access bgfx targets from the parent project directory.
It seems that this limitation occurs because the bgfxTargets.cmake file (installed in ${CMAKE_INSTALL_PREFIX}/lib/cmake/bgfx) defines targets like bgfx::shaderc using add_executable(bgfx::shaderc IMPORTED) but without the GLOBAL option.
As per the CMake documentation on add_executable, omitting the GLOBAL option restricts target visibility to the scope where find_package(bgfx) is called.
Notably, this behavior is inconsistent with a scenario where add_subdirectory(bgfx.cmake) is used instead of find_package(bgfx). In that case, targets like bgfx::shaderc are accessible globally.
Could this omission of the GLOBAL flag be an oversight? If not, could you explain the reasoning behind this design choice?
[...]
find_package(bgfx)
# Here I can use the target `bgfx::shaderc`
OuterProject/CMakeLists.txt:
[...]
add_subdirectory(InnerProject)
# Here, `bgfx::shaderc` is not accessible, though I can call `bgfx` utility functions like `bgfx_compile_shaders` (they just fail at build time).
I am using
bgfx
in a setup where it is first built and installed on the system. In my project, I then attempt to import it with:This approach allows me to use
bgfx::*
targets (e.g.bgfx::shaderc
) within the same CMake project wherefind_package(bgfx)
is called. However, if I callfind_package(bgfx)
within a subdirectory, I cannot access bgfx targets from the parent project directory.It seems that this limitation occurs because the
bgfxTargets.cmake
file (installed in${CMAKE_INSTALL_PREFIX}/lib/cmake/bgfx
) defines targets likebgfx::shaderc
usingadd_executable(bgfx::shaderc IMPORTED)
but without theGLOBAL
option.As per the CMake documentation on
add_executable
, omitting theGLOBAL
option restricts target visibility to the scope wherefind_package(bgfx)
is called.Notably, this behavior is inconsistent with a scenario where
add_subdirectory(bgfx.cmake)
is used instead offind_package(bgfx)
. In that case, targets likebgfx::shaderc
are accessible globally.Could this omission of the
GLOBAL
flag be an oversight? If not, could you explain the reasoning behind this design choice?=====
Example with
find_package(bgfx)
:Project Tree:
InnerProject/CMakeLists.txt
:OuterProject/CMakeLists.txt
:=====
Example with
add_subdirectory(bgfx.cmake)
:Project Tree:
InnerProject/CMakeLists.txt
:OuterProject/CMakeLists.txt
:The text was updated successfully, but these errors were encountered: