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

Can't build a project using add_subdirectory with both glfw and vulkan-loader because of conflicting target names in cmake #1477

Closed
danielmrussell opened this issue May 4, 2019 · 2 comments
Assignees
Labels
bug Bug reports and bugfix pull requests build Build file bugs and PRs (not compilation errors) verified Reproduced or otherwise verified bugs
Milestone

Comments

@danielmrussell
Copy link

danielmrussell commented May 4, 2019

Really frustrating that there is a target named "vulkan" exactly in the glfw cmake project. I am working on an application that uses Vulkan with GLFW, so it shocked the hell out of me that this was an issue.

I really don't want to use ExternalProject or find_package for installed binaries, another nonsense. I want to just use add_subdirectory on both, but cannot.

Really REALLY wished cmake had an option in add_subdirectory for including targets in namepsaces to prevent this problem like:

add_subdirectory( glfw "some/path/to/glfw/subdir" NAMESPACE GLFW )

that would import all targets in the subdir with a prefixed namespace GLFW:, but sadly, this is not a feature in cmake (yet).

In the meantime, can we please make our target names a lot less ambiguous? Cmake is just not that good at this.

@gracicot
Copy link
Contributor

gracicot commented May 4, 2019

My primary suggestion would be to use a package manager such as vcpkg or conan. I understand this may not be possible for you.

If not, then it's worth noting that find_package can also find build trees (uninstalled packages). With glfw it would be to clone and build it, then specifying the prefix to cmake. So to build your project, the cmake command should be:

cmake .. -DCMAKE_PREFIX_PATH=../../glfw

If you have many packages and don't want to list them all out, you also can set all the prefix path in a toolchain file:

list(APPEND CMAKE_PREFIX_PATH path/to/lib1/tree)
list(APPEND CMAKE_PREFIX_PATH path/to/lib2/tree)

Then use it:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../your-toolchain.cmake

The problem with add_subdirectory(...) is that you effectively says glfw are my sources. Which is not what you want. You also don't want to install all libraries into your system, which is totally understandable. Fortunately, find_package can also find other project on your system and can also have arbitrary installation folder, including a third_party directory in your project.

I know use that thing you don't want instead is not nice to get as an answer, but add_subdirectory won't resolve variable or target conflict since it's primarly meant to split one project into parts.

@elmindreda elmindreda self-assigned this May 17, 2019
@elmindreda elmindreda added bug Bug reports and bugfix pull requests build Build file bugs and PRs (not compilation errors) verified Reproduced or otherwise verified bugs labels May 17, 2019
@elmindreda elmindreda added this to the 3.3.1 milestone May 17, 2019
@elmindreda
Copy link
Member

elmindreda commented May 24, 2019

@danielmrussell Yep, it's a bad name. The program has been renamed to triangle-vulkan.

elmindreda added a commit that referenced this issue May 29, 2019
Fixes #1477.

(cherry picked from commit d834f01)
m4ce-w1ndu pushed a commit to m4ce-w1ndu/glfw that referenced this issue Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports and bugfix pull requests build Build file bugs and PRs (not compilation errors) verified Reproduced or otherwise verified bugs
Projects
None yet
Development

No branches or pull requests

3 participants