Apache logging services logo Apache log4j logo

Building Apache log4cxx with CMake

Quick start:

Building and testing log4cxx on a Unix platform with packaged APR and APR-Util.

Make sure cmake 3.13+, g++ and make are available, install or build apr 1.x, apr-util 1.x, gzip and zip.

  1. $ apt-get install build-essential libapr1-dev libaprutil1-dev gzip zip
  2. $ cd apache-log4cxx-x.x.x
  3. $ mkdir build
  4. $ cd build
  5. $ ccmake ..
  6. $ make
  7. $ sudo make install

ccmake options

-DLOG4CXX_WCHAR_T=no Enable wchar_t API methods, choice of yes (default), no.
-DLOG4CXX_UNICHAR=yes Enable UniChar API methods, choice of yes, no (default).
-DLOG4CXX_CFSTRING=yes Enable CFString API methods, requires Mac OS/X CoreFoundation, choice of yes, no (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 extracted into apr-1.7.0, libexpat(from github) and apr-util-1.6.1 in %HOMEPATH%\Libraries.

  1. $ cd %HOMEPATH%\Libraries
  2. $ cmake -S libexpat\expat -B buildtrees\expat -DCMAKE_INSTALL_PREFIX=%HOMEPATH%\Libraries\installed
  3. $ cmake --build buildtrees\expat --target install --config Release
  4. $ cmake -S apr-1.7.0 -B buildtrees\apr -DCMAKE_INSTALL_PREFIX=%HOMEPATH%\Libraries\installed
  5. $ cmake --build buildtrees\apr --target install --config Release
  6. $ set CMAKE_PREFIX_PATH=%HOMEPATH%\Libraries\installed
  7. $ cmake -S apr-util-1.6.1 -B buildtrees\apr-util -DCMAKE_INSTALL_PREFIX=%HOMEPATH%\Libraries\installed
  8. $ cmake --build buildtrees\apr-util --target install --config Release
  9. $ cmake -S apache-log4cxx-x.x.x -B buildtrees\log4cxx -DCMAKE_INSTALL_PREFIX=%HOMEPATH%\Libraries\installed
  10. $ cmake --build buildtrees\log4cxx --target install --config Release

Platform specific notes:

Mac OS/X:

APR and APR-Util are provided by the platform in Mac OS/X 10.5 and iODBC in 10.4.

cmake can be installed by typing "brew install cmake".

Debian:

APR, APR-Util, openssl, gzip and zip may be installed by:

  1. $ sudo apt-get install libssl-dev libapr1-dev libaprutil1-dev gzip zip

CMake can be built from source by typing:

  1. $ wget https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4.tar.gz
  2. $ tar xf cmake-3.16.4.tar.gz
  3. $ cd cmake-3.16.4
  4. $ ./bootstrap
  5. $ make
  6. $ sudo make install

FreeBSD:

APR, APR-Util, gzip and zip may be installed from the ports collection by:

  1. $ cd /usr/ports/archivers/zip
  2. $ make
  3. $ make install
  4. $ cd /usr/ports/archivers/gzip
  5. $ make
  6. $ make install
  7. $ cd /usr/ports/devel/apr
  8. $ make
  9. $ 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.

  1. find_package(log4cxx 0.11)
  2. add_executable(myApplication myMain.cpp)
  3. target_include_directories(myApplication PRIVATE $<TARGET_PROPERTY:log4cxx,INTERFACE_INCLUDE_DIRECTORIES>)
  4. target_link_libraries( myApplication PRIVATE log4cxx)