Skip to content

Instantly share code, notes, and snippets.

@aniongithub
Last active February 25, 2025 07:16
Show Gist options
  • Save aniongithub/1f6c1206afc4f39262448b876ad411c2 to your computer and use it in GitHub Desktop.
Save aniongithub/1f6c1206afc4f39262448b876ad411c2 to your computer and use it in GitHub Desktop.
Use glad as a static lib with CMake FetchContent
...
# https://github.com/Dav1dde/glad/issues/397#issue-1463640603
# This doesn't work out of the box with conflicting targets, forcing shared libs, etc.
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # Ugly way to force static glad build
# Fetch GLAD from GitHub
FetchContent_Declare(glad_src
GIT_REPOSITORY https://github.com/Dav1dde/glad.git
GIT_TAG v0.1.36)
set(GLAD_PROFILE "core" CACHE STRING "OpenGL profile")
set(GLAD_GENERATOR "c" CACHE STRING "Language to generate the binding for")
FetchContent_MakeAvailable(glad_src)
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) # Ugly way to force static glad build
set_property(TARGET glad PROPERTY POSITION_INDEPENDENT_CODE ON) # fPIC
...
# Now this works fine
target_link_libraries(${PROJECT_NAME}
PRIVATE
glad
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment