Skip to content

UsingCMakeExternally

philthiel edited this page Apr 11, 2017 · 7 revisions

Using BALL in external CMake projects

BALL uses the CMake build system and creates required project configuration files. Thus, you can a BALL in other CMake based projects. An example is shown here, which creates an executable example from example.cpp and links against BALL.

  1. Create a CMakeLists.txt project file in the location where your source file(s) are located with the following content:
#The name of the project to build
PROJECT(BALL_EXAMPLE)

# We currently require at least version 3.1 of CMake
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

# The path to the BALLConfig.cmake file. Usually located
# in the build directory of your BALL installation
SET(BALL_DIR "/path/to/BALL/build/cmake")

# Make cmake read the BALL configuration files
FIND_PACKAGE(BALL REQUIRED)

# Add required BALL include directories
INCLUDE_DIRECTORIES(${BALL_INCLUDE_DIRS})

# Add required BALL compiler flags and definitions
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BALL_CXX_FLAGS}")
ADD_DEFINITIONS("${BALL_COMPILE_DEFINITIONS}")

# Tell cmake to generate an executable called example that depends
# on the file example.cpp
ADD_EXECUTABLE(example example.cpp)

# Link example against BALL
TARGET_LINK_LIBRARIES(example BALL)
  1. Create a directory named build
  2. Change to this directory
  3. Configure the project (if you use the ball_contrib package you have to specify the path to its installation directory):
$ cmake .. -DCMAKE_PREFIX_PATH=<ball_contrib_build_dir>/install
  1. Build the project
$ make 

You are done ;-)

Clone this wiki locally