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

Export GLFW targets #2424

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Export GLFW targets #2424

wants to merge 1 commit into from

Conversation

aWilson41
Copy link

@aWilson41 aWilson41 commented Nov 1, 2023

The current cmake code does not export its targets (modern cmake).

If you make a project that uses GLFW with the following CMakeListst.txt I would've expected it to work.

cmake_minimum_required(VERSION 3.16)
project(VulkanExample)

set(CMAKE_CXX_STANDARD 17)
find_package(Vulkan REQUIRED)
find_package(glfw3 REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} Vulkan::Vulkan glfw3::glfw)

With the small change in this PR, the above is possible (without a Findglfw3.cmake file), only specify glfw3_DIR=/src.

Details:

The old cmake solution would've been to write a find file for GLFW. Findglfw3.cmake. But modern cmake makes life easier. GLFW should instead produce glfw3Config.cmake file (already done in GLFW) that imports its own targets. No need to write a find. But this shouldn't effect finds in any way.

When find_package is run it will search glfw3_DIR, cmake path, & system path for a find (old cmake, or non-cmake libs) OR config file (modern).

GLFW config file is produced in /src. When glfw3_DIR=/src is given in a project. It fails to find any targets in the config. Looking at GLFW cmake code, no targets are exported. This PR is a fix for that. It now exports targets and the above cmake should work simply by providing glfw3_DIR=/src. No need for a find.

@gracicot
Copy link
Contributor

gracicot commented Nov 1, 2023

For the records, glfw do export targets. When you install glfw, it correctly writes glfw3Config and all. What you describe and what your PR adds is support for exporting from the build tree.

@elmindreda elmindreda added enhancement Feature suggestions and PRs build Build file bugs and PRs (not compilation errors) labels Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build file bugs and PRs (not compilation errors) enhancement Feature suggestions and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants