summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt188
1 files changed, 135 insertions, 53 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b9c5d8..d16eec6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,14 +21,45 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(APR C)
+# Enable support for MSVC runtime library selection by abstraction
+# if supported by CMake.
+IF(POLICY CMP0091)
+ CMAKE_POLICY(SET CMP0091 NEW)
+ENDIF()
+
+# Add simple support CMAKE_WARNING_AS_ERROR if CMake doesn't
+# support it.
+IF (CMAKE_VERSION VERSION_LESS 3.24)
+ IF(CMAKE_WARNING_AS_ERROR AND MSVC)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
+ ENDIF()
+ENDIF()
+
+SET(apr_name apr-1)
+SET(apr_libname libapr-1)
+
OPTION(APR_INSTALL_PRIVATE_H "Install selected private .h files (for httpd)" 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" OFF)
+OPTION(APR_BUILD_SHARED "Build shared libraries" ON)
+OPTION(APR_BUILD_STATIC "Build static libraries" ON)
OPTION(TEST_STATIC_LIBS "Test programs use APR static libraries instead of shared libraries?" OFF)
SET(MIN_WINDOWS_VER "Vista"
CACHE STRING "Minimum Windows version")
+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" 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()
+
# create 1-or-0 representation of feature tests for apr.h
SET(apr_have_ipv6_10 0)
@@ -47,6 +78,13 @@ ELSE()
SET(win32_winnt_str ${MIN_WINDOWS_VER})
ENDIF()
+# Read current version.
+FILE(STRINGS include/apr_version.h VERSION_STRINGS REGEX "#define (APR_MAJOR_VERSION|APR_MINOR_VERSION|APR_PATCH_VERSION)")
+
+STRING(REGEX REPLACE ".*#define APR_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" APR_MAJOR_VERSION ${VERSION_STRINGS})
+STRING(REGEX REPLACE ".*#define APR_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" APR_MINOR_VERSION ${VERSION_STRINGS})
+STRING(REGEX REPLACE ".*#define APR_PATCH_VERSION[ \t]+([0-9]+).*" "\\1" APR_PATCH_VERSION ${VERSION_STRINGS})
+
CONFIGURE_FILE(include/apr.hwc
${PROJECT_BINARY_DIR}/apr.h)
@@ -71,16 +109,15 @@ ADD_CUSTOM_TARGET(
# you've generated apr.h before using a different build
SET(APR_INCLUDE_DIRECTORIES
- ${PROJECT_BINARY_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/include
- ${CMAKE_CURRENT_SOURCE_DIR}/include/arch/win32
- ${CMAKE_CURRENT_SOURCE_DIR}/include/arch/unix
- ${CMAKE_CURRENT_SOURCE_DIR}/include/private
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/arch/win32>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/arch/unix>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/private>
)
SET(APR_SYSTEM_LIBS
ws2_32
- mswsock
rpcrt4
)
@@ -261,28 +298,62 @@ SET(APR_TEST_SUITES
SET(install_targets)
SET(install_bin_pdb)
+IF (MSVC)
+ # Ignore Microsoft's interpretation of secure development
+ # and the POSIX string handling API
+ ADD_COMPILE_DEFINITIONS(_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_WARNINGS)
+ENDIF()
+
# libapr-1 is shared, apr-1 is static
-ADD_LIBRARY(libapr-1 SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc)
-SET(install_targets ${install_targets} libapr-1)
-SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/libapr-1.pdb)
-TARGET_LINK_LIBRARIES(libapr-1 ${APR_SYSTEM_LIBS})
-SET_TARGET_PROPERTIES(libapr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_EXPORT;WINNT")
-ADD_DEPENDENCIES(libapr-1 test_char_header)
-
-ADD_LIBRARY(apr-1 STATIC ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED})
-SET(install_targets ${install_targets} apr-1)
-TARGET_LINK_LIBRARIES(apr-1 ${APR_SYSTEM_LIBS})
-SET_TARGET_PROPERTIES(apr-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;WINNT")
-ADD_DEPENDENCIES(apr-1 test_char_header)
+IF (APR_BUILD_SHARED)
+ ADD_LIBRARY(${apr_libname} SHARED ${APR_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libapr.rc)
+ LIST(APPEND install_targets ${apr_libname})
+ LIST(APPEND install_bin_pdb ${PROJECT_BINARY_DIR}/${apr_libname}.pdb)
+ TARGET_LINK_LIBRARIES(${apr_libname}
+ PRIVATE ${APR_SYSTEM_LIBS})
+ TARGET_COMPILE_DEFINITIONS(${apr_libname}
+ PRIVATE "APR_DECLARE_EXPORT;WINNT"
+ INTERFACE "APR_DECLARE_IMPORT;WINNT")
+ TARGET_INCLUDE_DIRECTORIES(${apr_libname}
+ PRIVATE ${APR_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_PUBLIC_HEADERS_GENERATED})
+ LIST(APPEND install_targets ${apr_name})
+ TARGET_LINK_LIBRARIES(${apr_name}
+ PRIVATE ${APR_SYSTEM_LIBS})
+ TARGET_COMPILE_DEFINITIONS(${apr_name}
+ PRIVATE "APR_DECLARE_STATIC;WINNT"
+ INTERFACE "APR_DECLARE_STATIC;WINNT")
+ TARGET_INCLUDE_DIRECTORIES(${apr_name}
+ PRIVATE ${APR_INCLUDE_DIRECTORIES}
+ INTERFACE $<INSTALL_INTERFACE:${APR_INSTALL_INCLUDE_DIR}> ${APR_INCLUDE_DIRECTORIES}
+ )
+ ADD_DEPENDENCIES(${apr_name} test_char_header)
+ENDIF()
# libaprapp-1 and aprapp-1 are static
-ADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
-SET(install_targets ${install_targets} libaprapp-1)
-SET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT")
+IF (APR_BUILD_SHARED)
+ ADD_LIBRARY(libaprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
+ LIST(APPEND install_targets libaprapp-1)
+ SET_TARGET_PROPERTIES(libaprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_APP;WINNT")
+ TARGET_INCLUDE_DIRECTORIES(libaprapp-1
+ PRIVATE ${APR_INCLUDE_DIRECTORIES}
+ )
+ENDIF()
-ADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
-SET(install_targets ${install_targets} aprapp-1)
-SET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT")
+IF (APR_BUILD_STATIC)
+ ADD_LIBRARY(aprapp-1 STATIC misc/win32/apr_app.c misc/win32/internal.c ${APR_PUBLIC_HEADERS_GENERATED})
+ LIST(APPEND install_targets aprapp-1)
+ SET_TARGET_PROPERTIES(aprapp-1 PROPERTIES COMPILE_DEFINITIONS "APR_DECLARE_STATIC;APR_APP;WINNT")
+ TARGET_INCLUDE_DIRECTORIES(aprapp-1
+ PRIVATE ${APR_INCLUDE_DIRECTORIES}
+ )
+ENDIF()
IF(APR_BUILD_TESTAPR)
ENABLE_TESTING()
@@ -300,21 +371,16 @@ IF(APR_BUILD_TESTAPR)
${PROJECT_BINARY_DIR}/data/mmap_datafile.txt)
IF(TEST_STATIC_LIBS)
- SET(whichapr apr-1)
+ SET(whichapr ${apr_name})
SET(whichaprapp aprapp-1)
- SET(apiflag -DAPR_DECLARE_STATIC)
ELSE()
- SET(whichapr libapr-1)
+ SET(whichapr ${apr_libname})
SET(whichaprapp libaprapp-1)
- SET(apiflag)
ENDIF()
ADD_EXECUTABLE(testapp test/testapp.c)
- TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp} ${APR_SYSTEM_LIBS})
+ TARGET_LINK_LIBRARIES(testapp ${whichapr} ${whichaprapp})
SET_TARGET_PROPERTIES(testapp PROPERTIES LINK_FLAGS /entry:wmainCRTStartup)
- IF(apiflag)
- SET_TARGET_PROPERTIES(testapp PROPERTIES COMPILE_FLAGS ${apiflag})
- ENDIF()
ADD_TEST(NAME testapp COMMAND testapp)
SET (APR_TEST_SOURCES
@@ -327,27 +393,21 @@ IF(APR_BUILD_TESTAPR)
ENDFOREACH()
ADD_EXECUTABLE(testall ${APR_TEST_SOURCES})
- TARGET_LINK_LIBRARIES(testall ${whichapr} ${APR_SYSTEM_LIBS})
+ TARGET_LINK_LIBRARIES(testall ${whichapr} ws2_32.lib)
SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_DEFINITIONS "BINPATH=$<TARGET_FILE_DIR:testall>")
- IF(apiflag)
- SET_TARGET_PROPERTIES(testall PROPERTIES COMPILE_FLAGS ${apiflag})
- ENDIF()
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} ${APR_SYSTEM_LIBS})
+ TARGET_LINK_LIBRARIES(mod_test ${whichapr})
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)
GET_PROPERTY(link_flags TARGET mod_test PROPERTY LINK_FLAGS)
SET(link_flags "${link_flags} /export:count_reps")
SET_TARGET_PROPERTIES(mod_test PROPERTIES LINK_FLAGS ${link_flags})
- IF(apiflag)
- SET_TARGET_PROPERTIES(mod_test PROPERTIES COMPILE_FLAGS ${apiflag})
- ENDIF()
# Build all the single-source executable files with no special build
# requirements.
@@ -371,11 +431,10 @@ 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} ${APR_SYSTEM_LIBS})
+ TARGET_LINK_LIBRARIES(${proggie} ${whichapr})
SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_DEFINITIONS "BINPATH=$<TARGET_FILE_DIR:${proggie}>")
- IF(apiflag)
- SET_TARGET_PROPERTIES(${proggie} PROPERTIES COMPILE_FLAGS ${apiflag})
- ENDIF()
+
+ ADD_DEPENDENCIES(testall ${proggie})
ENDFOREACH()
# Add tests for programs that run by themselves with no arguments.
@@ -401,20 +460,38 @@ IF(APR_BUILD_TESTAPR)
ENDIF (APR_BUILD_TESTAPR)
# Installation
+INCLUDE(CMakePackageConfigHelpers)
+
+string(TOLOWER "${PROJECT_NAME}" project_name_lower)
-INSTALL(TARGETS ${install_targets}
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION lib
- ARCHIVE DESTINATION lib
- )
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${project_name_lower}-config-version.cmake"
+ VERSION ${APR_MAJOR_VERSION}.${APR_MINOR_VERSION}.${APR_PATCH_VERSION}
+ COMPATIBILITY SameMajorVersion
+)
+
+INSTALL(TARGETS ${install_targets} EXPORT apr-config
+ RUNTIME DESTINATION ${APR_INSTALL_BIN_DIR}
+ LIBRARY DESTINATION ${APR_INSTALL_LIB_DIR}
+ ARCHIVE DESTINATION ${APR_INSTALL_LIB_DIR}
+)
+
+INSTALL(EXPORT apr-config
+ NAMESPACE apr::
+ DESTINATION "lib/cmake/${project_name_lower}"
+ FILE "${project_name_lower}-config.cmake"
+)
+
+INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/${project_name_lower}-config-version.cmake"
+ DESTINATION "lib/cmake/${project_name_lower}"
+)
IF(INSTALL_PDB)
INSTALL(FILES ${install_bin_pdb}
- DESTINATION bin
+ DESTINATION ${APR_INSTALL_BIN_DIR}
CONFIGURATIONS RelWithDebInfo Debug)
ENDIF()
-INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION include)
+INSTALL(FILES ${APR_PUBLIC_HEADERS_STATIC} ${APR_PUBLIC_HEADERS_GENERATED} DESTINATION ${APR_INSTALL_INCLUDE_DIR})
IF(APR_INSTALL_PRIVATE_H)
# Kludges for unexpected dependencies of httpd 2.x, not installed by default
SET(APR_PRIVATE_H_FOR_HTTPD
@@ -423,8 +500,8 @@ IF(APR_INSTALL_PRIVATE_H)
include/arch/win32/apr_arch_utf8.h
include/arch/win32/apr_private.h
)
- INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION include/arch/win32)
- INSTALL(FILES include/arch/apr_private_common.h DESTINATION include/arch)
+ INSTALL(FILES ${APR_PRIVATE_H_FOR_HTTPD} DESTINATION ${APR_INSTALL_INCLUDE_DIR}/arch/win32)
+ INSTALL(FILES include/arch/apr_private_common.h DESTINATION ${APR_INSTALL_INCLUDE_DIR}/arch)
ENDIF()
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" buildtype)
@@ -436,9 +513,14 @@ MESSAGE(STATUS "")
MESSAGE(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}")
MESSAGE(STATUS " Install .pdb (if available)...... : ${INSTALL_PDB}")
MESSAGE(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
+MESSAGE(STATUS " Directory for binary files .... : PREFIX/${APR_INSTALL_BIN_DIR}")
+MESSAGE(STATUS " Directory for library files ... : PREFIX/${APR_INSTALL_LIB_DIR}")
+MESSAGE(STATUS " Directory for include files ... : PREFIX/${APR_INSTALL_INCLUDE_DIR}")
MESSAGE(STATUS " C compiler ...................... : ${CMAKE_C_COMPILER}")
MESSAGE(STATUS " IPv6 ............................ : ${APR_HAVE_IPV6}")
MESSAGE(STATUS " Minimum Windows version ......... : ${MIN_WINDOWS_VER}")
+MESSAGE(STATUS " Build shared libs ............... : ${APR_BUILD_SHARED}")
+MESSAGE(STATUS " Build static libs ............... : ${APR_BUILD_STATIC}")
MESSAGE(STATUS " Build test suite ................ : ${APR_BUILD_TESTAPR}")
IF(TEST_STATIC_LIBS)
MESSAGE(STATUS " (testing static libraries)")