|
From: <log...@li...> - 2026-02-10 22:07:47
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Log4cpp Git repository.".
The branch, master has been updated
via f88cdf00ece1dbe04cd97bf78b614775e72e2e98 (commit)
via 757e846946ce77fc503e5f4a7ebe0e107bf2a269 (commit)
via 4ca28ef4d07a107fbb3286e1c4d332b74d383a0b (commit)
via c08c0dab44048dd6b6949c9c3bcbb2990c38aef9 (commit)
from 4d87c33c33d070210f5805f052bdd1905b8de845 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://sourceforge.net/p/log4cpp/codegit/ci/
commit f88cdf00ece1dbe04cd97bf78b614775e72e2e98
Author: Alexander Perepelkin <san...@us...>
Date: Tue Feb 10 16:22:33 2026 +0100
Building examples is enabled via the LOG4CPP_BUILD_EXAMPLES option.
CMake usage examples are provided for both scenarios: importing a CMake-installed log4cpp library and using log4cpp as a CMake subproject.
Both shared and static library variants are demonstrated.
The CMake usage examples can be built either as part of the log4cpp library (when LOG4CPP_BUILD_EXAMPLES is enabled) or as standalone CMake applications that import or include log4cpp from their own directories.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e55761a..18eabeb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@
# Alexander Perepelkin san...@us...
#
# Note:
-# (1) A dummy file include/config.h is required (remnant from configure)
+# (1) A dummy file include/config.h is required (remnant from configure, produced by command ./configure)
# (2) Default installation directory is /usr/local, override with -DCMAKE_INSTALL_PREFIX="" during cmake
# invocation
# (3) Do the usual "make clean all" to build the library
@@ -20,12 +20,20 @@ INCLUDE ( CMakePackageConfigHelpers )
SET ( LOG4CPP_LIBRARY_NAME "log4cpp" )
#SET ( CMAKE_VERBOSE_MAKEFILE ON )
+IF ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR )
+ SET ( LOG4CPP_IS_TOP_LEVEL ON )
+ELSE ()
+ SET ( LOG4CPP_IS_TOP_LEVEL OFF )
+ENDIF ()
+
FIND_PACKAGE ( Threads REQUIRED )
IF (NOT CMAKE_BUILD_TYPE)
SET ( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." )
ENDIF ()
+OPTION ( LOG4CPP_BUILD_EXAMPLES "Build log4cpp examples" OFF )
+
# for macOS use var APPLE
IF (WIN32)
SET ( CMAKE_DEBUG_POSTFIX "D" )
@@ -199,3 +207,7 @@ INSTALL (
${CMAKE_CURRENT_BINARY_DIR}/log4cppConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/log4cpp
)
+
+IF ( LOG4CPP_BUILD_EXAMPLES AND LOG4CPP_IS_TOP_LEVEL )
+ ADD_SUBDIRECTORY ( examples )
+ENDIF ()
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..1bf2417
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,6 @@
+# examples/CMakeLists.txt
+# Forward building to subdirectories if examples are enabled
+
+if(LOG4CPP_BUILD_EXAMPLES)
+ add_subdirectory(cmake_usages)
+endif()
diff --git a/examples/cmake_usages/CMakeLists.txt b/examples/cmake_usages/CMakeLists.txt
new file mode 100644
index 0000000..9066bb2
--- /dev/null
+++ b/examples/cmake_usages/CMakeLists.txt
@@ -0,0 +1,5 @@
+# examples/cmake_usages/CMakeLists.txt
+# Add each subfolder example
+
+add_subdirectory(log4cpp_as_package)
+add_subdirectory(log4cpp_as_subproject)
diff --git a/examples/cmake_usages/log4cpp_as_package/CMakeLists.txt b/examples/cmake_usages/log4cpp_as_package/CMakeLists.txt
new file mode 100644
index 0000000..50cc3f0
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_package/CMakeLists.txt
@@ -0,0 +1,42 @@
+#
+# Note:
+# Example builds two targets, each against either shared or static log4cpp library.
+# If only one of them is available, linking to another one should be removed.
+#
+cmake_minimum_required(VERSION 3.10)
+project(log4cpp_as_package_example LANGUAGES CXX)
+
+# Determine if this example is being built standalone and not being included from top-level CMake as one of examples
+get_directory_property(HAS_PARENT PARENT_DIRECTORY)
+if(NOT HAS_PARENT)
+ set(EXAMPLE_BUILT_ALONE ON)
+else()
+ set(EXAMPLE_BUILT_ALONE OFF)
+endif()
+
+# If built standalone, find the (already) installed log4cpp package
+if(EXAMPLE_BUILT_ALONE)
+ # Find log4cpp installed via CMake export files
+ find_package(log4cpp REQUIRED)
+endif()
+
+# Create executable linked to shared library
+add_executable(log4cpp_as_package_example log4cpp_as_package.cpp)
+# Create executable with static library
+add_executable(log4cpp_as_package_example_static log4cpp_as_package.cpp)
+
+target_compile_features(log4cpp_as_package_example PUBLIC cxx_std_17)
+target_compile_features(log4cpp_as_package_example_static PUBLIC cxx_std_17)
+
+# Link 1st exe against log4cpp shared library
+target_link_libraries(log4cpp_as_package_example PRIVATE log4cpp::log4cpp_shared)
+# Link 2nd exe against log4cpp static library
+target_link_libraries(log4cpp_as_package_example_static PRIVATE log4cpp::log4cpp_static)
+
+# when linking to log4cpp::log4cpp_static, link to threads shared lib too
+find_package(Threads REQUIRED)
+target_link_libraries(log4cpp_as_package_example_static PRIVATE Threads::Threads)
+
+file(COPY ${PROJECT_SOURCE_DIR}/resources
+# DESTINATION ${CMAKE_BINARY_DIR})
+ DESTINATION .)
diff --git a/examples/cmake_usages/log4cpp_as_package/log4cpp_as_package.cpp b/examples/cmake_usages/log4cpp_as_package/log4cpp_as_package.cpp
new file mode 100644
index 0000000..84006a3
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_package/log4cpp_as_package.cpp
@@ -0,0 +1,17 @@
+#include <filesystem>
+#include <log4cpp/Category.hh>
+
+#include "log4cpp/PropertyConfigurator.hh"
+
+// Specify the directory that contains log4cpp’s CMake configuration files when running CMake configuration:
+// cmake <...> -Dlog4cpp_DIR=<log4cpp_installation_path>/lib/cmake/log4cpp
+int main() {
+ std::filesystem::path initFile = std::filesystem::current_path() / "resources" / "log4cpp.properties";
+ std::string initFileName = initFile.string();
+
+ log4cpp::PropertyConfigurator::configure(initFileName);
+ log4cpp::Category &root = log4cpp::Category::getRoot();
+
+ root.info("Hello, log4cpp lib as imported cmake package!");
+ return 0;
+}
diff --git a/examples/cmake_usages/log4cpp_as_package/resources/log4cpp.properties b/examples/cmake_usages/log4cpp_as_package/resources/log4cpp.properties
new file mode 100644
index 0000000..c965d1b
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_package/resources/log4cpp.properties
@@ -0,0 +1,6 @@
+# log4cpp.properties
+
+log4cpp.rootCategory=DEBUG, rootAppender
+log4cpp.appender.rootAppender=ConsoleAppender
+log4cpp.appender.rootAppender.layout=PatternLayout
+log4cpp.appender.rootAppender.layout.ConversionPattern=%d [%p] %m%n
\ No newline at end of file
diff --git a/examples/cmake_usages/log4cpp_as_subproject/CMakeLists.txt b/examples/cmake_usages/log4cpp_as_subproject/CMakeLists.txt
new file mode 100644
index 0000000..b0dd862
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_subproject/CMakeLists.txt
@@ -0,0 +1,50 @@
+#
+# Note:
+# Example builds two targets, each against either shared or static log4cpp library.
+# If only one of them is available, linking to another one should be removed.
+#
+cmake_minimum_required(VERSION 3.10)
+project(log4cpp_as_subproject_example LANGUAGES CXX)
+
+# Ensure shared libraries are built by subprojects
+#set(BUILD_SHARED_LIBS ON CACHE BOOL "")
+
+# Determine if this example is being built standalone and not being included from top-level CMake as one of examples
+get_directory_property(HAS_PARENT PARENT_DIRECTORY)
+if(NOT HAS_PARENT)
+ set(EXAMPLE_BUILT_ALONE ON)
+else()
+ set(EXAMPLE_BUILT_ALONE OFF)
+endif()
+
+# If built standalone, add the project log4cpp as a subproject (subdirectory)
+if(EXAMPLE_BUILT_ALONE)
+ add_subdirectory(../../.. log4cpp-build)
+endif()
+
+# Sanity check: we require shared log4cpp
+#if(NOT TARGET log4cpp::log4cpp_shared)
+# message(FATAL_ERROR "log4cpp::log4cpp_shared target not available")
+#endif()
+
+# Sanity check: we require static log4cpp
+#if(NOT TARGET log4cpp::log4cpp_static)
+# message(FATAL_ERROR "log4cpp::log4cpp_static target not available")
+#endif()
+
+# Create executable linked to shared library
+add_executable(log4cpp_as_subproject_example log4cpp_as_subproject.cpp)
+# Create executable with static library
+add_executable(log4cpp_as_subproject_example_static log4cpp_as_subproject.cpp)
+
+target_compile_features(log4cpp_as_subproject_example PUBLIC cxx_std_17)
+target_compile_features(log4cpp_as_subproject_example_static PUBLIC cxx_std_17)
+
+# Link 1st exe against log4cpp shared library
+target_link_libraries(log4cpp_as_subproject_example PRIVATE log4cpp::log4cpp_shared)
+# Link 2nd exe against log4cpp static library
+target_link_libraries(log4cpp_as_subproject_example_static PRIVATE log4cpp::log4cpp_static)
+
+file(COPY ${PROJECT_SOURCE_DIR}/resources
+ # DESTINATION ${CMAKE_BINARY_DIR})
+ DESTINATION .)
diff --git a/examples/cmake_usages/log4cpp_as_subproject/log4cpp_as_subproject.cpp b/examples/cmake_usages/log4cpp_as_subproject/log4cpp_as_subproject.cpp
new file mode 100644
index 0000000..5cb0ced
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_subproject/log4cpp_as_subproject.cpp
@@ -0,0 +1,17 @@
+#include <filesystem>
+#include <log4cpp/Category.hh>
+
+#include "log4cpp/PropertyConfigurator.hh"
+
+// The log4cpp CMake project is included as a subdirectory,
+// and the entire log4cpp library is built as part of this Cmake project.
+int main() {
+ std::filesystem::path initFile = std::filesystem::current_path() / "resources" / "log4cpp.properties";
+ std::string initFileName = initFile.string();
+
+ log4cpp::PropertyConfigurator::configure(initFileName);
+ log4cpp::Category &root = log4cpp::Category::getRoot();
+
+ root.info("Hello, log4cpp lib as cmake subdirectory!");
+ return 0;
+}
diff --git a/examples/cmake_usages/log4cpp_as_subproject/resources/log4cpp.properties b/examples/cmake_usages/log4cpp_as_subproject/resources/log4cpp.properties
new file mode 100644
index 0000000..c965d1b
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_subproject/resources/log4cpp.properties
@@ -0,0 +1,6 @@
+# log4cpp.properties
+
+log4cpp.rootCategory=DEBUG, rootAppender
+log4cpp.appender.rootAppender=ConsoleAppender
+log4cpp.appender.rootAppender.layout=PatternLayout
+log4cpp.appender.rootAppender.layout.ConversionPattern=%d [%p] %m%n
\ No newline at end of file
http://sourceforge.net/p/log4cpp/codegit/ci/
commit f88cdf00ece1dbe04cd97bf78b614775e72e2e98
Author: Alexander Perepelkin <san...@us...>
Date: Tue Feb 10 16:22:33 2026 +0100
Building examples is enabled via the LOG4CPP_BUILD_EXAMPLES option.
CMake usage examples are provided for both scenarios: importing a CMake-installed log4cpp library and using log4cpp as a CMake subproject.
Both shared and static library variants are demonstrated.
The CMake usage examples can be built either as part of the log4cpp library (when LOG4CPP_BUILD_EXAMPLES is enabled) or as standalone CMake applications that import or include log4cpp from their own directories.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e55761a..18eabeb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@
# Alexander Perepelkin san...@us...
#
# Note:
-# (1) A dummy file include/config.h is required (remnant from configure)
+# (1) A dummy file include/config.h is required (remnant from configure, produced by command ./configure)
# (2) Default installation directory is /usr/local, override with -DCMAKE_INSTALL_PREFIX="" during cmake
# invocation
# (3) Do the usual "make clean all" to build the library
@@ -20,12 +20,20 @@ INCLUDE ( CMakePackageConfigHelpers )
SET ( LOG4CPP_LIBRARY_NAME "log4cpp" )
#SET ( CMAKE_VERBOSE_MAKEFILE ON )
+IF ( CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR )
+ SET ( LOG4CPP_IS_TOP_LEVEL ON )
+ELSE ()
+ SET ( LOG4CPP_IS_TOP_LEVEL OFF )
+ENDIF ()
+
FIND_PACKAGE ( Threads REQUIRED )
IF (NOT CMAKE_BUILD_TYPE)
SET ( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." )
ENDIF ()
+OPTION ( LOG4CPP_BUILD_EXAMPLES "Build log4cpp examples" OFF )
+
# for macOS use var APPLE
IF (WIN32)
SET ( CMAKE_DEBUG_POSTFIX "D" )
@@ -199,3 +207,7 @@ INSTALL (
${CMAKE_CURRENT_BINARY_DIR}/log4cppConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/log4cpp
)
+
+IF ( LOG4CPP_BUILD_EXAMPLES AND LOG4CPP_IS_TOP_LEVEL )
+ ADD_SUBDIRECTORY ( examples )
+ENDIF ()
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..1bf2417
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,6 @@
+# examples/CMakeLists.txt
+# Forward building to subdirectories if examples are enabled
+
+if(LOG4CPP_BUILD_EXAMPLES)
+ add_subdirectory(cmake_usages)
+endif()
diff --git a/examples/cmake_usages/CMakeLists.txt b/examples/cmake_usages/CMakeLists.txt
new file mode 100644
index 0000000..9066bb2
--- /dev/null
+++ b/examples/cmake_usages/CMakeLists.txt
@@ -0,0 +1,5 @@
+# examples/cmake_usages/CMakeLists.txt
+# Add each subfolder example
+
+add_subdirectory(log4cpp_as_package)
+add_subdirectory(log4cpp_as_subproject)
diff --git a/examples/cmake_usages/log4cpp_as_package/CMakeLists.txt b/examples/cmake_usages/log4cpp_as_package/CMakeLists.txt
new file mode 100644
index 0000000..50cc3f0
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_package/CMakeLists.txt
@@ -0,0 +1,42 @@
+#
+# Note:
+# Example builds two targets, each against either shared or static log4cpp library.
+# If only one of them is available, linking to another one should be removed.
+#
+cmake_minimum_required(VERSION 3.10)
+project(log4cpp_as_package_example LANGUAGES CXX)
+
+# Determine if this example is being built standalone and not being included from top-level CMake as one of examples
+get_directory_property(HAS_PARENT PARENT_DIRECTORY)
+if(NOT HAS_PARENT)
+ set(EXAMPLE_BUILT_ALONE ON)
+else()
+ set(EXAMPLE_BUILT_ALONE OFF)
+endif()
+
+# If built standalone, find the (already) installed log4cpp package
+if(EXAMPLE_BUILT_ALONE)
+ # Find log4cpp installed via CMake export files
+ find_package(log4cpp REQUIRED)
+endif()
+
+# Create executable linked to shared library
+add_executable(log4cpp_as_package_example log4cpp_as_package.cpp)
+# Create executable with static library
+add_executable(log4cpp_as_package_example_static log4cpp_as_package.cpp)
+
+target_compile_features(log4cpp_as_package_example PUBLIC cxx_std_17)
+target_compile_features(log4cpp_as_package_example_static PUBLIC cxx_std_17)
+
+# Link 1st exe against log4cpp shared library
+target_link_libraries(log4cpp_as_package_example PRIVATE log4cpp::log4cpp_shared)
+# Link 2nd exe against log4cpp static library
+target_link_libraries(log4cpp_as_package_example_static PRIVATE log4cpp::log4cpp_static)
+
+# when linking to log4cpp::log4cpp_static, link to threads shared lib too
+find_package(Threads REQUIRED)
+target_link_libraries(log4cpp_as_package_example_static PRIVATE Threads::Threads)
+
+file(COPY ${PROJECT_SOURCE_DIR}/resources
+# DESTINATION ${CMAKE_BINARY_DIR})
+ DESTINATION .)
diff --git a/examples/cmake_usages/log4cpp_as_package/log4cpp_as_package.cpp b/examples/cmake_usages/log4cpp_as_package/log4cpp_as_package.cpp
new file mode 100644
index 0000000..84006a3
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_package/log4cpp_as_package.cpp
@@ -0,0 +1,17 @@
+#include <filesystem>
+#include <log4cpp/Category.hh>
+
+#include "log4cpp/PropertyConfigurator.hh"
+
+// Specify the directory that contains log4cpp’s CMake configuration files when running CMake configuration:
+// cmake <...> -Dlog4cpp_DIR=<log4cpp_installation_path>/lib/cmake/log4cpp
+int main() {
+ std::filesystem::path initFile = std::filesystem::current_path() / "resources" / "log4cpp.properties";
+ std::string initFileName = initFile.string();
+
+ log4cpp::PropertyConfigurator::configure(initFileName);
+ log4cpp::Category &root = log4cpp::Category::getRoot();
+
+ root.info("Hello, log4cpp lib as imported cmake package!");
+ return 0;
+}
diff --git a/examples/cmake_usages/log4cpp_as_package/resources/log4cpp.properties b/examples/cmake_usages/log4cpp_as_package/resources/log4cpp.properties
new file mode 100644
index 0000000..c965d1b
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_package/resources/log4cpp.properties
@@ -0,0 +1,6 @@
+# log4cpp.properties
+
+log4cpp.rootCategory=DEBUG, rootAppender
+log4cpp.appender.rootAppender=ConsoleAppender
+log4cpp.appender.rootAppender.layout=PatternLayout
+log4cpp.appender.rootAppender.layout.ConversionPattern=%d [%p] %m%n
\ No newline at end of file
diff --git a/examples/cmake_usages/log4cpp_as_subproject/CMakeLists.txt b/examples/cmake_usages/log4cpp_as_subproject/CMakeLists.txt
new file mode 100644
index 0000000..b0dd862
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_subproject/CMakeLists.txt
@@ -0,0 +1,50 @@
+#
+# Note:
+# Example builds two targets, each against either shared or static log4cpp library.
+# If only one of them is available, linking to another one should be removed.
+#
+cmake_minimum_required(VERSION 3.10)
+project(log4cpp_as_subproject_example LANGUAGES CXX)
+
+# Ensure shared libraries are built by subprojects
+#set(BUILD_SHARED_LIBS ON CACHE BOOL "")
+
+# Determine if this example is being built standalone and not being included from top-level CMake as one of examples
+get_directory_property(HAS_PARENT PARENT_DIRECTORY)
+if(NOT HAS_PARENT)
+ set(EXAMPLE_BUILT_ALONE ON)
+else()
+ set(EXAMPLE_BUILT_ALONE OFF)
+endif()
+
+# If built standalone, add the project log4cpp as a subproject (subdirectory)
+if(EXAMPLE_BUILT_ALONE)
+ add_subdirectory(../../.. log4cpp-build)
+endif()
+
+# Sanity check: we require shared log4cpp
+#if(NOT TARGET log4cpp::log4cpp_shared)
+# message(FATAL_ERROR "log4cpp::log4cpp_shared target not available")
+#endif()
+
+# Sanity check: we require static log4cpp
+#if(NOT TARGET log4cpp::log4cpp_static)
+# message(FATAL_ERROR "log4cpp::log4cpp_static target not available")
+#endif()
+
+# Create executable linked to shared library
+add_executable(log4cpp_as_subproject_example log4cpp_as_subproject.cpp)
+# Create executable with static library
+add_executable(log4cpp_as_subproject_example_static log4cpp_as_subproject.cpp)
+
+target_compile_features(log4cpp_as_subproject_example PUBLIC cxx_std_17)
+target_compile_features(log4cpp_as_subproject_example_static PUBLIC cxx_std_17)
+
+# Link 1st exe against log4cpp shared library
+target_link_libraries(log4cpp_as_subproject_example PRIVATE log4cpp::log4cpp_shared)
+# Link 2nd exe against log4cpp static library
+target_link_libraries(log4cpp_as_subproject_example_static PRIVATE log4cpp::log4cpp_static)
+
+file(COPY ${PROJECT_SOURCE_DIR}/resources
+ # DESTINATION ${CMAKE_BINARY_DIR})
+ DESTINATION .)
diff --git a/examples/cmake_usages/log4cpp_as_subproject/log4cpp_as_subproject.cpp b/examples/cmake_usages/log4cpp_as_subproject/log4cpp_as_subproject.cpp
new file mode 100644
index 0000000..5cb0ced
--- /dev/null
+++ b/examples/cmake_usages/log4cpp_as_subproject/log4cpp_as_subproject.cpp
@@ -0,0 +1,17 @@
+#include <filesystem>
+#include <log4cpp/Category.hh>
+
+#include "log4cpp/PropertyConfigurator.hh"
+
+// The log4cpp CMake project is included as a subdirectory,
+// and the entire log4cpp library is built as part of this Cmake project.
+int main() {
+ std::filesystem::path initFile = std::filesystem::current_path() / "resources" / "log4cpp.properties";
+ std::string initFileName = initFile.string();
+
+ log4cpp::PropertyConfigurator::configure(initFileName);
... 550 lines suppressed ...
hooks/post-receive
--
Log4cpp Git repository.
|