Skip to content

Commit c79f56c

Browse files
committed
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.
1 parent dc2c19c commit c79f56c

3 files changed

Lines changed: 37 additions & 7 deletions

File tree

attachments/simple_engine/CMake/FindOpenAL.cmake

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,24 @@ if (NOT OpenAL_FOUND)
6868
set(ALSOFT_NO_CONFIG_UTIL ON CACHE BOOL "" FORCE)
6969
set(ALSOFT_INSTALL OFF CACHE BOOL "" FORCE)
7070

71-
FetchContent_MakeAvailable(openal-soft)
71+
# Set policy to suppress the deprecation warning
72+
if (POLICY CMP0169)
73+
cmake_policy(SET CMP0169 OLD)
74+
endif ()
75+
76+
FetchContent_GetProperties(openal-soft)
77+
if (NOT openal-soft_POPULATED)
78+
FetchContent_Populate(openal-soft)
79+
80+
# Update the minimum required CMake version to avoid errors on new CMake versions
81+
file(READ "${openal-soft_SOURCE_DIR}/CMakeLists.txt" OPENAL_CMAKE_CONTENT)
82+
string(REPLACE "cmake_minimum_required(VERSION 3.0.2)"
83+
"cmake_minimum_required(VERSION 3.5)"
84+
OPENAL_CMAKE_CONTENT "${OPENAL_CMAKE_CONTENT}")
85+
file(WRITE "${openal-soft_SOURCE_DIR}/CMakeLists.txt" "${OPENAL_CMAKE_CONTENT}")
86+
87+
add_subdirectory(${openal-soft_SOURCE_DIR} ${openal-soft_BINARY_DIR})
88+
endif ()
7289

7390
# openal-soft defines a target named 'OpenAL'
7491
if (TARGET OpenAL)
@@ -77,8 +94,7 @@ if (NOT OpenAL_FOUND)
7794
add_library(OpenAL::OpenAL ALIAS OpenAL)
7895
endif ()
7996
# Satisfy find_package_handle_standard_args
80-
FetchContent_GetProperties(openal-soft SOURCE_DIR openal_SOURCE_DIR)
81-
set(OPENAL_INCLUDE_DIR "${openal_SOURCE_DIR}/include")
97+
set(OPENAL_INCLUDE_DIR "${openal-soft_SOURCE_DIR}/include")
8298
set(OPENAL_LIBRARY OpenAL)
8399
endif ()
84100
endif ()

attachments/simple_engine/CMake/Findglfw3.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,29 @@ if (NOT glfw3_FOUND)
6767
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
6868
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
6969

70-
FetchContent_MakeAvailable(glfw)
70+
# Set policy to suppress the deprecation warning
71+
if (POLICY CMP0169)
72+
cmake_policy(SET CMP0169 OLD)
73+
endif ()
74+
75+
FetchContent_GetProperties(glfw)
76+
if (NOT glfw_POPULATED)
77+
FetchContent_Populate(glfw)
78+
79+
# Update the minimum required CMake version to avoid errors on new CMake versions
80+
file(READ "${glfw_SOURCE_DIR}/CMakeLists.txt" GLFW_CMAKE_CONTENT)
81+
string(REPLACE "cmake_minimum_required(VERSION 3.0)"
82+
"cmake_minimum_required(VERSION 3.5)"
83+
GLFW_CMAKE_CONTENT "${GLFW_CMAKE_CONTENT}")
84+
file(WRITE "${glfw_SOURCE_DIR}/CMakeLists.txt" "${GLFW_CMAKE_CONTENT}")
85+
86+
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
87+
endif ()
7188

7289
# GLFW's CMakeLists.txt defines a target named 'glfw'
7390
if (TARGET glfw)
7491
set(glfw3_FOUND TRUE)
7592
# Satisfy find_package_handle_standard_args
76-
FetchContent_GetProperties(glfw SOURCE_DIR glfw_SOURCE_DIR)
7793
set(GLFW3_INCLUDE_DIR "${glfw_SOURCE_DIR}/include")
7894
set(GLFW3_LIBRARY glfw)
7995
endif ()

attachments/simple_engine/CMake/Findnlohmann_json.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ if(NOT nlohmann_json_INCLUDE_DIR)
6060
if(NOT nlohmann_json_POPULATED)
6161
FetchContent_Populate(nlohmann_json)
6262

63-
if(ANDROID)
6463
# Update the minimum required CMake version before including the CMakeLists.txt
6564
file(READ "${nlohmann_json_SOURCE_DIR}/CMakeLists.txt" NLOHMANN_JSON_CMAKE_CONTENT)
6665
string(REPLACE "cmake_minimum_required(VERSION 3.1"
@@ -91,7 +90,6 @@ if(NOT nlohmann_json_INCLUDE_DIR)
9190
"cmake_minimum_required(VERSION 3.10"
9291
NLOHMANN_JSON_CMAKE_CONTENT "${NLOHMANN_JSON_CMAKE_CONTENT}")
9392
file(WRITE "${nlohmann_json_SOURCE_DIR}/CMakeLists.txt" "${NLOHMANN_JSON_CMAKE_CONTENT}")
94-
endif()
9593

9694
# Now add the subdirectory manually
9795
add_subdirectory(${nlohmann_json_SOURCE_DIR} ${nlohmann_json_BINARY_DIR})

0 commit comments

Comments
 (0)