For building on any platform with any supported build
system Xerces-C++ uses the CMake build generator and
requires that you have CMake installed.
Additionally, a build tool such as GNU
make or Ninja is required for
building. CMake supports a wide range of generators for
several different compilers, build tools and popular IDEs,
including Eclipse, Kate, Visual Studio, Sublime Text and more.
Any of these may be used to build Xerces-C++. Run
cmake --help
to display the full list of
supported generators for your platform.
As with all CMake projects, the build process is divided
into several parts: configuration and building, followed by
(optional) testing and installation. The configuration part is
performed by running the cmake
command. The
build part is performed by invoking the chosen build tool
such as make
or ninja
, or by opening
the generated project files in your IDE, and building from
within the IDE.
Besides the standard cmake
variables,
Xerces-C++ provides a number of project-specific options
that are worth mentioning. You can specify one option for each
category outlined below. If you do not specify anything for a
particular category then cmake
will select the
most appropriate default, based upon the available options for
your system. At the end of its execution cmake
prints the selected values for each category.
Net Accessor (used to access network resources):
Option
|
Description
|
-Dnetwork-accessor=curl
|
use the libcurl library (only on UNIX)
|
-Dnetwork-accessor=socket
|
use plain sockets (only on UNIX)
|
-Dnetwork-accessor=cfurl
|
use the CFURL API (only on Mac OS X)
|
-Dnetwork-accessor=winsock
|
use WinSock (only on Windows, Cygwin, MinGW)
|
-Dnetwork:BOOL=OFF
|
disable network support
|
Transcoder (used to convert between internal UTF-16 and other encodings):
Option
|
Description
|
-Dtranscoder=gnuiconv
|
use the GNU iconv library
|
-Dtranscoder=iconv
|
use the iconv library
|
-Dtranscoder=icu
|
use the ICU library
|
-Dtranscoder=macosunicodeconverter
|
use Mac OS X APIs (only on Mac OS X)
|
-Dtranscoder=windows
|
use Windows APIs (only on Windows and MinGW)
|
Message Loader (used to access diagnostics messages):
Option
|
Description
|
-Dmessage-loader=inmemory
|
store the messages in memory
|
-Dmessage-loader=icu
|
store the messages using the ICU resource bundles
|
-Dmessage-loader=iconv
|
store the messages in the iconv message catalog
|
Thread support is enabled by default and can be disabled
with the -Dthreads:BOOL=OFF
option. If disabled,
it will not be possible to select a mutex manager other than
nothreads
.
Shared libraries are built by default. You can use the
-DBUILD_SHARED_LIBS:BOOL=OFF
option to build
static libraries.
If you need to specify compiler executables that should be
used to build Xerces-C++, you can set the CC and CXX
environment variables when invoking
cmake
. Similarly, if you need to specify
additional compiler or linker options, you can set the
CFLAGS, CXXFLAGS, and LDFLAGS environment variables. For
example:
| | |
| CC=gcc-5.3 CXX=g++-5.3 CFLAGS=-O3 CXXFLAGS=-O3 cmake ... | |
| | |
|
If building on Windows, the specific Visual Studio version
may be selected with some generators, and this may be run
from a normal command prompt. If using a generic generator
such as Ninja , then cmake should
be run from a Visual Studio command prompt, or in a
suitably configured environment, so that the correct
compiler will be detected.
|
Once the configuration part is complete you can run the
build tool of choice. This may be done generically using
cmake --build . [--config=Debug|Release]
.
Alternatively, a specific build tool, e.g. make
,
gmake
, ninja
or
msbuild
corresponding to the chosen generator
may be used directly. When invoked without a specific
target, it will build the Xerces-C++ library, all examples
and all unit tests.
If you would like to run the automated test suite, run
ctest [-V] [-C Debug|Release]
. This will run
all tests. Additional options
are available, such as running a subset of the tests and
running the tests in parallel. If any discrepancies in the
output are detected, the differences will be displayed if a
diff
program is available.
Finally, install the library and examples. This may be
done generically using cmake --build . --target
install
. Alternatively, a specific build tool may be
used, e.g. make install
. To change the
installation directory, use the
-DCMAKE_INSTALL_PREFIX=prefix
cmake
option.
Some platforms and configurations may require extra
cmake
options. Run cmake -LH
to
list the additional options, along with a short description
for each. For each of the selection categories mentioned
above, the help text will list the valid choices detected for
your platform. Run cmake -LAH
for all the
additional advanced settings.
Several examples of configuring, building, testing and
installing with CMake using different platforms, generators,
and installation options are shown below:
Platform
|
Generator
|
Example
|
Any
|
Ninja
|
mkdir build
cd build
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/opt/xerces-c -DCMAKE_BUILD_TYPE=Release -Dnetwork-accessor=curl /path/to/xerces-c/source
ninja
ctest -V -j 8
ninja install
|
Unix
|
Unix Makefiles
|
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/xerces-c -DCMAKE_BUILD_TYPE=Debug -Dmessage-loader=icu /path/to/xerces-c/source
make -j8
make test
make install
|
Windows
|
msbuild with VS2015 x64
|
mkdir build
cd build
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=D:\libs \path\to\xerces-c\source
cmake --build . --config Debug
ctest -V -C Debug -j 4
cmake --build . --config Debug --target install
|
|
Note that different UNIX platforms use different system
environment variables for finding shared libraries. On Linux
and Solaris, the environment variable name is
LD_LIBRARY_PATH , on AIX it is
LIBPATH , on Mac OS X it is
DYLD_FALLBACK_LIBRARY_PATH , and on HP-UX it is
SHLIB_PATH .
|
|
Note that Windows is different from the UNIX platforms in
the way it finds shared libraries at run time. While UNIX
platforms may use the LD_LIBRARY_PATH
environment variable, Windows uses the PATH
environment variable if the library is not in the same
directory as the executable.
|