From ca18c5b1b5004ffa88b6b3b85cd038d1217c09c6 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Mar 2024 22:57:02 +0100 Subject: zlib sources removed from this tree This, for whatever reason, breaks std::fs exception handling. All remaining external projects will be moved to use this approach soon. This is to prepare it for more new libraries which would otherwise make the tree grow even further. --- cmake/modules/ApplyPatch.cmake | 11 +++++++++++ cmake/modules/MakeAvailable.cmake | 16 ++++++++++++++++ cmake/modules/apply_patch.cmake.in | 5 +++++ 3 files changed, 32 insertions(+) create mode 100644 cmake/modules/ApplyPatch.cmake create mode 100644 cmake/modules/MakeAvailable.cmake create mode 100644 cmake/modules/apply_patch.cmake.in (limited to 'cmake') diff --git a/cmake/modules/ApplyPatch.cmake b/cmake/modules/ApplyPatch.cmake new file mode 100644 index 0000000..894d32e --- /dev/null +++ b/cmake/modules/ApplyPatch.cmake @@ -0,0 +1,11 @@ +# Creates a wrapper for patch(1) utility that discards exit status in case the patch gets reapplied. This happens +# because CMake applies patch step frequently with ExternalProject and FetchContent. Moreover, GNU patch does not follow +# strict POSIX description of -N option making CMake think patching failed. +# +# For compatibility use with cmake(1) itself: +# +# COMMAND ${CMAKE_COMMAND} -D PATCH_FILE=something.patch -P ${PATCH_SCRIPT} + +find_program(PATCH_COMMAND patch DOC "POSIX-compliant patch utility") +set(PATCH_SCRIPT ${CMAKE_BINARY_DIR}/apply_patch.cmake CACHE FILEPATH "CMake script wrapper for patch command") +configure_file(${CMAKE_CURRENT_LIST_DIR}/apply_patch.cmake.in ${PATCH_SCRIPT} @ONLY) diff --git a/cmake/modules/MakeAvailable.cmake b/cmake/modules/MakeAvailable.cmake new file mode 100644 index 0000000..16e976c --- /dev/null +++ b/cmake/modules/MakeAvailable.cmake @@ -0,0 +1,16 @@ +# Populates all declared FetchContent projects. Use this once after everything is set up: +# +# FetchContent_Declare(zlib ...) +# FetchContent_Declare(libpng ...) +# make_available(zlib libpng) + +function(make_available) + foreach(DEPNAME IN LISTS ARGN) + string(TOLOWER "${DEPNAME}" DEPNAME) + FetchContent_GetProperties(${DEPNAME}) + if(NOT ${DEPNAME}_POPULATED) + FetchContent_Populate(${DEPNAME}) + add_subdirectory(${${DEPNAME}_SOURCE_DIR} ${${DEPNAME}_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() + endforeach() +endfunction() diff --git a/cmake/modules/apply_patch.cmake.in b/cmake/modules/apply_patch.cmake.in new file mode 100644 index 0000000..61ce075 --- /dev/null +++ b/cmake/modules/apply_patch.cmake.in @@ -0,0 +1,5 @@ +# See ApplyPatch.cmake +if(NOT PATCH_FILE) + message(FATAL_ERROR "no PATCH_FILE passed to the script") +endif() +execute_process(COMMAND @PATCH_COMMAND@ -Np1 INPUT_FILE ${PATCH_FILE}) -- cgit v1.1