Skip to content

Commit

Permalink
CMake: FetchContent EXCLUDE_FROM_ALL fixes
Browse files Browse the repository at this point in the history
On CMake v3.28+, `EXCLUDE_FROM_ALL` is supported natively as an argument
to `FetchContent_Declare`.

On CMake v3.30+, `FetchContent_Populate`, which we use to polyfill
`EXCLUDE_FROM_ALL` support for older versions of CMake, is deprecated
and triggers a noisy warning.

Avoids the warning by using the native `EXCLUDE_FROM_ALL` support on
CMake v3.28+.
  • Loading branch information
glebm committed Nov 11, 2024
1 parent 17ce17e commit 553d135
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 79 deletions.
6 changes: 3 additions & 3 deletions 3rdParty/Lua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

set(LUA_ENABLE_TESTING OFF)
set(LUA_BUILD_COMPILER OFF)
Expand All @@ -9,11 +9,11 @@ else()
endif()

include(FetchContent)
FetchContent_Declare(Lua
FetchContent_Declare_ExcludeFromAll(Lua
URL https://github.com/walterschell/Lua/archive/88246d621abf7b6fba9332f49229d507f020e450.tar.gz
URL_HASH MD5=03b76927cb5341ffc53bea12c37ddcca
)
FetchContent_MakeAvailableExcludeFromAll(Lua)
FetchContent_MakeAvailable_ExcludeFromAll(Lua)

if(ANDROID AND ("${ANDROID_ABI}" STREQUAL "armeabi-v7a" OR "${ANDROID_ABI}" STREQUAL "x86"))
target_compile_definitions(lua_internal INTERFACE -DLUA_USE_C89)
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/SDL2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ else()
endif()
set(SDL_TEST_ENABLED_BY_DEFAULT OFF)

include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)
include(FetchContent)
FetchContent_Declare(SDL2
FetchContent_Declare_ExcludeFromAll(SDL2
URL https://github.com/libsdl-org/SDL/releases/download/release-2.30.9/SDL2-2.30.9.tar.gz
URL_HASH SHA256=24b574f71c87a763f50704bbb630cbe38298d544a1f890f099a4696b1d6beba4
)
FetchContent_MakeAvailableExcludeFromAll(SDL2)
FetchContent_MakeAvailable_ExcludeFromAll(SDL2)
6 changes: 3 additions & 3 deletions 3rdParty/SDL_audiolib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

if(DEVILUTIONX_STATIC_SDL_AUDIOLIB)
set(BUILD_SHARED_LIBS OFF)
Expand Down Expand Up @@ -37,10 +37,10 @@ set(USE_DEC_ADLMIDI OFF)
set(USE_DEC_DRMP3 ON)

include(FetchContent)
FetchContent_Declare(SDL_audiolib
FetchContent_Declare_ExcludeFromAll(SDL_audiolib
URL https://github.com/realnc/SDL_audiolib/archive/cc1bb6af8d4cf5e200259072bde1edd1c8c5137e.tar.gz
URL_HASH MD5=0e8174264ac9c6b314c6b2d9a5f72efd)
FetchContent_MakeAvailableExcludeFromAll(SDL_audiolib)
FetchContent_MakeAvailable_ExcludeFromAll(SDL_audiolib)

add_library(SDL_audiolib::SDL_audiolib ALIAS SDL_audiolib)

Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/SDL_image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ else()
add_subdirectory(../libpng libpng)
endif()

include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)
include(FetchContent)

FetchContent_Declare(SDL_image
FetchContent_Declare_ExcludeFromAll(SDL_image
URL https://github.com/libsdl-org/SDL_image/archive/refs/tags/release-2.0.5.tar.gz
URL_HASH MD5=3446ed7ee3c700065dcb33426a9b0c6e
)
FetchContent_MakeAvailableExcludeFromAll(SDL_image)
FetchContent_MakeAvailable_ExcludeFromAll(SDL_image)

if(DEVILUTIONX_STATIC_SDL_IMAGE)
add_library(SDL_image STATIC ${CMAKE_CURRENT_LIST_DIR}/IMG.c ${sdl_image_SOURCE_DIR}/IMG_png.c)
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/asio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

include(FetchContent)
FetchContent_Declare(asio
FetchContent_Declare_ExcludeFromAll(asio
URL https://github.com/diasurgical/asio/archive/4bcf552fcea3e1ae555dde2ab33bc9fa6770da4d.tar.gz
URL_HASH MD5=7ffee993fc21b1115abf485958d03ac8
)
FetchContent_MakeAvailableExcludeFromAll(asio)
FetchContent_MakeAvailable_ExcludeFromAll(asio)

add_library(asio STATIC ${CMAKE_CURRENT_LIST_DIR}/asio_handle_exception.cpp)
target_compile_definitions(asio PUBLIC ASIO_NO_EXCEPTIONS)
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

FetchContent_Declare(
FetchContent_Declare_ExcludeFromAll(
benchmark
URL https://github.com/google/benchmark/archive/refs/tags/v1.8.5.tar.gz
URL_HASH MD5=708d91ce255e8af4c1d7dfec50dff178
Expand All @@ -13,4 +13,4 @@ set(BENCHMARK_ENABLE_EXCEPTIONS OFF)
set(BENCHMARK_ENABLE_WERROR OFF)
set(BENCHMARK_ENABLE_INSTALL OFF)

FetchContent_MakeAvailable(benchmark)
FetchContent_MakeAvailable_ExcludeFromAll(benchmark)
6 changes: 3 additions & 3 deletions 3rdParty/bzip2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

include(FetchContent)
FetchContent_Declare(bzip2
FetchContent_Declare_ExcludeFromAll(bzip2
URL https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
URL_HASH MD5=67e051268d0c475ea773822f7500d0e5
)
FetchContent_MakeAvailableExcludeFromAll(bzip2)
FetchContent_MakeAvailable_ExcludeFromAll(bzip2)

if(DEVILUTIONX_STATIC_BZIP2)
set(_lib_type STATIC)
Expand Down
8 changes: 4 additions & 4 deletions 3rdParty/discord/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)
include(FetchContent)

find_package(Patch REQUIRED)
Expand All @@ -7,18 +7,18 @@ set(Discord_SDK_URL "https://dl-game-sdk.discordapp.net/3.2.1/discord_game_sdk.z
set(Discord_SDK_HASH "73e5e1b3f8413a2c7184ef17476822f2")

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
FetchContent_Declare(discordsrc
FetchContent_Declare_ExcludeFromAll(discordsrc
URL ${Discord_SDK_URL}
URL_HASH MD5=${Discord_SDK_HASH}
)
else()
FetchContent_Declare(discordsrc
FetchContent_Declare_ExcludeFromAll(discordsrc
URL ${Discord_SDK_URL}
URL_HASH MD5=${Discord_SDK_HASH}
PATCH_COMMAND "${Patch_EXECUTABLE}" -p1 -N < "${CMAKE_CURRENT_LIST_DIR}/fixes.patch" || true
)
endif()
FetchContent_MakeAvailableExcludeFromAll(discordsrc)
FetchContent_MakeAvailable_ExcludeFromAll(discordsrc)

file(GLOB discord_SRCS ${discordsrc_SOURCE_DIR}/cpp/*.cpp)
add_library(discord STATIC ${discord_SRCS})
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/find_steam_game/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

include(FetchContent)
FetchContent_Declare(find_steam_game
FetchContent_Declare_ExcludeFromAll(find_steam_game
URL https://github.com/cxong/find_steam_game/archive/a2bd6273fc002214052c2ee3bd48d7c1e7d3f366.tar.gz
URL_HASH MD5=a6950ce5d9ced8a259752bc2dc7f5311
)
FetchContent_MakeAvailableExcludeFromAll(find_steam_game)
FetchContent_MakeAvailable_ExcludeFromAll(find_steam_game)

add_library(find_steam_game INTERFACE)
target_include_directories(find_steam_game INTERFACE ${find_steam_game_SOURCE_DIR})
6 changes: 3 additions & 3 deletions 3rdParty/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

FetchContent_Declare(
FetchContent_Declare_ExcludeFromAll(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
URL_HASH MD5=c8340a482851ef6a3fe618a082304cfc
Expand All @@ -11,6 +11,6 @@ set(INSTALL_GTEST OFF)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)
FetchContent_MakeAvailable_ExcludeFromAll(googletest)

add_library(GTest::gtest ALIAS gmock)
6 changes: 3 additions & 3 deletions 3rdParty/libfmt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

if(NOT WIN32 AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
# Enable POSIX extensions such as `readlink` and `ftruncate`.
Expand All @@ -15,11 +15,11 @@ else()
set(BUILD_SHARED_LIBS ON)
endif()
include(FetchContent)
FetchContent_Declare(libfmt
FetchContent_Declare_ExcludeFromAll(libfmt
URL https://github.com/fmtlib/fmt/archive/02537548f3a9efb5f3b83755acf50c8a16ba58c8.tar.gz
URL_HASH MD5=6901c6945cd311117d96baaa6d067380
)
FetchContent_MakeAvailableExcludeFromAll(libfmt)
FetchContent_MakeAvailable_ExcludeFromAll(libfmt)

# We do not use locale-specific features of libfmt and disabling them reduces the size.
target_compile_definitions(fmt PUBLIC FMT_USE_LOCALE=0)
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/libmpq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ if(NOT TARGET BZip2::BZip2)
find_package(BZip2 REQUIRED)
endif()

include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

include(FetchContent)
FetchContent_Declare(libmpq
FetchContent_Declare_ExcludeFromAll(libmpq
URL https://github.com/diasurgical/libmpq/archive/7c2924d4553513eba1a70bbdb558198dd8c2726a.tar.gz
URL_HASH MD5=315c88c02b45851cdfee8460322de044
)
FetchContent_MakeAvailableExcludeFromAll(libmpq)
FetchContent_MakeAvailable_ExcludeFromAll(libmpq)

add_library(libmpq STATIC
${libmpq_SOURCE_DIR}/libmpq/common.c
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/libpng/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

if(NOT DISABLE_LTO)
# Force CMake to raise an error if INTERPROCEDURAL_OPTIMIZATION
Expand All @@ -24,11 +24,11 @@ if(APPLE AND "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
endif()

include(FetchContent)
FetchContent_Declare(libpng
FetchContent_Declare_ExcludeFromAll(libpng
URL https://github.com/glennrp/libpng/archive/0a158f3506502dfa23edfc42790dfaed82efba17.tar.gz
URL_HASH MD5=6d705417242732e8e081bff752c98c18
)
FetchContent_MakeAvailableExcludeFromAll(libpng)
FetchContent_MakeAvailable_ExcludeFromAll(libpng)

target_include_directories(${PNG_LIBRARY} INTERFACE
$<BUILD_INTERFACE:${libpng_SOURCE_DIR}>
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/libsmackerdec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

include(FetchContent)
FetchContent_Declare(libsmackerdec
FetchContent_Declare_ExcludeFromAll(libsmackerdec
URL https://github.com/diasurgical/libsmackerdec/archive/91e732bb6953489077430572f43fc802bf2c75b2.tar.gz
URL_HASH MD5=c3b1ecbe702266e149b158178a03e2b3
)
FetchContent_MakeAvailableExcludeFromAll(libsmackerdec)
FetchContent_MakeAvailable_ExcludeFromAll(libsmackerdec)

add_library(libsmackerdec STATIC
${libsmackerdec_SOURCE_DIR}/src/BitReader.cpp
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/libsodium/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(NOT DEVILUTIONX_SYSTEM_LIBSODIUM)
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

set(SODIUM_MINIMAL ON)
set(SODIUM_ENABLE_BLOCKING_RANDOM OFF)
Expand All @@ -11,9 +11,9 @@ if(NOT DEVILUTIONX_SYSTEM_LIBSODIUM)
set(BUILD_SHARED_LIBS ON)
endif()
include(FetchContent)
FetchContent_Declare(libsodium
FetchContent_Declare_ExcludeFromAll(libsodium
GIT_REPOSITORY https://github.com/robinlinden/libsodium-cmake.git
GIT_TAG a8ac4509b22b84d6c2eb7d7448f08678e4a67da6
)
FetchContent_MakeAvailableExcludeFromAll(libsodium)
FetchContent_MakeAvailable_ExcludeFromAll(libsodium)
endif()
6 changes: 3 additions & 3 deletions 3rdParty/libzt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

set(BUILD_HOST_SELFTEST OFF)

include(FetchContent)
FetchContent_Declare(libzt
FetchContent_Declare_ExcludeFromAll(libzt
GIT_REPOSITORY https://github.com/diasurgical/libzt.git
GIT_TAG db7b642a4ce9f0f5e0ba7f293bd7ffa7897e4831)
FetchContent_MakeAvailableExcludeFromAll(libzt)
FetchContent_MakeAvailable_ExcludeFromAll(libzt)

if(NOT ANDROID)
set(libzt_LIB_NAME zt-static)
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/sol2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

set(SOL2_ENABLE_INSTALL OFF)

include(FetchContent)
FetchContent_Declare(sol2
FetchContent_Declare_ExcludeFromAll(sol2
URL https://github.com/ThePhD/sol2/archive/9c882a28fdb6f4ad79a53a4191b43ce48a661175.tar.gz
URL_HASH MD5=2637c3fcdcce3ff34b36437c1d3b99d1
)
FetchContent_MakeAvailableExcludeFromAll(sol2)
FetchContent_MakeAvailable_ExcludeFromAll(sol2)

target_include_directories(sol2 SYSTEM BEFORE INTERFACE ${CMAKE_CURRENT_LIST_DIR}/sol_config)
target_compile_definitions(sol2 INTERFACE SOL_NO_EXCEPTIONS=1)
6 changes: 3 additions & 3 deletions 3rdParty/tolk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

include(FetchContent)
FetchContent_Declare(Tolk
FetchContent_Declare_ExcludeFromAll(Tolk
URL https://github.com/sig-a11y/tolk/archive/89de98779e3b6365dc1688538d5de4ecba3fdbab.tar.gz
URL_HASH MD5=724f6022186573dd9c5c2c92ed9e21e6
)
FetchContent_MakeAvailableExcludeFromAll(Tolk)
FetchContent_MakeAvailable_ExcludeFromAll(Tolk)

target_include_directories(Tolk PUBLIC ${libTolk_SOURCE_DIR}/src)

Expand Down
8 changes: 4 additions & 4 deletions 3rdParty/unordered_dense/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)
include(FetchContent)

set(unordered_dense_URL "https://github.com/martinus/unordered_dense/archive/refs/tags/v4.4.0.tar.gz")
set(unordered_dense_HASH "f33c294a010540434b272754f937decf")

if(MINGW_CROSS)
find_package(Patch REQUIRED)
FetchContent_Declare(unordered_dense
FetchContent_Declare_ExcludeFromAll(unordered_dense
URL ${unordered_dense_URL}
URL_HASH MD5=${unordered_dense_HASH}
PATCH_COMMAND "${Patch_EXECUTABLE}" -p1 -N < "${CMAKE_CURRENT_LIST_DIR}/0001-Disable-PMR-support-for-mingw-std-threads-compat.patch" || true
)
else()
FetchContent_Declare(unordered_dense
FetchContent_Declare_ExcludeFromAll(unordered_dense
URL ${unordered_dense_URL}
URL_HASH MD5=${unordered_dense_HASH}
)
endif()
FetchContent_MakeAvailableExcludeFromAll(unordered_dense)
FetchContent_MakeAvailable_ExcludeFromAll(unordered_dense)
6 changes: 3 additions & 3 deletions 3rdParty/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(functions/FetchContent_ExcludeFromAll_backport)

set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)

include(FetchContent)
FetchContent_Declare(zlib
FetchContent_Declare_ExcludeFromAll(zlib
URL https://www.zlib.net/zlib-1.3.tar.gz
https://www.zlib.net/fossils/zlib-1.3.tar.gz
https://github.com/madler/zlib/releases/download/v1.3/zlib-1.3.tar.gz
URL_HASH MD5=60373b133d630f74f4a1f94c1185a53f
)
FetchContent_MakeAvailableExcludeFromAll(zlib)
FetchContent_MakeAvailable_ExcludeFromAll(zlib)

if(DEVILUTIONX_STATIC_ZLIB)
add_library(ZLIB::ZLIB ALIAS zlibstatic)
Expand Down
25 changes: 25 additions & 0 deletions CMake/functions/FetchContent_ExcludeFromAll_backport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if(CMAKE_VERSION VERSION_LESS "3.28.0")
macro(FetchContent_Declare_ExcludeFromAll)
FetchContent_Declare(${ARGV})
endmacro()
# Like `FetchContent_MakeAvailable` but passes EXCLUDE_FROM_ALL to `add_subdirectory`.
macro(FetchContent_MakeAvailable_ExcludeFromAll)
foreach(name ${ARGV})
string(TOLOWER ${name} nameLower)
FetchContent_GetProperties(${name})
if(NOT ${${nameLower}_POPULATED})
FetchContent_Populate(${name})
if(EXISTS ${${nameLower}_SOURCE_DIR}/CMakeLists.txt)
add_subdirectory(${${nameLower}_SOURCE_DIR} ${${nameLower}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
endforeach()
endmacro()
else()
macro(FetchContent_Declare_ExcludeFromAll)
FetchContent_Declare(${ARGV} EXCLUDE_FROM_ALL)
endmacro()
macro(FetchContent_MakeAvailable_ExcludeFromAll)
FetchContent_MakeAvailable(${ARGV})
endmacro()
endif()
Loading

0 comments on commit 553d135

Please sign in to comment.