This package offers files to help build log4cxx from the source files found on Apache's website, with Windows environment in mind, and more specifically Visual Studio.
It consists in of 3 separates elements:
- a set of scripts to configure and patch the code,
- a ready-to-use solution for Visual Studio 2015,
- a CMake file that can be used to build with other version of Visual Studio or even other environments.
For the scripts to work, you need to have sed installed and the sed.exe repository added to your PATH. If sed is not installed or if something is not working properly, you can make the required actions by hand (see explanations below).
-
Clone or download this project. We will call <rootDir> the corresponding directory.
-
Download the following sources:
- apr (website, source zip)
- apr-util (website, source zip)
- log4cxx (website, source zip)
-
unzip them in <rootDir> and rename the folders apr, apr-util and log4cxx, respectively.
Your working directory should be organized as follow:<rootDir> |-- <apr> |-- <apr-util> |-- <cmake> |-- <log4cxx> |-- <msvc15> |-- <patch> |-- readme.md
-
In <patch>, execute configure.bat
You can now use either the Visual Studio 2015 solution in <msvc15> or CMake with the CMakeLists.txt in <cmake>
We explain the work done by the scripts and give a step by step details.
There are two aspects to the scripts:
- copying a bunch of headers or replacing values in them, to configure the code for (modern) Windows systems,
- patching the log4cxx code to work with with recent Visual Studio version. In particular, C++11 capable compilers are not happy with some default constructors and destructors.
Here are the steps performed by patch/configure.bat:
-
go to rootDir/log4cxx
-
execute configure.bat
-
execute configure-aprutil.bat
- in rootDir/apr-util/include/apu.hw, look for the line
#define APU_HAVE_APR_ICONV
and set the value to 0 - in rootDir/apr-util/include/apr_ldap.hw, look for the line
#define APR_HAS_LDAP
and set the value to 0
- in rootDir/apr-util/include/apu.hw, look for the line
-
apply rootDir/buildVS/patch.bat
- in rootDir/log4cxx/src/main/cpp/stringhelper.cpp, add
#include<iterator>
in the include section - in rootDir/log4cxx/src/main/include/log4cxx/helpers/objectimpl.h, add the following macros after the include section:
#define DELETED_CTORS(T) \ T(const T&) = delete;\ T& operator=(const T&) = delete;
#define DEFAULTED_AND_DELETED_CTORS(T) \ T() = default;\ T(const T&) = delete;\ T& operator=(const T&) = delete;
- in rootDir/log4cxx/src/main/include/log4cxx/pattern/patternconverter.h, add
DEFAULTED_AND_DELETED_CTORS(PatternConverter)
afterEND_LOG4CXX_CAST_MAP()
- in rootDir/log4cxx/src/main/include/log4cxx/rolling/RollingPolicyBase.h, add
DELETED_CTORS(RollingPolicyBase)
abovevirtual ~RollingPolicyBase();
- in rootDir/log4cxx/src/main/include/log4cxx/rolling/TriggeringPolicy.h, add
DEFAULTED_AND_DELETED_CTORS(TriggeringPolicy)
abovevirtual ~TriggeringPolicy();
- in rootDir/log4cxx/src/main/include/log4cxx/spi/Filter.h, add
DELETED_CTORS(Filter)
afterFilter();
- in rootDir/log4cxx/src/main/include/log4cxx/Layout.h, add
DEFAULTED_AND_DELETED_CTORS(Layout)
abovevirtual ~Layout();
- in rootDir/log4cxx/src/main/include/log4cxx/log4cxx.h, add
&& _MSC_VER < 1600
to the two tests#if defined(_MSC_VER) && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)
and#elif defined(_MSC_VER) && !defined(LOG4CXX_STATIC)
- in rootDir/log4cxx/src/main/cpp/stringhelper.cpp, add
-
(optional) remove the temporary files possibly generated by sed (name such as sedAbCDef) in rootDir/log4cxx and rootDir/buildVS.
The solution automatically converted from the .dsw found in the log4cxx source package was not usable. The solution proposed here is a clean one built from scratch, using the automatically converted one as a guide.
log4cxx.dll will be located in buildVS/bin/plateform/configuration while apr.lib, xml.lib and apr-util.lib will be found in buildVS/lib/plateform/configuration
The CMakeLists.txt file was initially built to generate a Visual Studio solution very close to the one mentionned above. The idea is to have a cmake base that can be reused for different compilers/systems.
Because of its history (.dsw -> .sln -> cmake and configure.bat), it is certainly not the optimal way to use CMake for this project. In particular:
- at least part of the configuration/patch steps could be done in CMake,
- we are not using the existing CMakeLists for apr and apr-util (which are more complete, but also more complex, with options not available through the original configure+.dsw).
The content of this project was tested on Windows 7 with
- apr 1.5.2
- apr-util 1.5.4
- log4cxx 0.10.0
- Visual Studio Community 2015 (Update 1 and 2)
- CMake 3.2.3
A starting point for this work was this blog's post on how to build log4cxx with Visual Studio 10.