You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2026/02/27 07:00:18 UTC
(logging-log4cxx) 01/01: Simplify use of log4cxx-qt in consuming CMake projects
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch qt_support_as_component
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 49c9cbd3a1fc04c0503da337f66cd86045b40815
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Fri Feb 27 17:59:30 2026 +1100
Simplify use of log4cxx-qt in consuming CMake projects
---
.github/workflows/log4cxx-ubuntu.yml | 25 ++++++++++++++++++++-----
CMakeLists.txt | 26 ++++++++++++++++++++------
Config.cmake.in | 20 ++++++++++++++++++++
src/examples/cpp/MyApp-qt/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++
src/examples/cpp/MyApp/CMakeLists.txt | 28 ++++++++++++++++++++++++++++
5 files changed, 119 insertions(+), 11 deletions(-)
diff --git a/.github/workflows/log4cxx-ubuntu.yml b/.github/workflows/log4cxx-ubuntu.yml
index 6375fedf..1421556f 100644
--- a/.github/workflows/log4cxx-ubuntu.yml
+++ b/.github/workflows/log4cxx-ubuntu.yml
@@ -105,9 +105,7 @@ jobs:
- name: 'run cmake - posix'
run: |
- cd main
- mkdir build
- cd build
+ ROOT=`pwd`
cmake \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
-DLOG4CXX_ENABLE_ODBC=${{ matrix.odbc }} \
@@ -118,8 +116,25 @@ jobs:
-DBUILD_FUZZERS=${{ matrix.fuzzers }} \
-DLOG4CXX_CHAR=${{ matrix.logchar }} \
-DLOG4CXX_BUILD_NEXT_ABI=${{ matrix.next_abi }} \
- ..
- cmake --build .
+ -DCMAKE_INSTALL_PREFIX=$ROOT/lib \
+ -S $ROOT/main \
+ -B $ROOT/build
+ cmake --build $ROOT/build --target install
+
+ - name: 'test installation'
+ run: |
+ ROOT=`pwd`
+ cmake \
+ -DCMAKE_PREFIX_PATH=$ROOT/lib \
+ -S $ROOT/main/src/examples/cpp/MyApp \
+ -B $ROOT/MyApp-build
+ cmake --build $ROOT/MyApp-build
+ if [ ${{ matrix.qt }} == ON ]; then
+ cmake \
+ -S $ROOT/main/src/examples/cpp/MyApp-qt \
+ -B $ROOT/MyApp-qt-build
+ cmake --build $ROOT/MyApp-qt-build
+ if
- name: run unit tests
shell: pwsh
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7db4e1eb..e81e6c01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -211,29 +211,42 @@ if(LOG4CXX_WITH_PKG_CONFIG)
endif(LOG4CXX_WITH_PKG_CONFIG)
# 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 ${LOG4CXX_LIB_NAME}Targets
- FILE ${LOG4CXX_LIB_NAME}Config.cmake
+ FILE ${LOG4CXX_LIB_NAME}Targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LOG4CXX_LIB_NAME}
)
-# Support for find_package(log4cxx 1.3) in consuming CMake projects
include(CMakePackageConfigHelpers)
+# Support find_package(log4cxx CONFIG) in consuming CMake projects
+configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
+ "${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}Config.cmake"
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LOG4CXX_LIB_NAME}
+ NO_SET_AND_CHECK_MACRO
+)
+# Support for find_package(log4cxx 1.6) in consuming CMake projects
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}ConfigVersion.cmake"
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}Config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LOG4CXX_LIB_NAME}
)
if(LOG4CXX_QT_SUPPORT)
+ # Support for find_package(log4cxx COMPONENTS qt) in consuming CMake projects
+ install(EXPORT ${LOG4CXX_LIB_NAME}-qtTargets
+ FILE ${LOG4CXX_LIB_NAME}-qtTargets.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LOG4CXX_LIB_NAME}
+ )
+ if(${log4cxx_VERSION_MAJOR} EQUAL 1)
+ # Support for find_package(log4cxx-qt) in consuming CMake projects
install(EXPORT ${LOG4CXX_LIB_NAME}-qtTargets
FILE ${LOG4CXX_LIB_NAME}-qtConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LOG4CXX_LIB_NAME}-qt
)
- # Support for find_package(log4cxx 0.11) in consuming CMake projects
- include(CMakePackageConfigHelpers)
+ # Support for find_package(log4cxx-qt 1.6) in consuming CMake projects
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}-qtConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
@@ -241,6 +254,7 @@ if(LOG4CXX_QT_SUPPORT)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LOG4CXX_LIB_NAME}-qtConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LOG4CXX_LIB_NAME}-qt
)
+ endif(${log4cxx_VERSION_MAJOR} 1)
endif(LOG4CXX_QT_SUPPORT)
#
diff --git a/Config.cmake.in b/Config.cmake.in
new file mode 100644
index 00000000..bde6eeae
--- /dev/null
+++ b/Config.cmake.in
@@ -0,0 +1,20 @@
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/${CMAKE_FIND_PACKAGE_NAME}Targets.cmake")
+
+# The components that can specified in find_package
+set(_${CMAKE_FIND_PACKAGE_NAME}_supported_components qt)
+
+foreach(component ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
+ # if we couldn't find the component, set the ${CMAKE_FIND_PACKAGE_NAME} library to no
+ # longer be found and notify the user about the missing component
+ if (NOT ${component} IN_LIST _${CMAKE_FIND_PACKAGE_NAME}_supported_components)
+ set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
+ set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "Unsupported component: ${component}")
+ else()
+ include(${CMAKE_CURRENT_LIST_DIR}/${CMAKE_FIND_PACKAGE_NAME}-${component}Targets.cmake)
+ set(${CMAKE_FIND_PACKAGE_NAME}_${component}_FOUND True)
+ endif()
+endforeach()
+
+check_required_components(${CMAKE_FIND_PACKAGE_NAME})
diff --git a/src/examples/cpp/MyApp-qt/CMakeLists.txt b/src/examples/cpp/MyApp-qt/CMakeLists.txt
new file mode 100644
index 00000000..db2b8b3f
--- /dev/null
+++ b/src/examples/cpp/MyApp-qt/CMakeLists.txt
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http:/www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+cmake_minimum_required(VERSION 3.13)
+project(MyApp LANGUAGES CXX)
+
+# Find the required libraries
+find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
+find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
+find_package(log4cxx REQUIRED)
+find_package(log4cxx COMPONENTS qt REQUIRED)
+
+# Build an executable that uses Qt and Log4cxx
+get_filename_component(SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY)
+add_executable(MyApp ${SOURCE_DIR}/MyApp-qt.cpp)
+target_include_directories(MyApp PRIVATE ${SOURCE_DIR})
+target_sources(MyApp PRIVATE ${SOURCE_DIR}/com/foo/config-qt.cpp ${SOURCE_DIR}/com/foo/bar-qt.cpp)
+target_link_libraries(MyApp PRIVATE Qt${QT_VERSION_MAJOR}::Core log4cxx-qt)
diff --git a/src/examples/cpp/MyApp/CMakeLists.txt b/src/examples/cpp/MyApp/CMakeLists.txt
new file mode 100644
index 00000000..5cfe07aa
--- /dev/null
+++ b/src/examples/cpp/MyApp/CMakeLists.txt
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http:/www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+cmake_minimum_required(VERSION 3.13)
+project(MyApp LANGUAGES CXX)
+
+# Find the required library
+find_package(log4cxx REQUIRED)
+
+# Build an executable that uses Log4cxx
+get_filename_component(SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY)
+add_executable(MyApp ${SOURCE_DIR}/MyApp2.cpp)
+target_include_directories(MyApp PRIVATE ${SOURCE_DIR})
+target_sources(MyApp PRIVATE ${SOURCE_DIR}/com/foo/config4.cpp ${SOURCE_DIR}/com/foo/bar.cpp)
+target_link_libraries(MyApp PRIVATE log4cxx)