Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgfx targets not visible globally when imported via find_package(bgfx) #251

Open
alemuntoni opened this issue Oct 28, 2024 · 0 comments
Open

Comments

@alemuntoni
Copy link

alemuntoni commented Oct 28, 2024

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?

=====

Example with find_package(bgfx):

Project Tree:

.
└── OuterProject/
    ├── CMakeLists.txt
    └── InnerProject/
        └── CMakeLists.txt

InnerProject/CMakeLists.txt:

[...]
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).

=====

Example with add_subdirectory(bgfx.cmake):

Project Tree:

.
└── OuterProject/
    ├── CMakeLists.txt
    └── InnerProject/
        ├── bgfx.cmake/
        │   └── ...
        └── CMakeLists.txt

InnerProject/CMakeLists.txt:

[...]
add_subdirectory(bgfx.cmake)

# Here I can use `bgfx::shaderc`

OuterProject/CMakeLists.txt:

[...]
add_subdirectory(InnerProject)

# Here `bgfx::shaderc` is accessible as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant