Skip to content

Commit

Permalink
On the 'cmake-native-type' branch: CMake: Use BUILD_SHARED_LIBS inste…
Browse files Browse the repository at this point in the history
…ad of

APR_BUILD_SHARED/APR_BUILD_STATIC to specify build type.

* .github/workflows/windows.yml: Update to use BUILD_SHARED_LIBS.

* build/vcpkg/apr-2/portfile.cmake: Remove custom code to support
  APR_BUILD_SHARED/APR_BUILD_STATIC.

* CMakeLists.txt: Remove APR_BUILD_SHARED/APR_BUILD_STATIC build options and
  use BUILD_SHARED_LIBS. Remove TEST_STATIC_LIBS build option since it doesn't
  make sense now.

git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/cmake-native-type@1920428 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Ivan Zhakov committed Sep 3, 2024
1 parent 48da790 commit 2e1ad9d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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 }}"
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
75 changes: 22 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 +70,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(BUILD_SHARED_LIBS "Build using shared libraries" ON)
OPTION(APR_MODULAR_DSO "Use DSO build of modular components" ON)
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 Down Expand Up @@ -537,8 +526,7 @@ 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 ${PROJECT_BINARY_DIR}/${apr_libname}.pdb)
Expand All @@ -552,39 +540,34 @@ IF (APR_BUILD_SHARED)
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}
TARGET_COMPILE_DEFINITIONS(${apr_libname}
PRIVATE "APR_DECLARE_STATIC;APR_HAVE_MODULAR_DSO=${apr_have_modular_dso_10}"
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 +629,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 +647,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 +688,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 @@ -817,12 +792,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 2e1ad9d

Please sign in to comment.