Author: brane Date: Sun Sep 23 19:58:08 2018 New Revision: 1841780 URL: http://svn.apache.org/viewvc?rev=1841780&view=rev Log: Use proper target dependencies for APR and APR-Util, and support linking with static APR on Windows.
* build/FindAPR.cmake: Define targets APR::APR and APR::APR_static. * build/FindAPRUtil.cmake: Define targets APR::APRUTIL and APR::APRUTIL_static. * CMakeLists.txt: - Use the new APR::* target dependencies instead of variables, except for generating the pkg-config file. - Support the APR_STATIC flag on Windows. 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=1841780&r1=1841779&r2=1841780&view=diff ============================================================================== --- serf/trunk/CMakeLists.txt (original) +++ serf/trunk/CMakeLists.txt Sun Sep 23 19:58:08 2018 @@ -164,6 +164,7 @@ if(SERF_WINDOWS) set(SERF_STANDARD_LIBRARIES "crypt32.lib" "mswsock.lib" + "rpcrt4.lib" "secur32.lib" "ws2_32.lib" ) @@ -179,14 +180,16 @@ if(BROTLI) message(WARNING "option BROTLI is not implemented") endif() -if(APR_STATIC) - message(WARNING "option APR_STATIC is not implemented") -endif() - -if(EXPAT) - set(PC_EXPAT_INCLUDE_DIRS "${EXPAT}/include") - set(PC_EXPAT_LIBRARY_DIRS "${EXPAT}/lib") -endif() +if(SERF_WINDOWS) + if(EXPAT) + set(PC_EXPAT_INCLUDE_DIRS "${EXPAT}/include") + set(PC_EXPAT_LIBRARY_DIRS "${EXPAT}/lib") + endif(EXPAT) +else(SERF_WINDOWS) + if(EXPAT) + message(WARNING "option EXPAT is not implemented on this platform") + endif(EXPAT) +endif(SERF_WINDOWS) # Find dependencies find_package(OpenSSL) @@ -198,23 +201,27 @@ if(SERF_WINDOWS) # Find ZLIB and OpenSSL runtime libraries etc. SerfWindowsProcessOpenSSL() SerfWindowsProcessZLIB() -endif() - +endif(SERF_WINDOWS) -set(SERF_INTERFACE_INCLUDES - ${APR_INCLUDES} - ${APRUTIL_INCLUDES} -) -list(REMOVE_DUPLICATES SERF_INTERFACE_INCLUDES) - -set(SERF_INTERFACE_LIBRARIES - ${APR_LIBRARIES} - ${APR_EXTRALIBS} - ${APRUTIL_LIBRARIES} - ${APRUTIL_EXTRALIBS} -) -list(REMOVE_DUPLICATES SERF_INTERFACE_LIBRARIES) +# Calculate the set of private and public targets +set(SERF_PRIVATE_TARGETS OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB) +if(APR_STATIC) + if(SERF_WINDOWS) + list(APPEND SERF_PUBLIC_TARGETS APR::APR_static) + if(NOT APR_CONTAINS_APRUTIL) + list(APPEND SERF_PUBLIC_TARGETS APR::APRUTIL_static) + endif() + add_definitions("/DAPR_DECLARE_STATIC" "/DAPU_DECLARE_STATIC") + else(SERF_WINDOWS) + message(WARNING "option APR_STATIC is not implemented on this platform") + endif(SERF_WINDOWS) +else(APR_STATIC) + list(APPEND SERF_PUBLIC_TARGETS APR::APR) + if(NOT APR_CONTAINS_APRUTIL) + list(APPEND SERF_PUBLIC_TARGETS APR::APRUTIL) + endif() +endif(APR_STATIC) # Feature tests include(SerfChecks) @@ -293,13 +300,11 @@ endif(NOT MSVC) if(NOT SKIP_SHARED) add_library(serf_shared SHARED ${SOURCES} ${SHARED_SOURCES}) target_compile_options(serf_shared PUBLIC ${APR_CFLAGS}) - target_include_directories(serf_shared SYSTEM BEFORE - PUBLIC ${SERF_INTERFACE_INCLUDES}) target_include_directories(serf_shared PUBLIC ${SERF_SOURCE_DIR}) target_link_libraries(serf_shared - PRIVATE OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB + PRIVATE ${SERF_PRIVATE_TARGETS} ${SERF_STANDARD_LIBRARIES} - PUBLIC ${SERF_INTERFACE_LIBRARIES}) + PUBLIC ${SERF_PUBLIC_TARGETS}) set_target_properties(serf_shared PROPERTIES VERSION ${SERF_VERSION} @@ -314,12 +319,10 @@ endif() if(NOT SKIP_STATIC) add_library(serf_static STATIC ${SOURCES}) target_compile_options(serf_static PUBLIC ${APR_CFLAGS}) - target_include_directories(serf_static SYSTEM BEFORE - PUBLIC ${SERF_INTERFACE_INCLUDES}) target_include_directories(serf_static PUBLIC ${SERF_SOURCE_DIR}) target_link_libraries(serf_static - OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB - ${SERF_INTERFACE_LIBRARIES} + ${SERF_PRIVATE_TARGETS} + ${SERF_PUBLIC_TARGETS} ${SERF_STANDARD_LIBRARIES}) list(APPEND SERF_TARGETS "serf_static") endif() @@ -350,9 +353,16 @@ if(NOT SERF_WINDOWS) set(INCLUDE_SUBDIR ${SERF_INCLUDE_SUBDIR}) set(VERSION ${SERF_VERSION}) set(MAJOR ${SERF_MAJOR_VERSION}) + set(SERF_INTERFACE_LIBS + ${APR_LIBRARIES} + ${APR_EXTRALIBS} + ${APRUTIL_LIBRARIES} + ${APRUTIL_EXTRALIBS} + ) + list(REMOVE_DUPLICATES SERF_INTERFACE_LIBS) unset(LIBS) - foreach(DEPLIB ${SERF_DEPENDENCY_LIBRARIES} ${SERF_INTERFACE_LIBRARIES}) - set(LIBS "${LIBS} ${DEPLIB}") + foreach(DEPLIB ${SERF_INTERFACE_LIBS}) + string(APPEND LIBS " ${DEPLIB}") endforeach() configure_file("build/serf.pc.in" "serf.pc" @ONLY) endfunction() @@ -362,6 +372,7 @@ if(NOT SERF_WINDOWS) DESTINATION "share/pkgconfig") endif() + if(NOT SKIP_TESTS) if(SKIP_STATIC) message(WARNING "The tests depend on the Serf static library") Modified: serf/trunk/build/FindAPR.cmake URL: http://svn.apache.org/viewvc/serf/trunk/build/FindAPR.cmake?rev=1841780&r1=1841779&r2=1841780&view=diff ============================================================================== --- serf/trunk/build/FindAPR.cmake (original) +++ serf/trunk/build/FindAPR.cmake Sun Sep 23 19:58:08 2018 @@ -19,24 +19,51 @@ cmake_minimum_required(VERSION 3.0) -# This module uses: -# APR_ROOT, the (optional) root of the APR install area. -# This module defines: -# APR_FOUND, set to TRUE if found, FALSE otherwise. -# APR_VERSION, the version of APR that was found. -# APR_CONTAINS_APRUTIL, set to TRUE if the APR major version is 2 or greater. -# APR_INCLUDES, where to find apr.h, etc. -# APR_LIBRARIES, linker switches to use with ld to link against APR -# APR_EXTRALIBS, additional libraries to link against. -# APR_CFLAGS, the flags to use to compile. -# APR_STATIC_LIBS, on Windows: list of static libraries. -# APR_RUNTIME_LIBS, on Windows: list of DLLs that will be loaded at runtime. +#.rst: +# FindAPR +# -------- +# +# Find the native Apache Portable Runtime includes and library. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``APR::APR``, if +# APR has been found. On Windows, it may define the :prop_tgt:`IMPORTED` +# target ``APR::APR_static`` if the static libraries are found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# APR_FOUND - True if APR was found. +# APR_VERSION - The version of APR found (x.y.z) +# APR_CONTAINS_APRUTIL - True if the APR major version is 2 or greater. +# APR_INCLUDES - Where to find apr.h, etc. +# APR_LIBRARIES - Linker switches to use with ld to link against APR +# +# :: +# +# APR_EXTRALIBS - Additional libraries to link against +# APR_CFLAGS - The flags to use to compile. +# APR_STATIC_LIBS - On Windows: list of APR static libraries +# APR_RUNTIME_LIBS - On Windows: list of APR runtime DLLs +# +# Hints +# ^^^^^ +# +# A user may set ``APR_ROOT`` to an APR installation root to tell this +# module where to look. This variable must be defined on Windows. # ------------------------------------------------------------------- # Common utility functions for FindAPR.cmaks and FindAPRtil.cmake # ------------------------------------------------------------------- +# Run the APR/Util configuration program function(_apru_config _program _varname _regexp) execute_process(COMMAND ${_program} ${ARGN} OUTPUT_VARIABLE _apru_output @@ -62,6 +89,7 @@ function(_apru_config _program _varname endif() endfunction(_apru_config) +# Parse the APR/Util version number from the header function(_apru_version _version_varname _major_varname _minor_varname _header _prefix) file(STRINGS ${_header} _apru_major REGEX "^ *# *define +${_prefix}_MAJOR_VERSION +[0-9]+.*$") @@ -77,12 +105,64 @@ function(_apru_version _version_varname set(${_minor_varname} ${_apru_minor} PARENT_SCOPE) endfunction(_apru_version) +# Windows: Find the DLL (runtime) library function(_apru_find_dll _varname _dllname) set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll") find_library(${_varname} NAMES ${_dllname} PATHS ${ARGN} NO_DEFAULT_PATH PATH_SUFFIXES "bin" "lib") endfunction(_apru_find_dll) +# Extract the main and extra static libraries +function(_apru_extras _static_var _extra_var) + # The first element in the list of static libraries will be the the main + # APR/Util static library, anything else will be additional interface + # libraries. + set(_extra "${ARGN}") + list(GET _extra 0 _static) + list(REMOVE_AT _extra 0) + set(${_static_var} ${_static} PARENT_SCOPE) + set(${_extra_var} ${_extra} PARENT_SCOPE) +endfunction(_apru_extras) + +# From the list of link libraries, extract the imported location +function(_apru_location _location_var _extralibs_var) + foreach(_part ${ARGN}) + string(SUBSTRING "${_part}" 0 2 _flag) + if(_flag STREQUAL "-L") + if(NOT _dir AND NOT _lib) + string(SUBSTRING "${_part}" 2 -1 _rest) + set(_dir "${_rest}") + else() + list(APPEND _extra "${_part}") + endif() + elseif(_flag STREQUAL "-l") + if(NOT _lib) + string(SUBSTRING "${_part}" 2 -1 _rest) + set(_lib "${_rest}") + else() + list(APPEND _extra " ${_part}") + endif() + else() + if(NOT _lib) + set(_lib "${_rest}") + else() + list(APPEND _extra " ${_part}") + endif() + endif() + endforeach() + + if(NOT _lib) + message(FATAL_ERROR "did not find any libraries in '${ARGN}'") + endif() + + if(NOT _dir) + find_library(${_location_var} NAMES "${_lib}") + else() + find_library(${_location_var} NAMES "${_lib}" PATHS "${_dir}" NO_DEFAULT_PATH) + endif() + set(${_extralibs_var} ${_extra} PARENT_SCOPE) +endfunction(_apru_location) + # ------------------------------------------------------------------- if(NOT _apru_include_only_utilities) @@ -91,7 +171,9 @@ if(NOT _apru_include_only_utilities) if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - if(NOT DEFINED APR_ROOT) + if(DEFINED APR_ROOT) + get_filename_component(APR_ROOT "${APR_ROOT}" REALPATH) + else() message(FATAL_ERROR "APR_ROOT must be defined on Windows") endif() @@ -114,9 +196,10 @@ if(NOT _apru_include_only_utilities) PATHS ${APR_ROOT} NO_DEFAULT_PATH PATH_SUFFIXES "lib") _apru_find_dll(APR_RUNTIME_LIBS "lib${_apr_name}.dll" ${APR_ROOT}) - else() #NOT Windows + else() # NOT Windows if(DEFINED APR_ROOT) + get_filename_component(APR_ROOT "${APR_ROOT}" REALPATH) find_program(APR_CONFIG_EXECUTABLE NAMES apr-2-config apr-1-config PATHS "${APR_ROOT}/bin" NO_DEFAULT_PATH) else() @@ -137,7 +220,7 @@ if(NOT _apru_include_only_utilities) endif() # NOT Windows - if(_apr_major GREATER 2) + if(${_apr_major} GREATER 1) set(APR_CONTAINS_APRUTIL TRUE) else() set(APR_CONTAINS_APRUTIL FALSE) @@ -148,4 +231,36 @@ if(NOT _apru_include_only_utilities) REQUIRED_VARS APR_LIBRARIES APR_INCLUDES VERSION_VAR APR_VERSION) + if(APR_FOUND) + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + + if(APR_LIBRARIES AND APR_RUNTIME_LIBS) + add_library(APR::APR SHARED IMPORTED) + set_target_properties(APR::APR PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APR_INCLUDES}" + IMPORTED_LOCATION "${APR_RUNTIME_LIBS}" + IMPORTED_IMPLIB "${APR_LIBRARIES}") + endif() + + if(APR_STATIC_LIBS) + _apru_extras(_apr_static _apr_extra ${APR_STATIC_LIBS}) + add_library(APR::APR_static STATIC IMPORTED) + set_target_properties(APR::APR_static PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APR_INCLUDES}" + IMPORTED_INTERFACE_LINK_LIBRARIES "${_apr_extra}" + IMPORTED_LOCATION "${_apr_static}") + endif() + + else() # NOT Windows + + _apru_location(_apr_library _apr_extra "${APR_LIBRARIES}") + add_library(APR::APR UNKNOWN IMPORTED) + set_target_properties(APR::APR PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APR_INCLUDES}" + INTERFACE_LINK_LIBRARIES "${APR_EXTRALIBS};${_apr_extra}" + IMPORTED_LOCATION "${_apr_library}") + + endif() # NOT Windows + endif(APR_FOUND) + endif(NOT _apru_include_only_utilities) Modified: serf/trunk/build/FindAPRUtil.cmake URL: http://svn.apache.org/viewvc/serf/trunk/build/FindAPRUtil.cmake?rev=1841780&r1=1841779&r2=1841780&view=diff ============================================================================== --- serf/trunk/build/FindAPRUtil.cmake (original) +++ serf/trunk/build/FindAPRUtil.cmake Sun Sep 23 19:58:08 2018 @@ -19,27 +19,53 @@ cmake_minimum_required(VERSION 3.0) -# This module uses: -# APRUtil_ROOT, the (optional) root of the APR-Util install area. -# This module defines: -# APRUTIL_FOUND, set to TRUE if found, FALSE otherwise. -# APRUTIL_VERSION, the version of APR that was found. -# APRUTIL_INCLUDES, where to find apr.h, etc. -# APRUTIL_LIBRARIES, linker switches to use with ld to link against APR -# APRUTIL_EXTRALIBS, additional libraries to link against. -# APRUTIL_STATIC_LIBS, on Windows: list of static libraries. -# APRUTIL_RUNTIME_LIBS, on Windows: list of DLLs that will be loaded at runtime. +#.rst: +# FindAPRUtil +# -------- +# +# Find the native Apache Portable Runtime Utilities includes and library. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``APR::APRUTIL``, if +# APR-Util has been found. On Windows, it may define the :prop_tgt:`IMPORTED` +# target ``APR::APRUTIL_static`` if the static libraries are found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# APRUTIL_FOUND - True if APR-Util was found +# APRUTIL_VERSION - The version of APR-Util found (x.y.z) +# APRUTIL_INCLUDES - Where to find apr.h, etc. +# APRUTIL_LIBRARIES - Linker switches to use with ld to link against APR +# +# :: +# +# APRUTIL_EXTRALIBS - Additional libraries to link against +# APRUTIL_STATIC_LIBS - On Windows: list of APR-Util static libraries +# APRUTIL_RUNTIME_LIBS - On Windows: list of APR-Util runtime DLLs +# +# Hints +# ^^^^^ +# +# A user may set ``APRUtil_ROOT`` to an APR-Util installation root to tell +# this module where to look. This variable must be defined on Windows. -if(NOT APR_FOUND) # FIXME: should become: if(NOT TARGET APR::APR) +if(NOT APR_FOUND) find_package(APR REQUIRED) endif() +set(APRUTIL_FOUND FALSE) + if(APR_CONTAINS_APRUTIL) - set(APRUTIL_FOUND TRUE) set(APRUTIL_VERSION ${APR_VERSION}) - include(FindPackageHandleStandardArgs) find_package_handle_standard_args(APRUTIL REQUIRED_VARS APRUTIL_VERSION @@ -51,11 +77,11 @@ else(APR_CONTAINS_APRUTIL) include(${CMAKE_CURRENT_LIST_DIR}/FindAPR.cmake) unset(_apru_include_only_utilities) - set(APRUTIL_FOUND FALSE) - if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") - if(NOT DEFINED APRUtil_ROOT) + if(DEFINED APRUtil_ROOT) + get_filename_component(APRUtil_ROOT "${APRUtil_ROOT}" REALPATH) + else() message(FATAL_ERROR "APRUtil_ROOT must be defined on Windows") endif() @@ -102,6 +128,7 @@ else(APR_CONTAINS_APRUTIL) else() # NOT Windows if(DEFINED APRUtil_ROOT) + get_filename_component(APRUtil_ROOT "${APRUtil_ROOT}" REALPATH) find_program(APRUTIL_CONFIG_EXECUTABLE apu-1-config PATHS "${APRUtil_ROOT}/bin" NO_DEFAULT_PATH) else() @@ -126,4 +153,43 @@ else(APR_CONTAINS_APRUTIL) REQUIRED_VARS APRUTIL_LIBRARIES APRUTIL_INCLUDES VERSION_VAR APRUTIL_VERSION) + if(APRUTIL_FOUND) + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + + if(APRUTIL_LIBRARIES AND APRUTIL_RUNTIME_LIBS) + add_library(APR::APRUTIL SHARED IMPORTED) + set_target_properties(APR::APRUTIL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APRUTIL_INCLUDES}" + IMPORTED_LOCATION "${APRUTIL_RUNTIME_LIBS}" + IMPORTED_IMPLIB "${APRUTIL_LIBRARIES}") + if(TARGET APR::APR) + set_target_properties(APR::APRUTIL PROPERTIES + INTERFACE_LINK_LIBRARIES APR::APR) + endif() + endif() + + if(APRUTIL_STATIC_LIBS) + _apru_extras(_apu_static _apu_extra ${APRUTIL_STATIC_LIBS}) + if(TARGET APR::APR_static) + list(APPEND _apu_extra APR::APR_static) + endif() + add_library(APR::APRUTIL_static STATIC IMPORTED) + set_target_properties(APR::APRUTIL_static PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APRUTIL_INCLUDES}" + INTERFACE_LINK_LIBRARIES "${_apu_extra}" + IMPORTED_LOCATION "${_apu_static}") + endif() + + else() # NOT Windows + + _apru_location(_apu_library _apu_extra "${APRUTIL_LIBRARIES}") + add_library(APR::APRUTIL UNKNOWN IMPORTED) + set_target_properties(APR::APRUTIL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${APRUTIL_INCLUDES}" + INTERFACE_LINK_LIBRARIES "${APRUTIL_EXTRALIBS};${_apu_extra}" + IMPORTED_LOCATION "${_apu_library}") + + endif() # NOT Windows + endif(APRUTIL_FOUND) + endif(APR_CONTAINS_APRUTIL)