This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new 77b7672f Simplify use of log4cxx-qt in consuming CMake projects (#600)
77b7672f is described below
commit 77b7672fa410528aa38bc0b6705f1c5487d241eb
Author: Stephen Webb <[email protected]>
AuthorDate: Wed Mar 4 12:43:21 2026 +1100
Simplify use of log4cxx-qt in consuming CMake projects (#600)
* When log4cxx is built with FMTLayout, fmt::fmt must be made available in
the consuming CMake project
* Add example CMake files to the web-site documentation
* Remove 'find_package(log4cxx-qt)' support when building in vcpkg
* Add installation test to Windows CI
* #include APR before Qt as Qt defines __has_attribute
---
.github/workflows/log4cxx-ubuntu.yml | 33 ++++++++++++-----
.github/workflows/log4cxx-windows.yml | 61 +++++++++++++++++++++++++-------
CMakeLists.txt | 26 ++++++++++----
Config.cmake.in | 20 +++++++++++
src/examples/cpp/MyApp-qt/CMakeLists.txt | 33 +++++++++++++++++
src/examples/cpp/MyApp/CMakeLists.txt | 30 ++++++++++++++++
src/site/markdown/buildsystems.md | 8 +++++
src/test/cpp/qtconfigurationtest.cpp | 4 +--
8 files changed, 187 insertions(+), 28 deletions(-)
diff --git a/.github/workflows/log4cxx-ubuntu.yml
b/.github/workflows/log4cxx-ubuntu.yml
index 6375fedf..e614ff8f 100644
--- a/.github/workflows/log4cxx-ubuntu.yml
+++ b/.github/workflows/log4cxx-ubuntu.yml
@@ -105,9 +105,8 @@ jobs:
- name: 'run cmake - posix'
run: |
- cd main
- mkdir build
- cd build
+ ROOT=`pwd`
+ set -x
cmake \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
-DLOG4CXX_ENABLE_ODBC=${{ matrix.odbc }} \
@@ -118,12 +117,30 @@ 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`
+ set -x
+ 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 \
+ -DCMAKE_PREFIX_PATH=$ROOT/lib \
+ -S $ROOT/main/src/examples/cpp/MyApp-qt \
+ -B $ROOT/MyApp-qt-build
+ cmake --build $ROOT/MyApp-qt-build
+ fi
- name: run unit tests
- shell: pwsh
run: |
- cd main
- cd build
+ ROOT=`pwd`
+ cd $ROOT/build
ctest -C Debug --output-on-failure
diff --git a/.github/workflows/log4cxx-windows.yml
b/.github/workflows/log4cxx-windows.yml
index e17f30c4..67dc667a 100644
--- a/.github/workflows/log4cxx-windows.yml
+++ b/.github/workflows/log4cxx-windows.yml
@@ -20,16 +20,18 @@ jobs:
job:
name: ${{ matrix.os }}-${{ matrix.cxx }}-build-and-test
runs-on: ${{ matrix.os }}
- timeout-minutes: 38
strategy:
fail-fast: false
matrix:
- name: [windows-2022, windows-2025]
+ name: [windows-2022, windows-2025-qt]
include:
- name: windows-2022
os: windows-2022
- - name: windows-2025
+ qt: OFF
+ - name: windows-2025-qt
os: windows-2025
+ qt: ON
+ qt_component: qtbase
steps:
- uses: actions/checkout@v4
@@ -59,7 +61,7 @@ jobs:
run: |
cd vcpkg
./bootstrap-vcpkg.bat
- ./vcpkg install apr apr-util fmt --triplet=x64-windows
+ ./vcpkg install apr apr-util fmt ${{ matrix.qt_component }}
--triplet=x64-windows
- name: 'Install zip'
id: install-zip
@@ -71,16 +73,51 @@ jobs:
- name: 'run cmake'
shell: pwsh
run: |
- $THISDIR=Get-Location
- cd main
- mkdir build
- cd build
- cmake -DLOG4CXX_TEST_PROGRAM_PATH=C:\msys64\usr\bin
-DLOG4CXX_CHAR=wchar_t -DLOG4CXX_ENABLE_ODBC=on
"-DCMAKE_TOOLCHAIN_FILE=$THISDIR/vcpkg/scripts/buildsystems/vcpkg.cmake" ..
- cmake --build .
+ $ErrorActionPreference="Stop"
+ $ROOT=Get-Location
+ Set-PSDebug -Trace 1
+ cmake `
+ -DLOG4CXX_CHAR=wchar_t `
+ -DLOG4CXX_ENABLE_ODBC=on `
+ "-DLOG4CXX_QT_SUPPORT=${{ matrix.qt }}" `
+ "-DLOG4CXX_TEST_PROGRAM_PATH=C:\msys64\usr\bin" `
+
"-DCMAKE_TOOLCHAIN_FILE=$ROOT/vcpkg/scripts/buildsystems/vcpkg.cmake" `
+ "-DVCPKG_TARGET_TRIPLET=x64-windows" `
+ "-DCMAKE_INSTALL_PREFIX=$ROOT/Libraries" `
+ -S "$ROOT/main" `
+ -B "$ROOT/build"
+
+ cmake --build "$ROOT/build" --target INSTALL --config Release
+
+ - name: 'test installation'
+ shell: pwsh
+ run: |
+ $ErrorActionPreference="Stop"
+ $ROOT=Get-Location
+ Set-PSDebug -Trace 1
+ cmake `
+ "-DCMAKE_PREFIX_PATH=$ROOT/Libraries" `
+
"-DCMAKE_TOOLCHAIN_FILE=$ROOT/vcpkg/scripts/buildsystems/vcpkg.cmake" `
+ "-DVCPKG_TARGET_TRIPLET=x64-windows" `
+ -S "$ROOT/main/src/examples/cpp/MyApp" `
+ -B "$ROOT/MyApp-build"
+
+ cmake --build "$ROOT/MyApp-build" --config Release
+
+ if ( "${{ matrix.qt }}" -eq "ON" ) {
+ cmake `
+ "-DCMAKE_PREFIX_PATH=$ROOT/Libraries" `
+
"-DCMAKE_TOOLCHAIN_FILE=$ROOT/vcpkg/scripts/buildsystems/vcpkg.cmake" `
+ "-DVCPKG_TARGET_TRIPLET=x64-windows" `
+ -S "$ROOT/main/src/examples/cpp/MyApp-qt" `
+ -B "$ROOT/MyApp-qt-build"
+
+ cmake --build "$ROOT/MyApp-qt-build" --config Release
+ }
- name: run unit tests
shell: pwsh
+ timeout-minutes: 10
run: |
- cd main
cd build
- ctest -C Debug --output-on-failure
+ ctest -C Release --output-on-failure
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7db4e1eb..194a3e6b 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 AND NOT DEFINED VCPKG_TARGET_TRIPLET)
+ # 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} EQUAL 1 AND NOT DEFINED VCPKG_TARGET_TRIPLET)
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..7400ff0e
--- /dev/null
+++ b/src/examples/cpp/MyApp-qt/CMakeLists.txt
@@ -0,0 +1,33 @@
+#
+# 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)
+# Optionally locate fmt::fmt
+find_package(fmt QUIET)
+
+# 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..b67b5439
--- /dev/null
+++ b/src/examples/cpp/MyApp/CMakeLists.txt
@@ -0,0 +1,30 @@
+#
+# 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)
+# Optionally locate fmt::fmt
+find_package(fmt QUIET)
+
+# 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)
diff --git a/src/site/markdown/buildsystems.md
b/src/site/markdown/buildsystems.md
index 13674bba..ef29c8ef 100644
--- a/src/site/markdown/buildsystems.md
+++ b/src/site/markdown/buildsystems.md
@@ -41,6 +41,8 @@ find_package(log4cxx)
target_link_libraries( executable PRIVATE log4cxx )
~~~
+See \ref MyApp/CMakeLists.txt and \ref MyApp-qt/CMakeLists.txt for more
complete examples.
+
# How do I use Log4cxx with CMake and pkg-config? {#use_with_cmake_pkgconfig}
Add the following to your CMakeLists.txt file:
@@ -77,3 +79,9 @@ LDFLAGS += $(shell pkg-config --libs liblog4cxx)
all: main.o
$(CXX) -o application main.o $(LDFLAGS)
~~~
+
+\example MyApp/CMakeLists.txt
+This example shows one way to include Log4cxx in a consuming CMake project.
+
+\example MyApp-qt/CMakeLists.txt
+This example shows how to include Qt specific Log4cxx features in a consuming
CMake project.
diff --git a/src/test/cpp/qtconfigurationtest.cpp
b/src/test/cpp/qtconfigurationtest.cpp
index dd025831..19375cf7 100644
--- a/src/test/cpp/qtconfigurationtest.cpp
+++ b/src/test/cpp/qtconfigurationtest.cpp
@@ -15,6 +15,8 @@
* limitations under the License.
*/
#include "logunit.h"
+#include <apr_file_io.h>
+#include <apr_time.h>
#include <log4cxx/logger.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/helpers/bytebuffer.h>
@@ -26,8 +28,6 @@
#include <log4cxx/helpers/transcoder.h>
#include <log4cxx-qt/configuration.h>
#include <log4cxx-qt/transcoder.h>
-#include <apr_file_io.h>
-#include "apr_time.h"
#include <QCoreApplication>
#include <QFileInfo>