From 16cc3e25d400e043a88297e375590420658bab19 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 11 Dec 2025 14:23:37 -0500 Subject: Utilities: Select bundled or external dependencies very early --- CMakeLists.txt | 157 +++++++++++++++---------------- Source/Modules/CMakeBuildUtilities.cmake | 4 - 2 files changed, 75 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cab0fcb..ef6e301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,81 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) endif() set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin) + + include(CMakeDependentOption) + + # Allow the user to enable/disable all system utility library options by + # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}. + set(UTILITIES BZIP2 CPPDAP CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD) + foreach(util IN LISTS UTILITIES) + if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util} + AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES) + set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}") + endif() + if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}) + if(CMAKE_USE_SYSTEM_LIBRARY_${util}) + set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON) + else() + set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF) + endif() + if(CMAKE_BOOTSTRAP) + unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE) + endif() + string(TOLOWER "${util}" lutil) + set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}" + CACHE BOOL "Use system-installed ${lutil}" FORCE) + elseif(util STREQUAL "CURL" AND APPLE) + # macOS provides a curl with backends configured by Apple. + set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON) + else() + set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF) + endif() + endforeach() + if(CMAKE_BOOTSTRAP) + unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE) + endif() + + # Optionally use system utility libraries. + option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}") + if(CMake_ENABLE_DEBUGGER) + option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}") + endif() + option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}") + option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}") + cmake_dependent_option(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib" + "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON) + cmake_dependent_option(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2" + "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) + cmake_dependent_option(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd" + "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) + cmake_dependent_option(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma" + "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) + cmake_dependent_option(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2" + "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON) + option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}") + cmake_dependent_option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" + "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON) + option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}") + option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}") + + # For now use system KWIML only if explicitly requested rather + # than activating via the general system libs options. + option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF) + mark_as_advanced(CMAKE_USE_SYSTEM_KWIML) + + # Mention to the user what system libraries are being used. + if(CMAKE_USE_SYSTEM_CURL) + # Avoid messaging about curl-only dependencies. + list(REMOVE_ITEM UTILITIES NGHTTP2) + endif() + foreach(util IN LISTS UTILITIES ITEMS KWIML) + if(CMAKE_USE_SYSTEM_${util}) + message(STATUS "Using system-installed ${util}") + endif() + endforeach() + + # Inform utility library header wrappers whether to use system versions. + configure_file(Utilities/cmThirdParty.h.in Utilities/cmThirdParty.h @ONLY) endif() if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL) @@ -155,88 +230,6 @@ else() endif() #----------------------------------------------------------------------- -# a macro to deal with system libraries, implemented as a macro -# simply to improve readability of the main script -#----------------------------------------------------------------------- -macro(CMAKE_HANDLE_SYSTEM_LIBRARIES) - include(CMakeDependentOption) - - # Allow the user to enable/disable all system utility library options by - # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}. - set(UTILITIES BZIP2 CPPDAP CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV NGHTTP2 ZLIB ZSTD) - foreach(util IN LISTS UTILITIES) - if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util} - AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES) - set(CMAKE_USE_SYSTEM_LIBRARY_${util} "${CMAKE_USE_SYSTEM_LIBRARIES}") - endif() - if(DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}) - if(CMAKE_USE_SYSTEM_LIBRARY_${util}) - set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON) - else() - set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF) - endif() - if(CMAKE_BOOTSTRAP) - unset(CMAKE_USE_SYSTEM_LIBRARY_${util} CACHE) - endif() - string(TOLOWER "${util}" lutil) - set(CMAKE_USE_SYSTEM_${util} "${CMAKE_USE_SYSTEM_LIBRARY_${util}}" - CACHE BOOL "Use system-installed ${lutil}" FORCE) - elseif(util STREQUAL "CURL" AND APPLE) - # macOS provides a curl with backends configured by Apple. - set(CMAKE_USE_SYSTEM_LIBRARY_${util} ON) - else() - set(CMAKE_USE_SYSTEM_LIBRARY_${util} OFF) - endif() - endforeach() - if(CMAKE_BOOTSTRAP) - unset(CMAKE_USE_SYSTEM_LIBRARIES CACHE) - endif() - - # Optionally use system utility libraries. - option(CMAKE_USE_SYSTEM_LIBARCHIVE "Use system-installed libarchive" "${CMAKE_USE_SYSTEM_LIBRARY_LIBARCHIVE}") - if(CMake_ENABLE_DEBUGGER) - option(CMAKE_USE_SYSTEM_CPPDAP "Use system-installed cppdap" "${CMAKE_USE_SYSTEM_LIBRARY_CPPDAP}") - endif() - option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}") - option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}") - cmake_dependent_option(CMAKE_USE_SYSTEM_ZLIB "Use system-installed zlib" - "${CMAKE_USE_SYSTEM_LIBRARY_ZLIB}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE;NOT CMAKE_USE_SYSTEM_CURL" ON) - cmake_dependent_option(CMAKE_USE_SYSTEM_BZIP2 "Use system-installed bzip2" - "${CMAKE_USE_SYSTEM_LIBRARY_BZIP2}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) - cmake_dependent_option(CMAKE_USE_SYSTEM_ZSTD "Use system-installed zstd" - "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) - cmake_dependent_option(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma" - "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) - cmake_dependent_option(CMAKE_USE_SYSTEM_NGHTTP2 "Use system-installed nghttp2" - "${CMAKE_USE_SYSTEM_LIBRARY_NGHTTP2}" "NOT CMAKE_USE_SYSTEM_CURL" ON) - option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}") - cmake_dependent_option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" - "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}" "NOT CMAKE_USE_SYSTEM_CPPDAP" ON) - option(CMAKE_USE_SYSTEM_LIBRHASH "Use system-installed librhash" "${CMAKE_USE_SYSTEM_LIBRARY_LIBRHASH}") - option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}") - - # For now use system KWIML only if explicitly requested rather - # than activating via the general system libs options. - option(CMAKE_USE_SYSTEM_KWIML "Use system-installed KWIML" OFF) - mark_as_advanced(CMAKE_USE_SYSTEM_KWIML) - - # Mention to the user what system libraries are being used. - if(CMAKE_USE_SYSTEM_CURL) - # Avoid messaging about curl-only dependencies. - list(REMOVE_ITEM UTILITIES NGHTTP2) - endif() - foreach(util IN LISTS UTILITIES ITEMS KWIML) - if(CMAKE_USE_SYSTEM_${util}) - message(STATUS "Using system-installed ${util}") - endif() - endforeach() - - # Inform utility library header wrappers whether to use system versions. - configure_file(Utilities/cmThirdParty.h.in Utilities/cmThirdParty.h @ONLY) - -endmacro() - -#----------------------------------------------------------------------- # a macro to determine the generator and ctest executable to use # for testing. Simply to improve readability of the main script. #----------------------------------------------------------------------- diff --git a/Source/Modules/CMakeBuildUtilities.cmake b/Source/Modules/CMakeBuildUtilities.cmake index 5c21fff..44cde84 100644 --- a/Source/Modules/CMakeBuildUtilities.cmake +++ b/Source/Modules/CMakeBuildUtilities.cmake @@ -78,10 +78,6 @@ endif() add_subdirectory(Utilities/std) CMAKE_SET_TARGET_FOLDER(cmstd "Utilities/std") -# check for the use of system libraries versus builtin ones -# (a macro defined in this file) -CMAKE_HANDLE_SYSTEM_LIBRARIES() - if(CMAKE_USE_SYSTEM_KWIML) find_package(KWIML 1.0) if(NOT KWIML_FOUND) -- cgit v0.12 From cea7f7fc328955de5632f856bfc0474749b50219 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 11 Dec 2025 14:33:49 -0500 Subject: Linux: Do not force 64-bit `time_t` on 32-bit archs with system libarchive Commit 1b9e8f833f (Linux: Compile with 64-bit time_t even on 32-bit architectures, 2025-06-26, v4.1.0-rc2~16^2) broke running with a system-provided libarchive that uses a 32-bit `time_t`. If CMake is configured to build with a system libarchive, assume the user has taken responsibility to match `time_t` sizes. Fixes: #27448 --- CompileFlags.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CompileFlags.cmake b/CompileFlags.cmake index 1d2ed5a..62e5233 100644 --- a/CompileFlags.cmake +++ b/CompileFlags.cmake @@ -68,8 +68,14 @@ endif() # Use 64-bit off_t on 32-bit Linux if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4) - # ensure 64bit offsets are used for filesystem accesses for 32bit compilation - add_compile_definitions(_FILE_OFFSET_BITS=64 _TIME_BITS=64) + # Use 64-bit off_t even in 32-bit builds. + add_compile_definitions(_FILE_OFFSET_BITS=64) + + # Use 64-bit time_t even in 32-bit builds. Skip this with + # system libarchive because its ABI uses the default time_t. + if (NOT CMAKE_USE_SYSTEM_LIBARCHIVE) + add_compile_definitions(_TIME_BITS=64) + endif() endif() # Workaround for TOC Overflow on ppc64 -- cgit v0.12