Skip to content

Commit

Permalink
Merge 'cmake-native-type' branch: Use BUILD_SHARED_LIBS in CMake to s…
Browse files Browse the repository at this point in the history
…pecify the

build type of the libraries instead of APR_BUILD_SHARED and APR_BUILD_STATIC
options.

git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920436 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Ivan Zhakov committed Sep 3, 2024
2 parents d384777 + 0004bfa commit 95677c8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
generator: [ "Visual Studio 17 2022" ]
arch: [ "Win32", "x64" ]
toolset: [ "v143", "v142" ]
test-static: [ "ON", "OFF" ]
build-shared: [ "ON", "OFF" ]
fail-fast: false

name: "MSVC ${{ matrix.toolset }} ${{ matrix.arch }} [${{ matrix.build-type }}] test-static=${{ matrix.test-static }} on ${{ matrix.os }}"
name: "MSVC ${{ matrix.toolset }} ${{ matrix.arch }} [${{ matrix.build-type }}] build-shared=${{ matrix.build-shared }} on ${{ matrix.os }}"
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DAPR_BUILD_TESTAPR=ON -DTEST_STATIC_LIBS=${{ matrix.test-static }} -G "${{ matrix.generator }}" -A ${{ matrix.arch }} -T ${{ matrix.toolset }}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DAPR_BUILD_TESTAPR=ON -DBUILD_SHARED_LIBS=${{ matrix.build-shared }} -G "${{ matrix.generator }}" -A ${{ matrix.arch }} -T ${{ matrix.toolset }}

- name: Build
# Build your program with the given configuration
Expand Down
94 changes: 33 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

PROJECT(APR C)

INCLUDE(CMakeDependentOption)

# Enable support for MSVC runtime library selection by abstraction
# if supported by CMake.
IF(POLICY CMP0091)
Expand All @@ -47,7 +49,6 @@ ELSE()
OPTION(APU_HAVE_ODBC "Build ODBC DBD driver" OFF)
ENDIF()

SET(apr_name apr-2)
SET(apr_libname libapr-2)

IF(NOT APU_USE_EXPAT AND NOT APU_USE_LIBXML2 AND NOT APU_USE_XMLLITE)
Expand All @@ -71,33 +72,23 @@ OPTION(APU_HAVE_ICONV "Xlate support" OFF)
OPTION(APR_HAVE_IPV6 "IPv6 support" ON)
OPTION(INSTALL_PDB "Install .pdb files (if generated)" ON)
OPTION(APR_BUILD_TESTAPR "Build the test suite" ON)
OPTION(APR_BUILD_SHARED "Build shared libraries" ON)
OPTION(APR_BUILD_STATIC "Build static libraries" ON)
OPTION(APR_MODULAR_DSO "Use DSO build of modular components" ON)
OPTION(BUILD_SHARED_LIBS "Build using shared libraries" ON)
CMAKE_DEPENDENT_OPTION(APR_MODULAR_DSO "Use DSO build of modular components" ON "BUILD_SHARED_LIBS" OFF)
OPTION(APR_POOL_DEBUG "Turn on pools debugging" OFF)
OPTION(TEST_STATIC_LIBS "Test programs use APR static libraries instead of shared libraries?" OFF)

SET(APR_INSTALL_BIN_DIR "bin" CACHE STRING "Install subdirectory for binary files")
SET(APR_INSTALL_LIB_DIR "lib" CACHE STRING "Install subdirectory for library files")
SET(APR_INSTALL_INCLUDE_DIR "include/apr-2" CACHE STRING "Install subdirectory for include files")

IF(NOT APR_BUILD_SHARED AND NOT APR_BUILD_STATIC)
MESSAGE(FATAL_ERROR "Both APR_BUILD_SHARED and APR_BUILD_STATIC have been disabled")
ENDIF()

IF(NOT APR_BUILD_STATIC AND TEST_STATIC_LIBS)
MESSAGE(FATAL_ERROR "APR_BUILD_STATIC has been disabled, but TEST_STATIC_LIBS is enabled")
ENDIF()

IF(NOT APU_USE_EXPAT AND NOT APU_USE_LIBXML2 AND NOT APU_USE_XMLLITE)
MESSAGE(FATAL_ERROR "Either Expat or LibXml2 or XmlLite must be selected")
ENDIF()
IF(APU_USE_EXPAT AND APU_USE_LIBXML2)
MESSAGE(FATAL_ERROR "Only one of Expat and LibXml2 can be selected")
ENDIF()

IF(APR_MODULAR_DSO AND NOT APR_BUILD_SHARED)
MESSAGE(FATAL_ERROR "APR_MODULAR_DSO requires APR_BUILD_SHARED.")
IF(APR_MODULAR_DSO AND NOT BUILD_SHARED_LIBS)
MESSAGE(FATAL_ERROR "APR_MODULAR_DSO requires shared libraries build option enabled.")
ENDIF()

IF(APU_HAVE_CRYPTO)
Expand All @@ -120,12 +111,17 @@ IF(APR_POOL_DEBUG)
ADD_COMPILE_DEFINITIONS(APR_POOL_DEBUG=1)
ENDIF()

IF(APR_MODULAR_DSO)
ADD_COMPILE_DEFINITIONS(APR_HAVE_MODULAR_DSO=1)
ELSE()
ADD_COMPILE_DEFINITIONS(APR_HAVE_MODULAR_DSO=0)
ENDIF()

# create 1-or-0 representation of feature tests for apr.h

SET(apu_use_libxml2_10 0)
SET(apu_use_expat_10 0)
SET(apu_use_xmllite_10 0)
SET(apr_have_modular_dso_10 0)

IF(APU_USE_EXPAT)
SET(apu_use_expat_10 1)
Expand All @@ -135,10 +131,6 @@ ELSE(APU_USE_XMLLITE)
SET(apu_use_xmllite_10 1)
ENDIF()

IF(APR_MODULAR_DSO)
SET(apr_have_modular_dso_10 1)
ENDIF()

# Read current version.
FILE(STRINGS include/apr_version.h VERSION_STRINGS REGEX "#define (APR_MAJOR_VERSION|APR_MINOR_VERSION|APR_PATCH_VERSION)")

Expand Down Expand Up @@ -537,54 +529,48 @@ IF(NOT APR_MODULAR_DSO AND APU_HAVE_SQLITE3)
LIST(APPEND APR_EXTRA_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIRS}")
ENDIF()

# libapr-2 is shared, apr-2 is static
IF (APR_BUILD_SHARED)
IF (BUILD_SHARED_LIBS)
ADD_LIBRARY(${apr_libname} SHARED ${APR_SOURCES} ${APR_EXTRA_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc)
LIST(APPEND install_targets ${apr_libname})
LIST(APPEND install_bin_pdb $<TARGET_PDB_FILE:${apr_libname}>)
TARGET_LINK_LIBRARIES(${apr_libname}
PRIVATE ${XMLLIB_LIBRARIES} ${XLATE_LIBRARIES} ${APR_SYSTEM_LIBS} ${APR_EXTRA_LIBRARIES})
TARGET_COMPILE_DEFINITIONS(${apr_libname}
PRIVATE "APR_DECLARE_EXPORT;APR_HAVE_MODULAR_DSO=${apr_have_modular_dso_10}"
PRIVATE "APR_DECLARE_EXPORT"
INTERFACE "APR_DECLARE_IMPORT")
TARGET_INCLUDE_DIRECTORIES(${apr_libname}
PRIVATE ${APR_INCLUDE_DIRECTORIES} ${XMLLIB_INCLUDE_DIR} ${XLATE_INCLUDE_DIR} ${APR_EXTRA_INCLUDE_DIRECTORIES}
INTERFACE $<INSTALL_INTERFACE:${APR_INSTALL_INCLUDE_DIR}> ${APR_INCLUDE_DIRECTORIES}
)
ADD_DEPENDENCIES(${apr_libname} test_char_header)
ENDIF()

IF (APR_BUILD_STATIC)
ADD_LIBRARY(${apr_name} STATIC ${APR_SOURCES} ${APR_EXTRA_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED})
LIST(APPEND install_targets ${apr_name})
ELSE()
ADD_LIBRARY(${apr_libname} STATIC ${APR_SOURCES} ${APR_EXTRA_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED})
LIST(APPEND install_targets ${apr_libname})
# no .pdb file generated for static libraries
TARGET_LINK_LIBRARIES(${apr_name}
TARGET_LINK_LIBRARIES(${apr_libname}
PRIVATE ${XMLLIB_LIBRARIES} ${XLATE_LIBRARIES} ${APR_SYSTEM_LIBS} ${APR_EXTRA_LIBRARIES})
TARGET_COMPILE_DEFINITIONS(${apr_name}
PRIVATE "APR_DECLARE_STATIC;APR_HAVE_MODULAR_DSO=${apr_have_modular_dso_10}"
TARGET_COMPILE_DEFINITIONS(${apr_libname}
PRIVATE "APR_DECLARE_STATIC"
INTERFACE "APR_DECLARE_STATIC")
TARGET_INCLUDE_DIRECTORIES(${apr_name}
TARGET_INCLUDE_DIRECTORIES(${apr_libname}
PRIVATE ${APR_INCLUDE_DIRECTORIES} ${XMLLIB_INCLUDE_DIR} ${XLATE_INCLUDE_DIR} ${APR_EXTRA_INCLUDE_DIRECTORIES}
INTERFACE $<INSTALL_INTERFACE:${APR_INSTALL_INCLUDE_DIR}> ${APR_INCLUDE_DIRECTORIES}
)
ADD_DEPENDENCIES(${apr_name} test_char_header)
ADD_DEPENDENCIES(${apr_libname} test_char_header)
ENDIF()

# libaprapp-2 and aprapp-2 are static
IF (APR_BUILD_SHARED)
IF (BUILD_SHARED_LIBS)
ADD_LIBRARY(libaprapp-2 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
LIST(APPEND install_targets libaprapp-2)
SET_TARGET_PROPERTIES(libaprapp-2 PROPERTIES COMPILE_DEFINITIONS APR_APP)
TARGET_INCLUDE_DIRECTORIES(libaprapp-2
PRIVATE ${APR_INCLUDE_DIRECTORIES}
)
ENDIF()

IF (APR_BUILD_STATIC)
ADD_LIBRARY(aprapp-2 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
LIST(APPEND install_targets aprapp-2)
SET_TARGET_PROPERTIES(aprapp-2 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP")
TARGET_INCLUDE_DIRECTORIES(aprapp-2
ELSE()
ADD_LIBRARY(libaprapp-2 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
LIST(APPEND install_targets libaprapp-2)
SET_TARGET_PROPERTIES(libaprapp-2 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP")
TARGET_INCLUDE_DIRECTORIES(libaprapp-2
PRIVATE ${APR_INCLUDE_DIRECTORIES}
)
ENDIF()
Expand Down Expand Up @@ -646,16 +632,8 @@ IF(APR_BUILD_TESTAPR)
${PROJECT_SOURCE_DIR}/test/data/mmap_large_datafile.txt
${PROJECT_BINARY_DIR}/data/mmap_large_datafile.txt)

IF(TEST_STATIC_LIBS)
SET(whichapr ${apr_name})
SET(whichaprapp aprapp-2)
ELSE()
SET(whichapr ${apr_libname})
SET(whichaprapp libaprapp-2)
ENDIF()

ADD_EXECUTABLE(testapp test/testapp.c)
TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp})
TARGET_LINK_LIBRARIES(testapp ${apr_libname} libaprapp-2)
SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup)
ADD_TEST(NAME testapp COMMAND testapp)

Expand All @@ -672,15 +650,15 @@ IF(APR_BUILD_TESTAPR)
ENDFOREACH()

ADD_EXECUTABLE(testall ${APR_TEST_SOURCES})
TARGET_LINK_LIBRARIES(testall ${whichapr} ws2_32.lib)
TARGET_LINK_LIBRARIES(testall ${apr_libname} ws2_32.lib)
SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_DEFINITIONS "BINPATH=$<TARGET_FILE_DIR:testall>")

FOREACH(test ${APR_TEST_SUITES})
ADD_TEST(NAME ${test} COMMAND testall -v ${test})
ENDFOREACH()

ADD_LIBRARY(mod_test MODULE test/mod_test.c)
TARGET_LINK_LIBRARIES(mod_test ${whichapr})
TARGET_LINK_LIBRARIES(mod_test ${apr_libname})
SET_PROPERTY(TARGET mod_test APPEND PROPERTY LINK_FLAGS /export:print_hello)
# nasty work-around for difficulties adding more than one additional flag
# (they get joined in a bad way behind the scenes)
Expand Down Expand Up @@ -713,7 +691,7 @@ IF(APR_BUILD_TESTAPR)
FOREACH(sourcefile ${single_source_programs})
STRING(REGEX REPLACE ".*/([^\\]+)\\.c" "\\1" proggie ${sourcefile})
ADD_EXECUTABLE(${proggie} ${sourcefile})
TARGET_LINK_LIBRARIES(${proggie} ${whichapr})
TARGET_LINK_LIBRARIES(${proggie} ${apr_libname})
SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_DEFINITIONS "BINPATH=$<TARGET_FILE_DIR:${proggie}>")

ADD_DEPENDENCIES(testall ${proggie})
Expand Down Expand Up @@ -818,12 +796,6 @@ MESSAGE(STATUS " Have Iconv ...................... : ${APU_HAVE_ICONV}")
MESSAGE(STATUS " Library files for XML ........... : ${XMLLIB_LIBRARIES}")
MESSAGE(STATUS " DSO build of modular components.. : ${APR_MODULAR_DSO}")
MESSAGE(STATUS " Turn on pools debugging ..........: ${APR_POOL_DEBUG}")
MESSAGE(STATUS " Build shared libs ............... : ${APR_BUILD_SHARED}")
MESSAGE(STATUS " Build static libs ............... : ${APR_BUILD_STATIC}")
MESSAGE(STATUS " Build shared libraries .......... : ${BUILD_SHARED_LIBS}")
MESSAGE(STATUS " Build test suite ................ : ${APR_BUILD_TESTAPR}")
IF(TEST_STATIC_LIBS)
MESSAGE(STATUS " (testing static libraries)")
ELSE()
MESSAGE(STATUS " (testing dynamic libraries)")
ENDIF()
MESSAGE(STATUS " Install private .h for httpd .... : ${APR_INSTALL_PRIVATE_H}")
6 changes: 0 additions & 6 deletions build/vcpkg/apr-2/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ if (VCPKG_TARGET_IS_WINDOWS)
dbd-sqlite3 FEATURE_DBD_SQLITE3
)

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" APR_BUILD_STATIC)
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" APR_BUILD_SHARED)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DAPR_BUILD_STATIC=${APR_BUILD_STATIC}
-DAPR_BUILD_SHARED=${APR_BUILD_SHARED}
-DAPR_MODULAR_DSO=${APR_BUILD_SHARED}
-DAPR_BUILD_TESTAPR=OFF
-DINSTALL_PDB=OFF
-DAPU_HAVE_CRYPTO=${FEATURE_CRYPTO}
Expand Down

0 comments on commit 95677c8

Please sign in to comment.