Author: brane Date: Mon May 26 06:59:13 2025 New Revision: 1925805 URL: http://svn.apache.org/viewvc?rev=1925805&view=rev Log: In the CMake build, simplify building on macOS with Homebrew or MacPorts.
* CMakeLists.txt: On macOS only, search for Homebrew xor MacPorts packages. (APR_ROOT, APRUtil_ROOT, OPENSSL_ROOT_DIR, ZLIB_ROOT): Declare these options. (BROTLI_ROOT): Rename from option BROTLI. (GSSAPI_ROOT): Rename from option GSSAPI. (USE_HOMEBREW, USE_MACPORTS): New, platform-specific options. * build/SerfMacOS.cmake: New file with helper functions to find MacPorts and Homebrew packages. * build/FindAPR.cmake, build/FindAPRUtil.cmake: Use the linker flags returned from the config script in the target interface attributes. MacPorts build fails without that, as some libraries are squirreled away in subdirectories of '.../lib'. Added: serf/trunk/build/SerfMacOS.cmake Modified: serf/trunk/CMakeLists.txt serf/trunk/build/FindAPR.cmake serf/trunk/build/FindAPRUtil.cmake Modified: serf/trunk/CMakeLists.txt URL: http://svn.apache.org/viewvc/serf/trunk/CMakeLists.txt?rev=1925805&r1=1925804&r2=1925805&view=diff ============================================================================== --- serf/trunk/CMakeLists.txt (original) +++ serf/trunk/CMakeLists.txt Mon May 26 06:59:13 2025 @@ -26,6 +26,8 @@ # APRUtil_ROOT - Path to APR-Util's install area # OPENSSL_ROOT_DIR - Path to OpenSSL's install area # ZLIB_ROOT - Path to zlib's install area +# BROTLI_ROOT - Path to Brotli's install area +# GSSAPI_ROOT - Path to GSSAPI's install area # =================================================================== cmake_minimum_required(VERSION 3.12) @@ -47,13 +49,19 @@ message(WARNING "has not been tested on many supported platforms.") +# Build dependencies +option(APR_ROOT:PATH "Path to APR's install area" "") +option(APRUtil_ROOT:PATH "Path to APR-Util's install area" "") +option(OPENSSL_ROOT_DIR:PATH "Path to OpenSSL's install area" "") +option(ZLIB_ROOT:PATH "Path to zlib's install area" "") +option(BROTLI_ROOT:PATH "Path to GSSAPI's install area" "") +option(GSSAPI_ROOT:PATH "Path to GSSAPI's install area" "") + # Build options option(DEBUG "Enable debugging info and strict compile warnings" OFF) option(SKIP_SHARED "Disable building shared Serf libraries" OFF) option(SKIP_STATIC "Disable building static Serf libraries" OFF) option(LIBDIR "Install directory for architecture-dependent libraries" "") -option(GSSAPI "Path to GSSAPI's install area" "") -option(BROTLI "Path to Brotli's install area" "") option(DISABLE_LOGGING "Disable the logging framework at compile time" OFF) option(SKIP_TESTS "Disable building the unit tests and utilities" OFF) option(ENABLE_SLOW_TESTS "Enable long-running unit tests" OFF) @@ -62,11 +70,17 @@ option(ENABLE_SLOW_TESTS "Enable long-ru option(APR_STATIC "Windows: Link with static APR/-Util libraries" OFF) option(EXPAT "Windows: optional path to Expat's install area for APR_STATIC" "") option(RELATIVE_RPATH "macOS: Use @rpath in installed shared library" OFF) +option(USE_HOMEBREW "macOS: Use dependencies from Homebrew" OFF) +option(USE_MACPORTS "macOS: Use dependencies from MacPorts" OFF) if(SKIP_SHARED AND SKIP_STATIC) message(FATAL_ERROR "You have disabled both shared and static library builds.") endif() +if(USE_HOMEBREW AND USE_MACPORTS) + message(FATAL_ERROR "You requested both Homebrew and McPorts dependencies.") +endif() + # Initialize the build type if it was not set on the command line. if(NOT CMAKE_BUILD_TYPE) if(DEBUG) @@ -79,6 +93,20 @@ endif() include(SerfPlatform) include(SerfWindowsToolkit) +# On the Mac: Use dependencies from Homebrew or MacPorts +if(USE_HOMEBREW OR USE_MACPORTS) + if(SERF_DARWIN) + include(SerfMacOS) + serf_macos_find_packages() + else() + if(USE_HOMEBREW) + message(WARNING "option USE_HOMEBREW is not implemented on this platform") + endif() + if(USE_MACPORTS) + message(WARNING "option USE_MACPORTS is not implemented on this platform") + endif() + endif(SERF_DARWIN) +endif(USE_HOMEBREW OR USE_MACPORTS) # Public headers list(APPEND HEADERS @@ -178,12 +206,12 @@ endif(SERF_WINDOWS) # Process build options for dependency search -if(GSSAPI) - message(WARNING "option GSSAPI is not implemented") +if(BROTLI_ROOT) + message(WARNING "option BROTLI_ROOT is not implemented") endif() -if(BROTLI) - message(WARNING "option BROTLI is not implemented") +if(GSSAPI_ROOT) + message(WARNING "option GSSAPI_ROOT is not implemented") endif() if(SERF_WINDOWS) Modified: serf/trunk/build/FindAPR.cmake URL: http://svn.apache.org/viewvc/serf/trunk/build/FindAPR.cmake?rev=1925805&r1=1925804&r2=1925805&view=diff ============================================================================== --- serf/trunk/build/FindAPR.cmake (original) +++ serf/trunk/build/FindAPR.cmake Mon May 26 06:59:13 2025 @@ -216,6 +216,7 @@ if(NOT _apru_include_only_utilities) _apr_invoke(APR_CFLAGS "(^| )-(g|O)[^ ]*" --cppflags --cflags) _apr_invoke(APR_INCLUDES "(^| )-I" --includes) + _apr_invoke(APR_LDFLAGS "" --ldflags) _apr_invoke(APR_LIBRARIES "" --link-ld) _apr_invoke(APR_EXTRALIBS "" --libs) _apr_invoke(APR_VERSION "" --version) @@ -260,7 +261,7 @@ if(NOT _apru_include_only_utilities) add_library(APR::APR UNKNOWN IMPORTED) set_target_properties(APR::APR PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${APR_INCLUDES}" - INTERFACE_LINK_LIBRARIES "${APR_EXTRALIBS};${_apr_extra}" + INTERFACE_LINK_LIBRARIES "${APR_LDFLAGS};${APR_EXTRALIBS};${_apr_extra}" IMPORTED_LOCATION "${_apr_library}") endif() # NOT Windows Modified: serf/trunk/build/FindAPRUtil.cmake URL: http://svn.apache.org/viewvc/serf/trunk/build/FindAPRUtil.cmake?rev=1925805&r1=1925804&r2=1925805&view=diff ============================================================================== --- serf/trunk/build/FindAPRUtil.cmake (original) +++ serf/trunk/build/FindAPRUtil.cmake Mon May 26 06:59:13 2025 @@ -189,7 +189,7 @@ else(APR_CONTAINS_APRUTIL) INTERFACE_INCLUDE_DIRECTORIES "${APRUTIL_INCLUDES}" IMPORTED_LOCATION "${_apu_library}") target_link_libraries(APR::APRUTIL - INTERFACE ${APRUTIL_EXTRALIBS};${_apu_extra}) + INTERFACE ${APRUTIL_LDFLAGS};${APRUTIL_EXTRALIBS};${_apu_extra}) endif() # NOT Windows endif(APRUTIL_FOUND) Added: serf/trunk/build/SerfMacOS.cmake URL: http://svn.apache.org/viewvc/serf/trunk/build/SerfMacOS.cmake?rev=1925805&view=auto ============================================================================== --- serf/trunk/build/SerfMacOS.cmake (added) +++ serf/trunk/build/SerfMacOS.cmake Mon May 26 06:59:13 2025 @@ -0,0 +1,150 @@ +# =================================================================== +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# =================================================================== + +cmake_minimum_required(VERSION 3.12) + +# macOS: Find packages installed in Homebrew or MacPorts. + +macro(serf_macos__check_package_manager_) + if(USE_HOMEBREW) + serf_macos__check_homebrew_() + endif() + if(USE_MACPORTS) + serf_macos__check_macports_() + endif() +endmacro(serf_macos__check_package_manager_) + +macro(serf_macos__find_package_ package variable docstring) + if(USE_HOMEBREW) + serf_macos__find_homebrew_package_("${package}" "${variable}" "${docstring}") + endif() + if(USE_MACPORTS) + serf_macos__find_macports_package_("${package}" "${variable}" "${docstring}") + endif() +endmacro(serf_macos__find_package_) + +function(serf_macos_find_packages) + serf_macos__check_package_manager_() + serf_macos__find_package_("apr" APR_ROOT "Path to APR's install area") + serf_macos__find_package_("apr-util" APRUtil_ROOT "Path to APR-Util's install area") + serf_macos__find_package_("openssl" OPENSSL_ROOT_DIR "Path to OpenSSL's install area") + if(USE_MACPORTS) + # NOTE: MacPorts uses its own version of zlib. Homebrew tends to use + # the system zlib, so we won't even look for the Homebrew version. + # The user can always override that on the command line. + serf_macos__find_package_("zlib" ZLIB_ROOT "Path to zlib's install area") + endif() + serf_macos__find_package_("brotli" BROTLI_ROOT "Path to GSSAPI's install area") + serf_macos__find_package_("gssapi" GSSAPI_ROOT "Path to GSSAPI's install area") +endfunction() + +# +# Homebrew +# +function(serf_macos__check_homebrew_) + if(NOT DEFINED SERF_MACOS__HAS_HOMEBREW_) + execute_process(COMMAND "brew" "--version" + ERROR_VARIABLE shutup + OUTPUT_VARIABLE version + RESULT_VARIABLE failed) + if(NOT failed) + execute_process(COMMAND "brew" "--prefix" + ERROR_VARIABLE shutup + OUTPUT_VARIABLE prefix + RESULT_VARIABLE failed) + endif() + if(failed) + set(SERF_MACOS__HAS_HOMEBREW_ FALSE PARENT_SCOPE) + message(WARNING "Homebrew was not found") + else() + string(STRIP "${version}" version) + string(STRIP "${prefix}" prefix) + message(STATUS "Found ${version} at ${prefix}") + set(SERF_MACOS__HAS_HOMEBREW_ TRUE PARENT_SCOPE) + endif() + endif() +endfunction(serf_macos__check_homebrew_) + +function(serf_macos__find_homebrew_package_ package variable docstring) + # Don't override user's provided values. + if("${${variable}}" STREQUAL "" AND ${SERF_MACOS__HAS_HOMEBREW_}) + execute_process(COMMAND "brew" "--prefix" "--installed" "${package}" + ERROR_VARIABLE shutup + OUTPUT_VARIABLE prefix + RESULT_VARIABLE failed) + if(failed) + message(STATUS "Homebrew: not found: ${package}") + else() + string(STRIP "${prefix}" prefix) + message(STATUS "Homebrew: found ${package} at ${prefix}") + set(${variable} "${prefix}" CACHE PATH "${docstring}" FORCE) + endif() + endif() +endfunction(serf_macos__find_homebrew_package_) + +# +# MacPorts +# +function(serf_macos__check_macports_) + if(NOT DEFINED SERF_MACOS__HAS_MACPORTS_) + execute_process(COMMAND "port" "version" + ERROR_VARIABLE shutup + OUTPUT_VARIABLE version + RESULT_VARIABLE failed) + if(NOT failed) + execute_process(COMMAND "which" "port" + ERROR_VARIABLE shutup + OUTPUT_VARIABLE prefix + RESULT_VARIABLE failed) + endif() + if(failed) + set(SERF_MACOS__HAS_MACPORTS_ FALSE PARENT_SCOPE) + message(WARNING "MacPorts was not found") + else() + string(REPLACE "Version:" "" version "${version}") + string(STRIP "${version}" version) + cmake_path(SET prefix_path NORMALIZE ${prefix}) + cmake_path(GET prefix_path PARENT_PATH prefix_path) + cmake_path(GET prefix_path PARENT_PATH prefix_path) + cmake_path(NATIVE_PATH prefix_path prefix) + message(STATUS "Found MacPorts ${version} at ${prefix}") + set(SERF_MACOS__HAS_MACPORTS_ TRUE PARENT_SCOPE) + set(SERF_MACOS__MACPORTS_ROOT_ "${prefix}" PARENT_SCOPE) + endif() + endif() +endfunction(serf_macos__check_macports_) + +function(serf_macos__find_macports_package_ package variable docstring) + # Don't override user's provided values. + if("${${variable}}" STREQUAL "" AND ${SERF_MACOS__HAS_MACPORTS_}) + ##!message(WARNING "MacPorts dependencies are not implemented (${package})") + execute_process(COMMAND "port" "echo" "active" "and" "name:^${package}$" + ERROR_VARIABLE shutup + OUTPUT_VARIABLE output + RESULT_VARIABLE failed) + if(failed OR "${output}" STREQUAL "") + message(STATUS "MacPorts: not found: ${package}") + else() + # TODO: Invoke "port contents ${package}" and calculate the common + # prefix of the installed files instead? + message(STATUS "MacPorts: found ${package} at ${SERF_MACOS__MACPORTS_ROOT_}") + set(${variable} "${SERF_MACOS__MACPORTS_ROOT_}" CACHE PATH "${docstring}" FORCE) + endif() + endif() +endfunction(serf_macos__find_macports_package_)