Fix support for find_package(log4cxx) in consuming CMake projects (#19)
Fix support for find_package(log4cxx) in consuming CMake projects and add instructions for using log4cxx in a CMake build
Co-authored-by: Stephen Webb <stephen.webb@sabreautonomous.com.au>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 51a9c5a..026d3b4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@
ENDIF(WIN32 AND LOG4CXX_INSTALL_PDB)
if(UNIX)
+ # Support for pkg-config in consuming projects
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
@@ -54,13 +55,22 @@
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
endif(UNIX)
-
-# create export file which can be imported by other cmake projects
+# Support for find_package(log4cxx) in consuming CMake projects using
+# target_include_directories(myApplication PRIVATE $<TARGET_PROPERTY:log4cxx,INTERFACE_INCLUDE_DIRECTORIES>)
+# target_link_libraries( myApplication PRIVATE log4cxx)
install(EXPORT log4cxxTargets
- FILE log4cxx-targets.cmake
- NAMESPACE log4cxx::
+ FILE log4cxxConfig.cmake
DESTINATION share/cmake/log4cxx
)
+# Support for find_package(log4cxx 0.11) in consuming CMake projects
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/log4cxxConfigVersion.cmake"
+ VERSION ${PROJECT_VERSION}
+ COMPATIBILITY SameMinorVersion
+)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/log4cxxConfigVersion.cmake"
+ DESTINATION share/cmake/log4cxx
+)
#
# Get the varaibles from the subdirectories
diff --git a/src/site/apt/building/cmake.apt b/src/site/apt/building/cmake.apt
index 2bcdb6f..b53374c 100644
--- a/src/site/apt/building/cmake.apt
+++ b/src/site/apt/building/cmake.apt
@@ -107,3 +107,18 @@
$ make
$ make install
+----+
+
+* Using log4cxx in a CMake build
+
+ A log4cxxConfig.cmake and log4cxxConfigVersion.cmake is installed to allow use of find_package() in your CMakeLists.txt.
+
+ Below are example cmake commands that compile and link 'myApplication" with log4cxx.
+
++----+
+find_package(log4cxx 0.11)
+add_executable(myApplication myMain.cpp)
+target_include_directories(myApplication PRIVATE $<TARGET_PROPERTY:log4cxx,INTERFACE_INCLUDE_DIRECTORIES>)
+target_link_libraries( myApplication PRIVATE log4cxx)
++----+
+
+