Merge branch 'master' of https://gitbox.apache.org/repos/asf/logging-log4cxx
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 026d3b4..bc26ae6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,6 +12,12 @@
# Find Apache Runtime Utilities
find_package(APR-Util REQUIRED)
+# Add support for linking statically
+option(BUILD_SHARED_LIBS "Build shared libraries" ON)
+if(NOT BUILD_SHARED_LIBS)
+ set(LOG4CXX_COMPILE_DEFINITIONS LOG4CXX_STATIC)
+endif()
+
# Building
add_subdirectory(src)
@@ -33,12 +39,12 @@
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
-IF(WIN32 AND LOG4CXX_INSTALL_PDB)
+IF(WIN32 AND BUILD_SHARED_LIBS AND LOG4CXX_INSTALL_PDB)
INSTALL(FILES $<TARGET_PDB_FILE:log4cxx>
DESTINATION ${CMAKE_INSTALL_BINDIR}
CONFIGURATIONS RelWithDebInfo Debug
)
-ENDIF(WIN32 AND LOG4CXX_INSTALL_PDB)
+ENDIF()
if(UNIX)
# Support for pkg-config in consuming projects
@@ -98,7 +104,7 @@
message(STATUS "log4cxx configuration summary:")
message(STATUS "")
-message(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}")
+message(STATUS " Build shared library ............ : ${BUILD_SHARED_LIBS}")
message(STATUS " Build tests ..................... : ${BUILD_TESTING}")
message(STATUS " Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
message(STATUS " C++ compiler .................... : ${CMAKE_CXX_COMPILER}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 39420dd..3e0cb17 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,7 @@
add_subdirectory(main)
+target_compile_definitions(log4cxx PRIVATE ${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(log4cxx INTERFACE $<INSTALL_INTERFACE:include> PRIVATE ${APR_INCLUDE_DIR} ${APR_UTIL_INCLUDE_DIR})
-target_link_libraries(log4cxx PRIVATE ${APR_LIBRARIES} ${APR_UTIL_LIBRARIES})
+target_link_libraries(log4cxx PRIVATE ${APR_UTIL_LIBRARIES} ${XMLLIB_LIBRARIES} ${APR_LIBRARIES} ${APR_SYSTEM_LIBS})
if(WIN32)
# The ODBC appender is always enabled in the Windows configuration
target_link_libraries(log4cxx PRIVATE odbc32.lib)
diff --git a/src/cmake/FindAPR-Util.cmake b/src/cmake/FindAPR-Util.cmake
index 9b1ec68..4f07c93 100644
--- a/src/cmake/FindAPR-Util.cmake
+++ b/src/cmake/FindAPR-Util.cmake
@@ -37,9 +37,16 @@
_apu_invoke(APR_UTIL_LIBRARIES --link-ld)
else()
find_path(APR_UTIL_INCLUDE_DIR apu.h PATH_SUFFIXES apr-1)
- find_library(APR_UTIL_LIBRARIES NAMES libaprutil-1 aprutil-1)
- find_path(APR_UTIL_DLL_DIR libaprutil-1.dll)
+ if (APU_STATIC OR NOT BUILD_SHARED_LIBS)
+ set(APR_UTIL_COMPILE_DEFINITIONS APU_DECLARE_STATIC)
+ find_library(APR_UTIL_LIBRARIES NAMES aprutil-1)
+ find_library(XMLLIB_LIBRARIES NAMES libexpat)
+ find_program(XMLLIB_DLL libexpat.dll)
+ else()
+ find_library(APR_UTIL_LIBRARIES NAMES libaprutil-1)
+ find_program(APR_UTIL_DLL libaprutil-1.dll)
+ endif()
endif()
-find_package_handle_standard_args(apr-util DEFAULT_MSG
+find_package_handle_standard_args(APR-Util DEFAULT_MSG
APR_UTIL_INCLUDE_DIR APR_UTIL_LIBRARIES)
diff --git a/src/cmake/FindAPR.cmake b/src/cmake/FindAPR.cmake
index 7678519..92eaa98 100644
--- a/src/cmake/FindAPR.cmake
+++ b/src/cmake/FindAPR.cmake
@@ -36,9 +36,15 @@
_apr_invoke(APR_LIBRARIES --link-ld)
else()
find_path(APR_INCLUDE_DIR apr.h PATH_SUFFIXES apr-1)
- find_library(APR_LIBRARIES NAMES libapr-1 apr-1)
- find_path(APR_DLL_DIR libapr-1.dll)
+ if (APR_STATIC OR NOT BUILD_SHARED_LIBS)
+ set(APR_SYSTEM_LIBS ws2_32 mswsock rpcrt4)
+ set(APR_COMPILE_DEFINITIONS APR_DECLARE_STATIC)
+ find_library(APR_LIBRARIES NAMES apr-1)
+ else()
+ find_library(APR_LIBRARIES NAMES libapr-1)
+ find_program(APR_DLL libapr-1.dll)
+ endif()
endif()
-find_package_handle_standard_args(apr
+find_package_handle_standard_args(APR
APR_INCLUDE_DIR APR_LIBRARIES)
diff --git a/src/examples/cpp/CMakeLists.txt b/src/examples/cpp/CMakeLists.txt
index ed0412a..05614b3 100644
--- a/src/examples/cpp/CMakeLists.txt
+++ b/src/examples/cpp/CMakeLists.txt
@@ -2,6 +2,7 @@
foreach(exampleName IN LISTS ALL_LOG4CXX_EXAMPLES)
add_executable(${exampleName} ${exampleName}.cpp)
+ target_compile_definitions(${exampleName} PRIVATE ${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(${exampleName} PRIVATE ${CMAKE_CURRENT_LIST_DIR} $<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
- target_link_libraries(${exampleName} PRIVATE log4cxx ${APR_LIBRARIES})
+ target_link_libraries(${exampleName} PRIVATE log4cxx ${APR_UTIL_LIBRARIES} ${XMLLIB_LIBRARIES} ${APR_LIBRARIES} ${APR_SYSTEM_LIBS})
endforeach()
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 779554a..321edf0 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -1,7 +1,6 @@
# Options
option(LOG4CXX_BLOCKING_ASYNC_APPENDER "Async appender behaviour" ON)
-option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Build the log4cxx library
add_library(log4cxx action.cpp)
diff --git a/src/site/apt/building/cmake.apt b/src/site/apt/building/cmake.apt
index 94acdf1..fbbecac 100644
--- a/src/site/apt/building/cmake.apt
+++ b/src/site/apt/building/cmake.apt
@@ -46,7 +46,16 @@
*------------------------+---------------------------------------------------------------------------------------------+
| -DLOG4CXX_CFSTRING=yes | Enable CFString API methods, requires Mac OS/X CoreFoundation, choice of yes, no (default). |
*------------------------+---------------------------------------------------------------------------------------------+
-| -DBUILD_TESTING=off | Disable tests. Tests are enabled by default |
+| -DBUILD_TESTING=off | Do not build tests. Tests are built by default |
+*------------------------+---------------------------------------------------------------------------------------------+
+| -DBUILD_SHARED_LIBS=off| Build log4cxx as a static library. A dynamically linked log4cxx library is built by default.|
+| | Any compilation unit that includes a log4cxx header must define LOG4CXX_STATIC. |
+*------------------------+---------------------------------------------------------------------------------------------+
+| -DAPU_STATIC=yes | Link to the APR-Util static library. By default, the log4cxx shared library is linked to the|
+| | APR-Util shared library. If BUILD_SHARED_LIBS=off, the static APR-Util library is used. |
+*------------------------+---------------------------------------------------------------------------------------------+
+| -DAPR_STATIC=yes | Link to the APR static library. By default, the log4cxx shared library is linked to the |
+| | APR shared library. If BUILD_SHARED_LIBS=off, the static APR library is always used. |
*------------------------+---------------------------------------------------------------------------------------------+
Building and testing log4cxx on a Microsoft Windows with APR, Expat and APR-Util built from source
diff --git a/src/test/cpp/CMakeLists.txt b/src/test/cpp/CMakeLists.txt
index 8c90999..bdb66fe 100644
--- a/src/test/cpp/CMakeLists.txt
+++ b/src/test/cpp/CMakeLists.txt
@@ -1,5 +1,6 @@
# Components required by all tests
add_library(testingFramework STATIC abts.cpp appenderskeletontestcase.cpp logunit.cpp vectorappender.cpp writerappendertestcase.cpp )
+target_compile_definitions(testingFramework PRIVATE ${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(testingFramework PRIVATE ${CMAKE_CURRENT_LIST_DIR} $<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
add_subdirectory(util)
target_sources(testingUtilities PRIVATE xml/xlevel.cpp)
@@ -50,15 +51,20 @@
add_subdirectory(xml)
foreach(testName IN LISTS ALL_LOG4CXX_TESTS)
+ target_compile_definitions(${testName} PRIVATE ${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(${testName} PRIVATE ${CMAKE_CURRENT_LIST_DIR} $<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
- target_link_libraries(${testName} PRIVATE testingFramework testingUtilities log4cxx ${APR_LIBRARIES})
+ target_link_libraries(${testName} PRIVATE testingFramework testingUtilities log4cxx ${APR_LIBRARIES} ${APR_SYSTEM_LIBS})
add_test(NAME ${testName}
COMMAND ${testName} -v
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../resources
)
if(WIN32)
- set(LOG4CXX_DLL_DIR "$<SHELL_PATH:$<TARGET_FILE_DIR:log4cxx>>")
+ get_filename_component(APR_DLL_DIR "${APR_DLL}" DIRECTORY)
+ get_filename_component(APR_UTIL_DLL_DIR "${APR_UTIL_DLL}" DIRECTORY)
+ get_filename_component(XMLLIB_DLL_DIR "${XMLLIB_DLL}" DIRECTORY)
+ set(PATH_FOR_TESTS $<SHELL_PATH:$<TARGET_FILE_DIR:log4cxx>> ${APR_DLL_DIR} ${APR_UTIL_DLL_DIR} ${XMLLIB_DLL_DIR})
+ list(REMOVE_DUPLICATES PATH_FOR_TESTS)
if(${testName} STREQUAL socketservertestcase)
set_tests_properties(socketservertestcase PROPERTIES
ENVIRONMENT "SOCKET_SERVER_PARAMETER_FILE=${START_SOCKET_SERVER_PARAMETER_FILE};PATH=${LOG4CXX_DLL_DIR}\;${APR_DLL_DIR}\;${APR_UTIL_DLL_DIR}"
diff --git a/src/test/cpp/db/CMakeLists.txt b/src/test/cpp/db/CMakeLists.txt
index 3f34418..ccf4d9f 100644
--- a/src/test/cpp/db/CMakeLists.txt
+++ b/src/test/cpp/db/CMakeLists.txt
@@ -1,3 +1,4 @@
add_executable(odbcappendertestcase odbcappendertestcase.cpp)
+target_compile_definitions(odbcappendertestcase PRIVATE ${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(odbcappendertestcase PRIVATE ${CMAKE_CURRENT_LIST_DIR} $<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
-target_link_libraries(odbcappendertestcase log4cxx testingFramework testingUtilities ${APR_LIBRARIES})
+target_link_libraries(odbcappendertestcase log4cxx testingFramework testingUtilities ${APR_LIBRARIES} ${APR_SYSTEM_LIBS})
diff --git a/src/test/cpp/helpers/CMakeLists.txt b/src/test/cpp/helpers/CMakeLists.txt
index bb27546..78aa1b1 100644
--- a/src/test/cpp/helpers/CMakeLists.txt
+++ b/src/test/cpp/helpers/CMakeLists.txt
@@ -21,6 +21,7 @@
)
foreach(fileName IN LISTS HELPER_TESTS)
add_executable(${fileName} "${fileName}.cpp")
+ target_compile_definitions(${fileName} PRIVATE ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(${fileName} PRIVATE ${CMAKE_CURRENT_LIST_DIR} $<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES> ${APR_INCLUDE_DIR})
endforeach()
target_sources(cacheddateformattestcase PRIVATE localechanger.cpp)
diff --git a/src/test/cpp/util/CMakeLists.txt b/src/test/cpp/util/CMakeLists.txt
index dd25dd7..c818ab8 100644
--- a/src/test/cpp/util/CMakeLists.txt
+++ b/src/test/cpp/util/CMakeLists.txt
@@ -18,4 +18,5 @@
xmlthreadfilter.cpp
xmltimestampfilter.cpp
)
+target_compile_definitions(testingUtilities PRIVATE ${LOG4CXX_COMPILE_DEFINITIONS} ${APR_COMPILE_DEFINITIONS} ${APR_UTIL_COMPILE_DEFINITIONS} )
target_include_directories(testingUtilities PRIVATE ${CMAKE_CURRENT_LIST_DIR} $<TARGET_PROPERTY:log4cxx,INCLUDE_DIRECTORIES>)
diff --git a/src/test/cpp/xml/CMakeLists.txt b/src/test/cpp/xml/CMakeLists.txt
index 2f265ce..bddfe48 100644
--- a/src/test/cpp/xml/CMakeLists.txt
+++ b/src/test/cpp/xml/CMakeLists.txt
@@ -4,5 +4,5 @@
xmllayouttestcase
)
-target_link_libraries(xmltests PRIVATE ${APR_UTIL_LIBRARIES})
+target_link_libraries(xmltests PRIVATE ${APR_UTIL_LIBRARIES} ${XMLLIB_LIBRARIES})
set(ALL_LOG4CXX_TESTS ${ALL_LOG4CXX_TESTS} xmltests PARENT_SCOPE)