Home > Programmation > Boost avec CMake

Boost avec CMake

November 29th, 2009

L’objectif de ce billet est de montrer comment compiler une application C++ utilisant boost avec cmake.

Tout d’abord, il faut avoir boost installé. Sous Ubuntu, il suffit de faire
sudo aptitude install libboost1.40-all-dev
Il faut bien entendu que cmake soit intallé
sudo aptitude install cmake

Ensuite, pour compiler un fichier avec boost, il faut utiliser un CMakeList du genre

cmake_minimum_required( VERSION 2.6 FATAL_ERROR )

SET(Boost_ADDITIONAL_VERSIONS "1.40.0" "1.41.0" )

# search for Boost version 1.40
# Components :
#filesystem, iostreams, programoptions, python, regex, serialization, signals
#system, thread, wave
find_package( Boost 1.40.0 COMPONENTS regex signals FATAL_ERROR)

link_directories ( ${Boost_LIBRARY_DIRS} )
include_directories ( ${Boost_INCLUDE_DIRS} )

SET (SOURCES
main.cpp
)

SET (EXECUTABLE_NAME
executable
)

add_executable (
${EXECUTABLE_NAME}
${SOURCES}
)

target_link_libraries (
${EXECUTABLE_NAME}
${Boost_LIBRARIES}
)

Et ensuite, la compilation habituelle avec cmake (je conseille de compiler dans un dossier séparé), personnellement je fais
mkdir build && cd build
cmake ..
make

Site officiel de Boost
Cmake

Programmation ,

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.