Skip to content

Instantly share code, notes, and snippets.

@Triavanicus Triavanicus/GLFW.cmake
Last active Mar 4, 2019

Embed
What would you like to do?
Downloads GLFW from git, and adds a glfw target that one can include in their project
include(ExternalProject)
set(GLFW_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
if(NOT EXISTS ${GLFW_DIR})
file(MAKE_DIRECTORY ${GLFW_DIR})
endif()
if(NOT EXISTS ${GLFW_DIR}/include)
file(MAKE_DIRECTORY ${GLFW_DIR}/include)
endif()
set(GLFW_VERSION master)
set(GLFW_BUILD_TYPE Release)
set(GLFW_CMAKE_ARGS
-DGLFW_BUILD_DOCS=OFF
-DGLFW_BUILD_TESTS=OFF
-DGLFW_BUILD_EXAMPLES=OFF
-DCMAKE_INSTALL_PREFIX=${GLFW_DIR}
)
set(GLFW_LIBRARY_NAME libglfw3.a)
set(GLFW_GIT_REPOSITORY "https://github.com/glfw/glfw.git")
ExternalProject_Add(glfw_git
GIT_REPOSITORY ${GLFW_GIT_REPOSITORY}
GIT_TAG ${GLFW_VERSION}
CMAKE_ARGS
${GLFW_CMAKE_ARGS}
-DCMAKE_BUILD_TYPE=${GLFW_BUILD_TYPE}
TEST_COMMAND ""
PATCH_COMMAND ""
UPDATE_COMMAND ""
PREFIX glfw
SOURCE_DIR glfw/source
INSTALL_DIR ${GLFW_DIR})
add_library(glfw STATIC IMPORTED GLOBAL)
set_target_properties(glfw PROPERTIES
IMPORTED_LOCATION ${GLFW_DIR}/lib/${GLFW_LIBRARY_NAME})
target_include_directories(glfw INTERFACE ${GLFW_DIR}/include)
add_dependencies(glfw glfw_git)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.