Your first own tgt projet
Overview
Using the tgt library ist generally spoken the same as using every other library. You have to link against it and include some of its .h files.
All you have to know though is that tgt and its gui wrappers are actually split into several libraries. The name of tgt’s core library tgt, while there are the gui wrapping libraries tgt_qt, tgt_glut and tgt_sdl. (In fact there are some tgt module libraries as well wich you probably don’t want to use.)
But as tgt is Open Source and uses the CMake build system it can be easily included in your project. That way you can build your project and tgt simultanously. This is usefull if you want to develop or alter tgt and your project at the same time.
Using the CMake build system
General configuration
Using CMake is really simple. All you have to do is creating a project file in your source directory named CMakeLists.txt. To start describing your project you have to chose a name for it. This is done by a
PROJECT( tgt_sample_project )
at the very beginning of the file. With a
FILE(GLOB PROJECT_SOURCES
project.cpp project.h
)
the files project.cpp and project.h are added to your project. The .h files are not needed for compilation but nice to include for IDE project file generation. If they are not included in the project, they won’t be displayed in your IDE’s filebrowser/projectmanager.
Last thing missing is a line to tell CMake to build an executable:
ADD_EXECUTABLE( project ${PROJECT_SOURCES} )
Now everything should already work fine. Except linking against tgt and including tgt’s .h files of course. This is done in CMake by adding the lines
INCLUDE_DIRECTORIES( ${TGT_INCLUDE_PATH} )
TARGET_LINK_LIBRARIES( project ${TGT_LIBRARY} ${TGT_GLUT_LIBRARY} )
which will tell the linker to link the executable project against the two libraries hold by the variables TGT_LIBRARY and TGT_GLUT_LIBRARY. These two have to be filled with content. As already described in the Overview there are two possible ways to do that. See below.
Using the tgt libraries
If you plan to use precompiled (by yourself or downloaded) binaries of the tgt libraries you can use the CMake module FindTGT.cmake which comes with every tgt package and resides in the samples folder.
To load this cmake module you have to set the cmake module path with
SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
The variables used are all state variables from CMake itself and will be filled correctly. The new module path will be the old one plus the subfolder “cmake” from the current source dir.
Now you can use the module’s routines to let it find your tgt installation. (Note that you have to fill in a filename when running “ccmake” if your tgt installation folder is neither a standard library folder such as /usr/local/lib nor included in the enviroment path.)
FIND_PACKAGE(TGT REQUIRED)
IF(NOT TGT_FOUND)
MESSAGE( FATAL ERROR "tgt Library not found.")
ENDIF(NOT TGT_FOUND)
The FIND_PACKAGE routine will set the variables TGT_INCLUDE_PATH, TGT_LIBRARY as well as the gui toolkit wrapper libraries TGT_QT_LIBRARY, TGT_SDL_LIBRARY and TGT_GLUT_LIBRARY correctly if tgt could be found and you can use them right away as described in the “General configuration” part above.
Compiling tgt with your project
As mentioned above it is possible to include compilation of tgt in your application when using cmake. All you have to do is to add the command
ADD_SUBDIRECTORY( tgt )
to your cmake (somewhere at the top would be clever) file. If you want to have control over your tgt subdirectory in the “ccmake” process use these lines instead:
SET( TGT_COMPILE_DIR "tgt" CACHE PATH "Path to tgt source which should be compiled with the project." )
ADD_SUBDIRECTORY ( )
Now configuration and project creation of tgt are included in your current project and will be configured and build by CMake whenever this is the case for your project.
You should also extend the include search path to your tgt directory with
INCLUDE_DIRECTORIES( tgt )
Linking is now done by using the library names specified in tgt’s CMakeLists.txt file. These are “tgt”, “tgt_qt”, “tgt_glut” and “tgt_sdl”. So a the linking of your application could be as follows
TARGET_LINK_LIBRARIES( project tgt tgt_glut )
which will tell the linker to link the executable project with the tgt core library and the tgt_glut library.
Sample project file
In the tgt/samples/project/ folder you will find a preconfigured CMake project wich can be easily configured by “ccmake” to use either a precompiled tgt library or to include tgt directly.
Using a different build system
You are free to use tgt with every other build system out there. Please regard your build system’s manual on how to use a third party library in your project.


