Dav1dde / glad

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
https://glad.dav1d.de/
Other
3.73k stars 440 forks source link

GLAD cmake command "ExternalProject_Add" #376

Closed petrasvestartas closed 1 year ago

petrasvestartas commented 2 years ago

Hi,

How can I download GLAD using cmake function "ExternalProject_Add" for this specific configuration ?

I found some CMake code on the internet but it does not specify these options:

# Download GLFW3 locally into the binary directory
if(DOWNLOAD_GLAD)
    message(STATUS "GLAD will be downloaded and built")
    # Download and build
    ExternalProject_Add(GLAD
        URL "https://github.com/Dav1dde/glad/archive/v0.1.29.zip"
        PREFIX ${GLAD_PREFIX}
        CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GLAD_PREFIX} -DGLAD_INSTALL=${GLAD_INSTALL}
        UPDATE_COMMAND "")
endif(DOWNLOAD_GLAD)

image

drsnuggles8 commented 2 years ago

In case ExternalProject_Add doesn't work, you could try cmake's fetchcontent. Make sure to put a include(FetchContent) somewhere before you insert the code below.

FetchContent_Declare(
    glad
    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)

You can set more options, too, here's an example.

petrasvestartas commented 2 years ago

Thank you, could you show how to download github repo and set these properties within external project command?

petrasvestartas commented 2 years ago

@drsnuggles8

If I write this, weirdly only github repository is cloned without any glad.c , glad.h present. Any idea why?

This is my code:

  ExternalProject_Add(glad
  GIT_REPOSITORY https://github.com/Dav1dde/glad.git
    GIT_TAG v0.1.36
  CMAKE_ARGS
    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
    -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
    -DGLAD_PROFILE="core"
    -DGLAD_GENERATOR="c"
  SOURCE_DIR   "${CMAKE_BINARY_DIR}/install/glad"
  CONFIGURE_COMMAND "" #do not configure
  BUILD_COMMAND "" #do not buld
  INSTALL_COMMAND "" #installer for now is empty
  )