Skip to content

How to add glad2 as a dependency using CMake with FetchContent_Declare and FetchContent_MakeAvailable? #426

Answered by nolmoonen
junglie85 asked this question in Q&A
Discussion options

You must be logged in to vote

As the original poster alludes to, the GLAD CMakeLists.txt is not in the project root, so a workaround is needed. With the SOURCE_SUBDIR option of FetchContent_Declare you can specify an alternative directory to use as the top of the CMake source tree, which is relative to the top directory of the populated content. So a full example would be:

FetchContent_Declare(
    glad
    GIT_REPOSITORY https://github.com/Dav1dde/glad.git
    GIT_TAG        658f48e72aee3c6582e80b05ac0f8787a64fe6bb #v2.0.6
    GIT_PROGRESS   TRUE
    SOURCE_SUBDIR  cmake
)
FetchContent_MakeAvailable(glad)
glad_add_library(glad_gl_core_43 STATIC REPRODUCIBLE LOADER API gl:core=4.3)
target_link_libraries(my_target PRIVATE

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Dav1dde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #425 on May 06, 2023 13:49.