The POCO C++ Libraries use a built system based on
[[http://www.gnu.org/software/make/ GNU Make]] on every platform
capable of running it. This includes Linux, Mac OS X, virtually
every other Unix platform, as well as Cygwin and MinGW on Windows.
Why GNU Make? Well, GNU Make is available virtually everywhere
and it's usually readily available, such as on Linux and Mac OS X.
Sure, there are more advanced build systems out there, but the
philisophy for POCO is download -- compile -- go. Requiring the user
to download and install another build tool just for getting
POCO to work is unacceptable.
The build system consists of a number of make files, as well as a few
supporting shell scripts. All core files are located within the <*build*>
directory in the POCO distribution. For every library and executable,
there is a small make file describing the kind of project,
its input files, and the output.
The POCO build system automatically determines the dependencies
between source and header files. This is done when a source file is
compiled for the first time, or after a source file has been changed.
This relieves the developer from the tedious task of maintining file
dependencies manually - one of the biggest drawbacks of GNU Make.
!!Build System Features
The POCO build system supports the following features:
* building libraries, applications and plugins
* debug and release builds
* dynamic and static linking
* 32-bit and 64-bit builds
* automatic dependency detection
* easy to use
* support for cross-compiling for embedded platforms
such as Embedded Linux or iOS
!!Build System Overview
The core of the build system consists of three different kinds of files --
platform configuration files, make rules and shell scripts. All are located
in the <*build*> directory within the POCO C++ Libraries root directory.
build/
config/
Darwin
Linux
HP-UX
...
rules/
compile
dylib
exec
global
lib
script/
makedepend.gcc
makedepend.cxx
makedepend.SunCC
makeldpath
projname
shlibln
...
----
!Configuration Files
Configuration files contain all the knowledge how the toolchain (compiler and linker)
must be invoked for a given platform. Configuration files for the most common
Unix platforms and their toolchains, as well as for Cygwin and MinGW are already
part of POCO.
Support for an additional platform (or a variation of a platform) can be added
by creating a new (or copying and modifying) an existing build configuration file.
Configuration files are located in the <*build/config*> directory.
!Rule Files
Rule files contain platform independent make rules for compiling and
linking executables or (static and shared) libraries from source files,
using the tools defined in a configuration file. Rule files are located
in the <*build/rules*> directory.
!Script Files
Script files are called by the build system's make files to do things that
cannot be expressed in make files. For example, there are scripts for
invoking a particular C++ compiler in such a way that it produces a list of
dependencies for later inclusion by the build system. Script files are
located in the <*build/script*> directory.
!!Filesystem Layout
!Sources
The build system expects a project's files (header files, source files, Makefiles)
to be in a certain directory layout.
First, all project directories must be located in or under the same directory where the
<*build*> directory is located, or in a directory below.
All header files must be in the <*include*> directory (or a subdirectory of it).
All source files must be in the <*src*> directory.
Finally, there must be a Makefile (named <*Makefile*>) located in the project directory.
Below is a sample for a POCO source directory hierarchy:
poco/
build/
Foundation/
Net/
Util/
XML/
...
MyLib/
include/
MyLib.h
MyClass.h
src/
MyClass.cpp
Makefile
----
!Build Products
The POCO build system puts final build products (executables and libraries)
and intermediate products (object files, dependency files) into certain directories.
Unless specified otherwise (by setting the environment variable
POCO_BUILD accordingly -- see below), these directories are located within
the source directory tree. All libraries are put into a
directory with the path <*lib/<OSNAME>/<OSARCH>*>, within the POCO base directory.
Executables are put into a directory with the path <*bin/<OSNAME>/<OSARCH>*>,
within the project directory. Object files are put into a directory with the
path <*obj/<OSNAME>/<OSARCH>*>, within the project directory.
Dependency files are put into <*.dep/<OSNAME>/<OSARCH>*>,
also within the project directory.
Unless specified otherwise (by setting the Makefile variables
<[$(POCO_TARGET_OSNAME)]> and <[$(POCO_TARGET_OSARCH)]>, <*<OSNAME>*> is the
name of the host's operating system, as obtained by a call to
<*uname*> (or something equivalent), and <*<OSARCH>*> is the name of the
host's hardware architecture, as obtained by a call to <*uname -m*>
(or something equivalent).
Taking into account the build products, a typical project hierarchy looks like this:
poco/
build/
lib/
Linux/
i686/
libCppUnit.so.1
libCppUnitd.so.1
libCppUnit.so
libCppUnitd.so
libPocoFouncation.so.1
...
Foundation/
...
testsuite/
...
bin/
Linux/
i686/
testrunner
testrunnerd
...
Net/
Util/
XML/
...
MyLib/
.dep/
Linux/
i686/
MyClass.d
obj/
Linux/
i686/
MyClass.o
include/
MyLib.h
MyClass.h
src/
MyClass.cpp
Makefile
----
!!Project Makefiles
Depending on the kind of project, a project Makefile comes in one of three variants.
!Library Makefiles
The Makefile for a library always looks like this:
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyLib
target_version = 1
target_libs = PocoFoundation ...
include $(POCO_BASE)/build/rules/lib
----
Every Makefile always has to include <*$(POCO_BASE)/build/rules/global*> first.
In the <*objects*> section, the source files (located in the <*src*> directory)
must be specified. The file extension must not be included; the build system
will find files ending in .cpp (C++ sources) and .c (C sources).
<*target*> specifies the name of the library, <*target_version*> specifies the
version number for the shared library. <*target_libs*> specifies the
libraries required for linking the library.
Last in the Makefile is the inclusion of <*$(POCO_BASE)/build/rules/lib*>,
which includes the rules for building a shared or static library.
!Executable Makefiles
Makefiles for executables look similar to the ones for libraries.
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyLib
target_libs = PocoFoundation ...
include $(POCO_BASE)/build/rules/exec
----
The only differences are the missing <*target_version*> entry, and the
<*$(POCO_BASE)/build/rules/exec*> file, which is included instead of
<*$(POCO_BASE)/build/rules/lib*> at the end of the Makefile.
!Plugin Makefiles
Makefiles for plugins - shared libraries that are loadable dynamically at runtime - again look almost the same as Makefiles for ordinary libraries or executables.
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyPlugin
target_libs = PocoFoundation ...
include $(POCO_BASE)/build/rules/dylib
----
The difference is the file that is included at the end of the Makefile:
<*$(POCO_BASE)/build/rules/dylib*>.
!!!Build System Reference
!!Postbuild Command
A Makefile can contain a so-called postbuild command -- a shell command
that will be executed when the target has been built successfully.
To specify a postbuild command, define the variable <*postbuild*>
in your Makefile, e.g.
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyLib
target_libs = PocoFoundation ...
postbuild = echo "The build is done."
include $(POCO_BASE)/build/rules/exec
----
!!Make Targets
Independently of which kind of product (library, executable, plugin) is
being built, there are always five make targets available:
If a new library is being added to POCO, a corresponding entry should be made in the <*components*> file, so that the compiler can find its header files.
!libversion
The content of the file <*libversion*>, located in <*$(POCO_BASE)*>,
will be stored in the variable <*$(LIBVERSION)*>. This variable can be used
in a Makefile as the value for the <*target_version*> variable.
!Configuring the Build Process
The build process is configured by build configuration files,
located in the <*build/config*> directory.
Unless specified otherwise, by setting the <*POCO_CONFIG*>
environment variable accordingly, the build system selects the
build configuration file with the same name as the host's
operating system (output of <*uname*>). If you need support for a
new operating system, or just need to customize an existing configuration,
you'll usually create a new build configuration file (by copying an existing one).
A typical build configuration file looks like this:
<*SHAREDOPT_CXX*> specifies additonal flags passed to the C++ compiler if
compiling for dynamic linking.
!SHAREDOPT_LINK
<*SHAREDOPT_LINK*> specifies additonal flags passed to the linker for dynamic linking.
!DEBUGOPT_CC
<*DEBUGOPT_CC*> specifies additional flags passed to the C compiler if compiling in debug mode.
!DEBUGOPT_CXX
<*DEBUGOPT_CXX*> specifies additional flags passed to the C++ compiler if compiling in debug mode.
!DEBUGOPT_LINK
<*DEBUGOPT_LINK*> specifies additional flags passed to the linker if linking in debug mode.
!RELEASEOPT_CC
<*RELEASEOPT_CC*> specifies additional flags passed to the C compiler if compiling in release mode.
!RELEASEOPT_CXX
<*RELEASEOPT_CXX*> specifies additional flags passed to the C++ compiler if compiling in release mode.
!RELEASEOPT_LINK
<*RELEASEOPT_LINK*> specifies additional flags passed to the linker if linking in release mode.
!!System Specific Flags
!SYSFLAGS
<*SYSFLAGS*> specifies flags passed to both the C and C++ compiler. This usually contains system-specific include paths and settings such as -D_XOPEN_SOURCE=500 or -D_THREAD_SAFE.
!SYSLIBS
<*SYSLIBS*> specifies flags passed to the linker. Usually, this flags specify system-specific libraries, such as -lpthread or -ldl.