Building Apache log4cxx with Apache Ant

Apache Ant with cpptasks from the Ant-Contrib project can be used to build log4cxx with supported compilers and is also used to generate the IDE project files included in the releases. The Apache Maven build which is used to generate the site documentation and release packaging delegates to this build. The Ant build can build APR and APR-Util if source is available.

Quick start:

  • Install Apache Ant 1.6.5 or later.
  • Install cpptasks 1.0b5 or later from the Ant-Contrib Project. ant-contribs 1.0b3 or later is needed for some less frequent build targets.
  • Install APR and APR-Util or place source in apr and apr-util directories as a sibling to the log4cxx directory.
  • Install gzip and zip (used for compression by RollingFileAppender) and sed (used to normalize output files for comparison in unit tests).
  • Install log4j 1.2. Used in testing of SocketAppender.

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

    $ export CLASSPATH=~/cpptasks/cpptasks-1.0b5.jar
    $ cd apache-log4cxx-0.10.0
    $ ant

    Building and testing log4cxx on a Unix platform with APR and APR-Util built from source.

    $ export CLASSPATH=~/cpptasks/cpptasks-1.0b5.jar
    $ tar -xvzf apr-1.2.12.tar.gz
    $ mv apr-1.2.12 apr
    $ tar -xvzf apr-util-1.2.12.tar.gz
    $ mv apr-util-1.2.12 apr-util
    $ cd apache-log4cxx-0.10.0
    $ ant

    Building and testing log4cxx on a Microsoft Windows with APR and APR-Util built from source.

    set PATH=\apache-ant-1.7.0\bin;%PATH%
    set CLASSPATH=\cpptasks\cpptasks-1.0b5.jar
    tar -xvzf apr-1.2.12.tar.gz
    rename apr-1.2.12 apr
    tar -xvzf apr-util-1.2.12.tar.gz
    rename apr-util-1.2.12 apr-util
    cd apache-log4cxx-0.10.0
    ant -Dfind=false

Common ant targets

buildbuild log4cxx library.
checkbuild logcxx library and build and run unit tests and examples.
cleanDelete all generated files.
build-unittestbuild log4cxx library and unit test.
run-socketserverTests SocketAppender with Java-based receiver.
build-projects-vc6Build Microsoft Visual Studio 6 project files.
build-projects-vc7Build Microsoft Visual Studio .NET project files.
build-projects-vc8Build Microsoft Visual Studio 2005 project files.
build-projects-vc9Build Microsoft Visual Studio 2008 project files.
build-projects-xcodeBuild Apple Xcode project files.

All build products will be placed in the target subdirectory.

Project files should be generated after successfully building the library, however it is possible to generate Microsoft Visual Studio project files on other platforms. The project files will typically be missing references to the Platform SDK libraries. The Maven project modifies the generated project files for release preparation. Generation of Xcode projects from Microsoft Windows is not supported.

ant options

-DcompilerCompiler, see cpptasks documentation for full list.
-DdebugBuild for debugging, yes (default), no.
-DfindAttempt to locate compiled APR and APR-Util, yes (default), no.
-Dwith-aprpath to non-default location for APR.
-Dwith-apr-utilpath to non-default location for APR-Util.
-Denable-wchar_tEnable wchar_t API methods, choice of yes (default), no.
-Denable-unicharEnable UniChar API methods, choice of yes, no (default).
-Denable-cfstringEnable CFString API methods, requires Mac OS/X CoreFoundation, choice of yes, no (default).
-Dwith-logcharInteral character representation, choice of utf-8 (default), wchar_t , unichar.
-Dwith-charsetExteral character encoding, choice of utf-8, iso-8859-1, usascii, ebcdic, auto (default).
-Dwith-SMTPSMTP implementation for SMTPAppender, choice of libesmtp, no (default).
-Dwith-ODBCOBDC implementation for ODBCAppender, choice of unixODBC, iODBC, Microsoft, no (default).
-Dlog4j.jarPath to log4j.jar for run-socketserver.
-Dprojects.dirLocation for generated IDE projects.
-Dlib.typeLibrary type to create, choice of shared (default), static.
-DruntimeType of C runtime library to use, choice of dynamic (default), static.
-DoptimizationOptimization: none (default), size, minimal, speed, full, aggressive, extreme, unsafe.
-pDisplay available targets and quit.

SMTP and ODBC options can depend on libraries that that have different licenses. You should review the corresponding licenses and understand the implications before redistribution.

Combining -Dlib.type=shared and -Druntime=static is unsafe.

Properties may also be placed in a build.properties file in the log4cxx directory.

Platform specific notes:

  • Microsoft Windows

    GnuWin32 provides binary versions of sed, gzip and zip. Alternative, the bin directory of Cygwin may be placed on the path.

    If -Dwith-SMTP=libesmtp is specified, the build will attempt to build libesmtp from source, unfortunately libesmtp depends on poll.h and will not build.

    APR 1.2.12 has a known issue that will prevent compilation with Visual Studio 6 unless a later Platform SDK is installed. See APR bug 44327. APR 1.2.11 and the corresponding APR-Util 1.2.10 will compile with Visual Studio 6.

  • Cygwin:

    gcc 3.x does not provide wchar_t support which needs to be explicitly disabled. The Win32 path to the APR libraries need to be provided (CYGWIN_HOME/lib) if compiling against an installed APR and APR-Util.

    $ cd apache-log4cxx-0.10.0
    $ ant -Dos.family=cygwin \
       -Dwith-apr=/cygwin/lib \
       -Dwith-apr-util=/cygwin/lib \
       -Denable-wchar_t=0
  • MinGW:
    $ cd apache-log4cxx-0.10.0
    $ path c:\mingw\bin;%PATH%
    $ ant -Dcompiler=gcc -Dfind=false build-all
    $ cd src\test\resources
    $ set TOTO=wonderful
    $ set key1=value1
    $ set key2=value2
    $ ..\..\..\target\debug\shared\testsuite -v 
    $ ..\..\..\target\debug\shared\trivial
    $ ..\..\..\target\debug\shared\stream 

    Running "ant check" was observed to fail with unexpected exceptions in streamtestcase and datetimedateformattestcase. See LOGCXX-244.

  • Debian:

    Apache APR, APR-Util, Ant and log4j and zip may be installed using:

    $ sudo apt-get install libapr1.0-dev libaprutil1.0-dev \
          ant ant-optional liblog4j1.2-java zip
  • Mac OS/X:

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

    Site generation requires "doxygen" command on path which can be provided by installing Doxygen.app and then setting the path like:

    $ setenv PATH /Applications/Doxygen.app/Contents/Resources:$PATH