From 5970b10ad88b4d55c7f54f9c161a7761efe4f332 Mon Sep 17 00:00:00 2001 From: swinston Date: Thu, 4 Jun 2026 02:30:12 -0700 Subject: [PATCH 1/4] fix #387 --- attachments/simple_engine/CMake/Findtinygltf.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/attachments/simple_engine/CMake/Findtinygltf.cmake b/attachments/simple_engine/CMake/Findtinygltf.cmake index b2412350c..d5d0c9c5a 100644 --- a/attachments/simple_engine/CMake/Findtinygltf.cmake +++ b/attachments/simple_engine/CMake/Findtinygltf.cmake @@ -74,10 +74,11 @@ if(NOT tinygltf_INCLUDE_DIR) TINYGLTF_CMAKE_CONTENT "${TINYGLTF_CMAKE_CONTENT}") file(WRITE "${tinygltf_SOURCE_DIR}/CMakeLists.txt" "${TINYGLTF_CMAKE_CONTENT}") - # Create a symbolic link to make nlohmann/json.hpp available + # Copy json.hpp to nlohmann/json.hpp to make it available + # Using COPY instead of CREATE_LINK SYMBOLIC to avoid permission issues on Windows if(EXISTS "${tinygltf_SOURCE_DIR}/json.hpp") file(MAKE_DIRECTORY "${tinygltf_SOURCE_DIR}/nlohmann") - file(CREATE_LINK "${tinygltf_SOURCE_DIR}/json.hpp" "${tinygltf_SOURCE_DIR}/nlohmann/json.hpp" SYMBOLIC) + file(COPY "${tinygltf_SOURCE_DIR}/json.hpp" DESTINATION "${tinygltf_SOURCE_DIR}/nlohmann") endif() # Set tinygltf to header-only mode From 10452fecb4242230e1b6cda12ff699bfc530d501 Mon Sep 17 00:00:00 2001 From: swinston Date: Thu, 4 Jun 2026 02:54:31 -0700 Subject: [PATCH 2/4] Refactor FindKTX.cmake to fix FetchContent fallback and improve cross-platform compatibility --- attachments/simple_engine/CMake/FindKTX.cmake | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/attachments/simple_engine/CMake/FindKTX.cmake b/attachments/simple_engine/CMake/FindKTX.cmake index c8c1c22c0..e9d77d695 100644 --- a/attachments/simple_engine/CMake/FindKTX.cmake +++ b/attachments/simple_engine/CMake/FindKTX.cmake @@ -51,16 +51,10 @@ else() ${CMAKE_SOURCE_DIR}/external/ktx/lib ) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(KTX - REQUIRED_VARS KTX_INCLUDE_DIR KTX_LIBRARY - FAIL_MESSAGE "" # Suppress the error message to allow our fallback - ) - - # Debug output if KTX is not found (only on non-Linux platforms) - if(NOT KTX_FOUND) - message(STATUS "KTX include directory search paths: ${PC_KTX_INCLUDEDIR}, /usr/include, /usr/local/include, $ENV{KTX_DIR}/include, $ENV{VULKAN_SDK}/include, ${CMAKE_SOURCE_DIR}/external/ktx/include") - message(STATUS "KTX library search paths: ${PC_KTX_LIBDIR}, /usr/lib, /usr/lib64, /usr/local/lib, /usr/local/lib64, $ENV{KTX_DIR}/lib, $ENV{VULKAN_SDK}/lib, ${CMAKE_SOURCE_DIR}/external/ktx/lib") + if (KTX_INCLUDE_DIR AND KTX_LIBRARY) + set(KTX_FOUND TRUE) + else () + set(KTX_FOUND FALSE) endif() endif() @@ -102,5 +96,16 @@ else() add_library(KTX::ktx ALIAS ktx) endif() + # Set variables to indicate that KTX was found and to satisfy find_package_handle_standard_args set(KTX_FOUND TRUE) + FetchContent_GetProperties(ktx SOURCE_DIR ktx_SOURCE_DIR) + set(KTX_INCLUDE_DIR "${ktx_SOURCE_DIR}/include") + set(KTX_LIBRARY ktx) + set(KTX_INCLUDE_DIRS ${KTX_INCLUDE_DIR}) + set(KTX_LIBRARIES ${KTX_LIBRARY}) endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(KTX + REQUIRED_VARS KTX_INCLUDE_DIR KTX_LIBRARY +) From dc2c19c89e1002d57fe6fd14f71726a0bfe62357 Mon Sep 17 00:00:00 2001 From: swinston Date: Thu, 4 Jun 2026 03:19:54 -0700 Subject: [PATCH 3/4] Add CMake Find modules for OpenAL and GLFW3 with FetchContent fallback Create FindOpenAL.cmake and Findglfw3.cmake modules that support multiple detection methods: CONFIG mode first, then standard find_path/find_library, and finally FetchContent as fallback. Both modules create standardized imported targets (OpenAL::OpenAL and glfw) and set appropriate include directories and library variables. --- .../simple_engine/CMake/FindOpenAL.cmake | 89 +++++++++++++++++++ .../simple_engine/CMake/Findglfw3.cmake | 85 ++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 attachments/simple_engine/CMake/FindOpenAL.cmake create mode 100644 attachments/simple_engine/CMake/Findglfw3.cmake diff --git a/attachments/simple_engine/CMake/FindOpenAL.cmake b/attachments/simple_engine/CMake/FindOpenAL.cmake new file mode 100644 index 000000000..8e81f406f --- /dev/null +++ b/attachments/simple_engine/CMake/FindOpenAL.cmake @@ -0,0 +1,89 @@ +# FindOpenAL.cmake +# +# Finds the OpenAL library +# +# This will define the following variables: +# +# OpenAL_FOUND +# OPENAL_INCLUDE_DIR +# OPENAL_LIBRARY +# +# and the following imported targets: +# +# OpenAL::OpenAL +# + +# Try to find OpenAL using CONFIG mode first +find_package(OpenAL CONFIG QUIET) + +if (OpenAL_FOUND) + if (NOT TARGET OpenAL::OpenAL) + if (TARGET OpenAL) + add_library(OpenAL::OpenAL ALIAS OpenAL) + endif () + endif () + + # Set variables for find_package_handle_standard_args + if (NOT OPENAL_INCLUDE_DIR) + get_target_property(OPENAL_INCLUDE_DIR OpenAL::OpenAL INTERFACE_INCLUDE_DIRECTORIES) + endif () + if (NOT OPENAL_LIBRARY) + set(OPENAL_LIBRARY OpenAL) + endif () +endif () + +if (NOT OpenAL_FOUND) + # Try to find using standard find_path/find_library + find_path(OPENAL_INCLUDE_DIR NAMES AL/al.h OpenAL/al.h) + find_library(OPENAL_LIBRARY NAMES OpenAL al openal OpenAL32) + + if (OPENAL_INCLUDE_DIR AND OPENAL_LIBRARY) + set(OpenAL_FOUND TRUE) + if (NOT TARGET OpenAL::OpenAL) + add_library(OpenAL::OpenAL UNKNOWN IMPORTED) + set_target_properties(OpenAL::OpenAL PROPERTIES + IMPORTED_LOCATION "${OPENAL_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}" + ) + endif () + endif () +endif () + +if (NOT OpenAL_FOUND) + # If not found, use FetchContent to download and build openal-soft + include(FetchContent) + + message(STATUS "OpenAL not found, fetching openal-soft from GitHub...") + + FetchContent_Declare( + openal-soft + GIT_REPOSITORY https://github.com/kcat/openal-soft.git + GIT_TAG 1.23.1 + ) + + # Set options to minimize OpenAL build + set(ALSOFT_EXAMPLES OFF CACHE BOOL "" FORCE) + set(ALSOFT_TESTS OFF CACHE BOOL "" FORCE) + set(ALSOFT_UTILS OFF CACHE BOOL "" FORCE) + set(ALSOFT_NO_CONFIG_UTIL ON CACHE BOOL "" FORCE) + set(ALSOFT_INSTALL OFF CACHE BOOL "" FORCE) + + FetchContent_MakeAvailable(openal-soft) + + # openal-soft defines a target named 'OpenAL' + if (TARGET OpenAL) + set(OpenAL_FOUND TRUE) + if (NOT TARGET OpenAL::OpenAL) + add_library(OpenAL::OpenAL ALIAS OpenAL) + endif () + # Satisfy find_package_handle_standard_args + FetchContent_GetProperties(openal-soft SOURCE_DIR openal_SOURCE_DIR) + set(OPENAL_INCLUDE_DIR "${openal_SOURCE_DIR}/include") + set(OPENAL_LIBRARY OpenAL) + endif () +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpenAL + REQUIRED_VARS OPENAL_INCLUDE_DIR OPENAL_LIBRARY +) diff --git a/attachments/simple_engine/CMake/Findglfw3.cmake b/attachments/simple_engine/CMake/Findglfw3.cmake new file mode 100644 index 000000000..1dd8129dc --- /dev/null +++ b/attachments/simple_engine/CMake/Findglfw3.cmake @@ -0,0 +1,85 @@ +# Findglfw3.cmake +# +# Finds the GLFW3 library +# +# This will define the following variables: +# +# glfw3_FOUND +# GLFW3_INCLUDE_DIR +# GLFW3_LIBRARY +# +# and the following imported targets: +# +# glfw +# + +# Try to find GLFW3 using CONFIG mode first (common for vcpkg) +find_package(glfw3 CONFIG QUIET) + +if (glfw3_FOUND) + if (NOT TARGET glfw) + if (TARGET glfw3::glfw) + add_library(glfw ALIAS glfw3::glfw) + endif () + endif () + + # Set variables for find_package_handle_standard_args + if (NOT GLFW3_INCLUDE_DIR) + get_target_property(GLFW3_INCLUDE_DIR glfw INTERFACE_INCLUDE_DIRECTORIES) + endif () + if (NOT GLFW3_LIBRARY) + set(GLFW3_LIBRARY glfw) + endif () +endif () + +if (NOT glfw3_FOUND) + # Try to find using standard find_path/find_library + find_path(GLFW3_INCLUDE_DIR NAMES GLFW/glfw3.h) + find_library(GLFW3_LIBRARY NAMES glfw glfw3) + + if (GLFW3_INCLUDE_DIR AND GLFW3_LIBRARY) + set(glfw3_FOUND TRUE) + if (NOT TARGET glfw) + add_library(glfw UNKNOWN IMPORTED) + set_target_properties(glfw PROPERTIES + IMPORTED_LOCATION "${GLFW3_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GLFW3_INCLUDE_DIR}" + ) + endif () + endif () +endif () + +if (NOT glfw3_FOUND) + # If not found, use FetchContent to download and build + include(FetchContent) + + message(STATUS "glfw3 not found, fetching from GitHub...") + + FetchContent_Declare( + glfw + GIT_REPOSITORY https://github.com/glfw/glfw.git + GIT_TAG 3.4 + ) + + # Set options to minimize GLFW build + set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) + set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) + + FetchContent_MakeAvailable(glfw) + + # GLFW's CMakeLists.txt defines a target named 'glfw' + if (TARGET glfw) + set(glfw3_FOUND TRUE) + # Satisfy find_package_handle_standard_args + FetchContent_GetProperties(glfw SOURCE_DIR glfw_SOURCE_DIR) + set(GLFW3_INCLUDE_DIR "${glfw_SOURCE_DIR}/include") + set(GLFW3_LIBRARY glfw) + endif () +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(glfw3 + REQUIRED_VARS GLFW3_INCLUDE_DIR GLFW3_LIBRARY +) From c79f56c034780ab6c3fbb2d1a8fa99cea31625a0 Mon Sep 17 00:00:00 2001 From: swinston Date: Thu, 4 Jun 2026 03:32:18 -0700 Subject: [PATCH 4/4] Fix CMake minimum version handling in Find modules for compatibility with newer CMake versions Remove Android-specific conditional from nlohmann_json finder and apply CMake version patching universally. Replace FetchContent_MakeAvailable with manual population approach in OpenAL and GLFW3 finders to patch their minimum required CMake versions before adding subdirectories. Set CMP0169 policy to OLD to suppress deprecation warnings. Fix openal-soft source directory variable reference. --- .../simple_engine/CMake/FindOpenAL.cmake | 22 ++++++++++++++++--- .../simple_engine/CMake/Findglfw3.cmake | 20 +++++++++++++++-- .../CMake/Findnlohmann_json.cmake | 2 -- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/attachments/simple_engine/CMake/FindOpenAL.cmake b/attachments/simple_engine/CMake/FindOpenAL.cmake index 8e81f406f..edebc64d6 100644 --- a/attachments/simple_engine/CMake/FindOpenAL.cmake +++ b/attachments/simple_engine/CMake/FindOpenAL.cmake @@ -68,7 +68,24 @@ if (NOT OpenAL_FOUND) set(ALSOFT_NO_CONFIG_UTIL ON CACHE BOOL "" FORCE) set(ALSOFT_INSTALL OFF CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(openal-soft) + # Set policy to suppress the deprecation warning + if (POLICY CMP0169) + cmake_policy(SET CMP0169 OLD) + endif () + + FetchContent_GetProperties(openal-soft) + if (NOT openal-soft_POPULATED) + FetchContent_Populate(openal-soft) + + # Update the minimum required CMake version to avoid errors on new CMake versions + file(READ "${openal-soft_SOURCE_DIR}/CMakeLists.txt" OPENAL_CMAKE_CONTENT) + string(REPLACE "cmake_minimum_required(VERSION 3.0.2)" + "cmake_minimum_required(VERSION 3.5)" + OPENAL_CMAKE_CONTENT "${OPENAL_CMAKE_CONTENT}") + file(WRITE "${openal-soft_SOURCE_DIR}/CMakeLists.txt" "${OPENAL_CMAKE_CONTENT}") + + add_subdirectory(${openal-soft_SOURCE_DIR} ${openal-soft_BINARY_DIR}) + endif () # openal-soft defines a target named 'OpenAL' if (TARGET OpenAL) @@ -77,8 +94,7 @@ if (NOT OpenAL_FOUND) add_library(OpenAL::OpenAL ALIAS OpenAL) endif () # Satisfy find_package_handle_standard_args - FetchContent_GetProperties(openal-soft SOURCE_DIR openal_SOURCE_DIR) - set(OPENAL_INCLUDE_DIR "${openal_SOURCE_DIR}/include") + set(OPENAL_INCLUDE_DIR "${openal-soft_SOURCE_DIR}/include") set(OPENAL_LIBRARY OpenAL) endif () endif () diff --git a/attachments/simple_engine/CMake/Findglfw3.cmake b/attachments/simple_engine/CMake/Findglfw3.cmake index 1dd8129dc..1c9c4bec5 100644 --- a/attachments/simple_engine/CMake/Findglfw3.cmake +++ b/attachments/simple_engine/CMake/Findglfw3.cmake @@ -67,13 +67,29 @@ if (NOT glfw3_FOUND) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(glfw) + # Set policy to suppress the deprecation warning + if (POLICY CMP0169) + cmake_policy(SET CMP0169 OLD) + endif () + + FetchContent_GetProperties(glfw) + if (NOT glfw_POPULATED) + FetchContent_Populate(glfw) + + # Update the minimum required CMake version to avoid errors on new CMake versions + file(READ "${glfw_SOURCE_DIR}/CMakeLists.txt" GLFW_CMAKE_CONTENT) + string(REPLACE "cmake_minimum_required(VERSION 3.0)" + "cmake_minimum_required(VERSION 3.5)" + GLFW_CMAKE_CONTENT "${GLFW_CMAKE_CONTENT}") + file(WRITE "${glfw_SOURCE_DIR}/CMakeLists.txt" "${GLFW_CMAKE_CONTENT}") + + add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR}) + endif () # GLFW's CMakeLists.txt defines a target named 'glfw' if (TARGET glfw) set(glfw3_FOUND TRUE) # Satisfy find_package_handle_standard_args - FetchContent_GetProperties(glfw SOURCE_DIR glfw_SOURCE_DIR) set(GLFW3_INCLUDE_DIR "${glfw_SOURCE_DIR}/include") set(GLFW3_LIBRARY glfw) endif () diff --git a/attachments/simple_engine/CMake/Findnlohmann_json.cmake b/attachments/simple_engine/CMake/Findnlohmann_json.cmake index 61dc66a61..ae7baed35 100644 --- a/attachments/simple_engine/CMake/Findnlohmann_json.cmake +++ b/attachments/simple_engine/CMake/Findnlohmann_json.cmake @@ -60,7 +60,6 @@ if(NOT nlohmann_json_INCLUDE_DIR) if(NOT nlohmann_json_POPULATED) FetchContent_Populate(nlohmann_json) - if(ANDROID) # Update the minimum required CMake version before including the CMakeLists.txt file(READ "${nlohmann_json_SOURCE_DIR}/CMakeLists.txt" NLOHMANN_JSON_CMAKE_CONTENT) string(REPLACE "cmake_minimum_required(VERSION 3.1" @@ -91,7 +90,6 @@ if(NOT nlohmann_json_INCLUDE_DIR) "cmake_minimum_required(VERSION 3.10" NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}") file(WRITE "${nlohmann_json_SOURCE_DIR}/CMakeLists.txt" "${NLOHMANN_JSON_CMAKE_CONTENT}") - endif() # Now add the subdirectory manually add_subdirectory(${nlohmann_json_SOURCE_DIR} ${nlohmann_json_BINARY_DIR})