# Cmake to generate projects files or makefile.

You start with downloading and installing Cmake http:://www.cmake.org

- On Windows
- On Unix alikes
- My Own Application
- Cpack for making distribution

## On windows

On windows call the program CmakeSetup.exe, distributed with Cmake.
This has a graphical interface used to generate your project files or makefiles.
Asumming Agg is installed at C:\agg\agg-2.4
In CmakeSetup.exe choose:
Where is the source code: C:\agg\agg-2.4
Where to build the binaries: C:\agg\agg-2.4_Build
The options:

- agg_USE_EXPAT

- At http://expat.sourceforge.net/
- you will find expat-win32bin-2.0.1.exe
- This will add a key to your registry, which is searched for by Cmake, if not oke, use next step.
- Do set EXPAT_DIR in your environment to the location where you installed the above.

- agg_USE_FREETYPE

- Get the library + headers from: http://gnuwin32.sourceforge.net/packages/freetype.htm
- tested with the download called: "Complete package, except sources"
- This will add a key to your registry, which is searched for by Cmake, if not oke, use next step.
- Do set FREETYPE_DIR in your environment to the location where you installed the above.

- agg_USE_GPC

- Internal files, but GPL, so an option.

- agg_USE_SDL_PLATFORM

- Todo

- agg_USE_PACK

- See Cpack for making distribution

For windows the routines to find expat and freetype are script found in C:\agg\agg-2.4\bin. They are available in Cmake itself, but the ones here are better.
In case of problem, un-comment the MESSAGE statements in those script, to see what is going on.

## On Unix alikes

Asumming Agg is installed at /home/me/agg/agg-2.4
cd /home/me/agg
mkdir agg_build
cd /home/me/agg/agg_build
Here you generate makefiles with a GUI with:
ccmake ../agg-2.4
OR using commandline for example:
cmake -Dagg_USE_FREETYPE:BOOL=ON -Dagg_USE_EXPAT:BOOL=ON ../agg-2.4
The options:

- agg_USE_EXPAT

- Requires expat to be installed.

- agg_USE_FREETYPE

- Requires freetype-devel to be installed. (e.g. on Fedora: yum install freetype-devel )

- agg_USE_GPC

- Part of Agg for the moment, but GPL, that is why its optional.

- agg_USE_SDL_PLATFORM

- SDL needs to be installed.

- agg_USE_PACK

- See Cpack for making distribution

After generating the makefiles, you just type:
make You can also build directly in the agg checkout dircetory, but that is bad habit.
When all is compiled, you can execute the samples already from the examples directory in your build tree.
Now you can login as root and install Agg as you compiled it.
So you type:
make install
This installes your file in /usr/local.

## My Own Application

Nice but what if i want to detect Agg libraries and headers etc. for use in my own application. For that you find in the resulting build directory created by Cmake, a template directory called myapp, containing a simple application. This show you how to do it for your own application. In there you see CMakeLists.txt, this file you can use in CMakeSetup.exe/ccmake as the source directory. Again choose your build directory, and configure.
This will result in project/make files for the demo application contained in my_demo.cpp.
In principle this is needed ( see myapp/CMakeLists.txt ):
FIND_PACKAGE( Agg )
IF( AGG_FOUND )
INCLUDE_DIRECTORIES(${AGG_INCLUDE_DIRS})
LINK_LIBRARIES(${AGG_LIBRARIES})
INCLUDE(${AGG_USE_FILE})
ELSE( AGG_FOUND )
MESSAGE( "AGG library was not found" )
ENDIF( AGG_FOUND )
If you look in your C:\agg\agg-2.4_Build you will see that AggConfig.cmake and UseAgg.cmake, they contain all the information you need to have to use Agg in your application. Study FindAgg.cmake to know who Agg install dir is found.
Also be aware that the file C:\agg\agg-2.4_Build\bin\AggConfigOutBuild.cmake is installed as AggConfig.cmake by make install are inside the packages.
The file C:\agg\agg-2.4_Build\AggConfig.cmake is setup such that you can use it from with in the build directory itself, using the Agg header files from the source directory.
This is the same as when building the agg libraries itself.
Only when packaging and/or doing a make install, the headers will be really installed.
On windows you need to set the environment variable AGG_DIR, if automatic detection via the registry fails. But if you use a package like antigrain-0.1.1-win32.exe to install on windows, a registry key "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Agg\\antigrain 0.1.1]/bin" is generated, which is used by FindAgg.cmake to find the installation.
On Unix you can, after installing Agg, go to /home/me/agg/agg_build/myapp and type this for an inside build:
cmake .
or for an outside build:
mkdir ../buildmyapp
cd ../buildmyapp
cmake ../myapp
If you do not want to install, you can set AGG_DIR first, to use the build without installing, like:
export AGG_DIR=/home/me/agg/agg_build

## Cpack to make distributions

If enabled agg_USE_PACK, you get an extra target.
On windows have gzip and nsis installed, they are used to generate the setup/installer script and zip files, and found automatically:
http://nsis.sourceforge.net
http://www.7-zip.org
Parts of the Cmake system is Cpack. After a build of Agg, you get an extra target to PACKAGE, but you can do it by hand also.
Calling the Cmake tool: cpack.exe -C debug or cpack.exe -C release on the command line, will result in files like:
antigrain-0.1.1-win32.exe # this is the installers script for Agg on windows.
antigrain-0.1.1-win32.zip #contains the same, and can be installed by hand
The first gives you a registery key like this: [HKEY_LOCAL_MACHINE\SOFTWARE\Agg\antigrain 0.1.1] And that is used to detect Agg in FindAgg.cmake, if you use the zip file, you will need to set AGG_DIR in your environment to reach the same.
On unix you type:
cpack -C debug on the line, and this gives you files like:
antigrain-0.1.1-Linux.sh
antigrain-0.1.1-Linux.tar.gz
antigrain-0.1.1-Linux.tar.Z
antigrain-0.1.1-Linux.tar.bz2