Table of Contents
Building TerraLib from CMake Scripts
CMake
CMake (Cross-Platform Makefile Generator), is a open-source cross-platform build system. It consists of a set of tools designed to build, test and package software. Through independents configuration files, CMake generates natives makefiles and workspaces that can be used in the compiler enviroment of your choice.
Installing CMake
For the CMake installation, you might follow several steps:
- Install CMake 2.8.4 or above
- On Windows, make sure that CMake was added to the ststem path
Design
The CMake scripts were organized into folders according to their respective TerraLib modules, keeping a main script in CMake tree root.
Updating the Scripts
Here you will see how to create and update CMake scripts. You can take as examples the scripts already created for TerraLib.
Creating a Script For a New Module
To create a script for a new TerraLib module, you will do:
- Create a directory at
terralib5/build/cmake
for the new module - In the new directory, create a txt file named “CMakeLists”
- The extension must be “txt”
- Edit this file using CMake functions. Let's see some used functions:
cmake_minimum_required()
- Inform the minimum CMake version required.SET(MY_VAR “My Var Value”)
- Create a variable.project(“MyProjectName”)
- Infoem the project name.add_definitions(-DMYDEF1 -DMYDEF2)
- Insert definitions needed to build the project.- Example:
add_definitions(-DTECOMMONDLL -DBOOST_ALL_NO_LIB)
file(GLOB SRCS src_dir/*.cpp
- Used to search and include in the variable (“SRCS” in this case), all files with extension “.cpp”- Use example:
file(GLOB SRCS ${TL_SRC_DIR}/*.cpp)
include_directories(“dependence/include”)
- Inform the path where are the include files of the dependences.LINK_LIBRARIES(dependence/lib/dep.lib)
- Inform the path and the dependency library name.add_library(${LIB_NAME} SHARED ${SRCS} ${HDRS})
- Configure the library that will be created with the source code used.
Creating a Script For a New Find
To create a script for a new Find, you will do:
- In the cmake_common directory, create a file named “FindXXXX.cmake”.
- The “XXXX” will be the name of component that you want to find.
- Edit this file using CMake functions. Let's see some used functions:
FIND_PATH (INCLUDE_DIR include_file.h PATHS “library/include”)
- See the path after tag “PATHS” to search the file “include_file.h”, that is only a reference. Doing that, the variable “INCLUDE_DIR” will receive that path of “include_file.h”.FIND_LIBRARY(LIBRARY NAMES thelib.lib HINTS “library/lib”)
- Search the lib “thelib.lib” at the path after the tag “HINTS”. Doing that, the variable “LIBRARY” will receive the path and the lib name.- With this informations, you can build a variable containing information about release lib and debug lib, like:
SET(LIBRARIES optimized ${LIBRARY} debug ${LIBRARY_D})
- These information will be disponibilized for the script build.
Updating a Script Of a Module
Adding New Dependencies
Final Remarks
Miscellaneous
TE_OUTPUT_REPORT_DIR
:TE_DEPENDENCIES_DIR
: