From 08c17aeaec2a14a1e455e374f4570b257cd9f18a Mon Sep 17 00:00:00 2001 From: sonoro1234 Date: Wed, 23 Oct 2024 12:26:55 +0200 Subject: [PATCH] cmake for glfw_vulkan downloads glfw instead of using fixed path --- examples/example_glfw_vulkan/CMakeLists.txt | 32 +++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/examples/example_glfw_vulkan/CMakeLists.txt b/examples/example_glfw_vulkan/CMakeLists.txt index 443a144eae65..94dfe369d9eb 100644 --- a/examples/example_glfw_vulkan/CMakeLists.txt +++ b/examples/example_glfw_vulkan/CMakeLists.txt @@ -15,14 +15,30 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVK_PROTOTYPES") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_PROTOTYPES") # GLFW -set(GLFW_DIR ../../../glfw) # Set this to point to an up-to-date GLFW repo -option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF) -option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF) -option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF) -option(GLFW_INSTALL "Generate installation target" OFF) -option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF) -add_subdirectory(${GLFW_DIR} binary_dir EXCLUDE_FROM_ALL) -include_directories(${GLFW_DIR}/include) +set(GLFW_VERSION 3.4) +include(FetchContent) + FetchContent_Declare( + glfw + URL https://github.com/glfw/glfw/archive/refs/tags/${GLFW_VERSION}.tar.gz) + #GIT_REPOSITORY https://github.com/glfw/glfw ) + +FetchContent_GetProperties(glfw) +if (NOT glfw_POPULATED) + set(FETCHCONTENT_QUIET NO) + FetchContent_Populate(glfw) + set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + if (NOT STATIC_BUILD) + set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) + endif() + add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() + +#if dynamic glfw then install +install(TARGETS glfw RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + LIBRARY DESTINATION ${CMAKE_CURRENT_BINARY_DIR} +) # Dear ImGui set(IMGUI_DIR ../../)