aGrUM  0.13.0
How to use aGrUM with CMake

As a build system, aGrUM uses CMake (http://www.cmake.org). A minimal project with agrum should look like this (for a project foo):

  • in the project folder, a sub-folder src,
  • in src folder, your *.{cpp|h|etc.} files
  • in src folder, a file named CMakeLists.txt like this one :
1 project(FOO)
2 cmake_minimum_required(VERSION 2.8)
3 
4 set (CMAKE_CXX_STANDARD 14)
5 
6 # do not forget to change this line if needed ("act install -d...")
7 set(AGRUM_INSTALLATION_DIRECTORY "/home/phw/usr")
8 set(aGrUM_DIR "${AGRUM_INSTALLATION_DIRECTORY}/lib/cmake/aGrUM/")
9 
10 find_package(aGrUM)
11 
12 if (aGrUM_FOUND)
13  include_directories(${AGRUM_INCLUDE_DIR})
14  link_directories(${AGRUM_LIB_DIR})
15 else (aGrUM_FOUND)
16  message(FATAL_ERROR "Please install aGrUM")
17 endif (aGrUM_FOUND)
18 
19 # cmake -DCMAKE_BUILD_TYPE=DEBUG
20 # or
21 # cmake -DCMAKE_BUILD_TYPE=RELEASE
22 # RELEASE is the default option (thanks to the next 3 lines)
23 if( NOT CMAKE_BUILD_TYPE )
24  set( CMAKE_BUILD_TYPE RELEASE)
25 endif()
26 
27 file(GLOB_RECURSE FOO_SOURCE ${FOO_SOURCE_DIR}/*.cpp)
28 file(GLOB_RECURSE FOO_INCLUDE ${FOO_SOURCE_DIR}/*.h)
29 
30 add_executable (foo ${FOO_SOURCE})
31 
32 if (${CMAKE_BUILD_TYPE} STREQUAL "RELEASE") # release : act install release
33  target_link_libraries(foo agrum)
34 else() # debug : act install debug
35  target_link_libraries(foo agrum-dbg)
36 endif()
37  *
1 mkdir build
2 cd build
3 cmake ../src/
4 make
  • build/foo is the executable.