INTRODUCTION Overview Download and Install Documentation Publications REPOSITORY Libraries DEVELOPER Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
Tutorial for the GearBox Build SystemThe term build system refers the software and procedures responsible for compiling, installing, and distributing source code. GearBox uses CMake to handle its build system. CMake is a cross-platform tool, designed as a replacement for autotools.Contents: BasicsBuilds are controlled by a set of files called 'CMakeLists.txt'. There is approximately one in each directory, and builds descend recursively through the source tree.An individual developer only needs to be concerned with writing CMakeLists.txt files in the directory containing his or her library code and below. ExampleHere's an example of a CMakeLists.txt file to builid a library. We'll go through it line by line.
SET ( lib_name GbxAdvanced ) GBX_ADD_LICENSE( GPL ) SET ( build TRUE ) # Check for human input GBX_REQUIRE_OPTION( build LIB ${lib_name} ON ) # Check arbitrary variables GBX_REQUIRE_VAR( build LIB ${lib_name} GBX_OS_LINUX "only Linux OS is supported" ) # Check local targets (libraries or executables) SET( dep_libs basic ) GBX_REQUIRE_TARGETS( build LIB ${lib_name} ${dep_libs} ) IF ( build ) INCLUDE( ${GBX_CMAKE_DIR}/UseBasicRules.cmake ) FILE( GLOB hdrs *.h ) FILE( GLOB srcs *.cpp ) GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} ) TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} ) GBX_ADD_HEADERS( gbxadvanced ${hdrs} ) ENDIF ( build ) Line-by-LineSET ( lib_name GbxAdvanced ) string lib_name = "GbxAdvanced" ).
Notice the GearBox convention for naming CMake variables:
GBX_ADD_LICENSE( GPL ) LICENSE file at the top level of the distribution (check out what it looks like). This is a custom GearBox macro as indicated by the "GBX_" prefix. Any text can be put into this macro, e.g. "LGPL (with written permission from the original authors)".
SET ( build TRUE ) build and set it to TRUE, i.e. "this library will be built". Failure to meet any one of the requirements will assign FALSE to this "cumulative variable".
# Check for human input GBX_REQUIRE_OPTION( build LIB ${lib_name} ON ) This GearBox macro checks for user input into the build process. It is actually a shortcut which does several things:
Notice that to evaluate the variable you have to inclose it in braces and add a dollar sign, i.e. This macro is quite flexible. You can specify custom names for the option variables and provide a custom description.
GBX_REQUIRE_VAR( build LIB ${lib_name} GBX_OS_LINUX "only Linux OS is supported" ) GBX_OS_LINUX , evaluates to TRUE. Examples of usage are: check that the OS is supported, the compiler version is acceptable, that dependencies are found, versions of required libraries are new enough, etc.
SET( dep_libs basic ) GBX_REQUIRE_TARGETS( build LIB ${lib_name} ${dep_libs} ) dep_libs can contain a list of libraries separated by a space. In this case we only have one called "basic". In order to reduce the amount of typing required we will reuse this variable later when it comes to actually linking.
IF ( build ) build variable can tell us to build or not to build.
A note on slightly funky CMake syntax: notice that in the IF statement and in other places with a boolean context, CMake accepts both the variable name, i.e.
INCLUDE( ${GBX_CMAKE_DIR}/UseBasicRules.cmake ) [GEARBOX-SRC]/cmake. For convenience, this path is stored in the special variable GBX_CMAKE_DIR . The INCLUDE command literally pastes the contents of the referenced scripts right here in the middle of our file. So you can take a look at that script to see what it does. Importantly, it adds -Wall compiler definition.
FILE( GLOB hdrs *.h ) FILE( GLOB srcs *.cpp ) hdrs and srcs .
GBX_ADD_LIBRARY( ${lib_name} SHARED ${srcs} ) TARGET_LINK_LIBRARIES( ${lib_name} ${dep_libs} )
GBX_ADD_HEADERS( gbxadvanced ${hdrs} ) [PREFIX]/include/gearbox/gbxadvanced. With the custom macro only the module subdirectory needs to be specified.
ENDIF ( build ) IF statements: the signature of the closing ENDIF must be identical.A list of useful CMake variables defined by GearBoxOS variables: evaluate to TRUE when running on the corresponding OS, otherwise to FALSE. We define our own because the standard CMake ones are inconsistently named and the one for Linux is not defined.GBX_OS_LINUX GBX_OS_MAC GBX_OS_QNX GBX_OS_WIN Path variables: GBX_BIN_INSTALL_DIR GBX_LIB_INSTALL_DIR GBX_INCLUDE_INSTALL_DIR GBX_PROJECT_BINARY_DIR GBX_PROJECT_SOURCE_DIR GBX_SHARE_INSTALL_DIR |