CMake compilation

This page explains how to compile programs that depend on Bio++ using CMake.

Project organisation and CMakeLists.txt file
Here we assume that your project is organized as follows, with the main function in dark_star.cpp : dark_star/ `-- src/ |-- dark_star.cpp `-- my_class.cpp
 * -- CMakeLists.txt
 * -- build/
 * -- include/
 * `-- my_class.h

For a project that uses bpp-phyl, the CMakeLists.txt file should look like this :

cmake_minimum_required (VERSION 2.6)

project("dark_star")

set(CMAKE_CXX_FLAGS "-Wall -Wshadow -Weffc++")

macro(IMPROVED_FIND_LIBRARY OUTPUT_LIBS lib_name include_to_find) FIND_PATH(${lib_name}_INCLUDE_DIR ${include_to_find}) SET(${lib_name}_NAMES ${lib_name} ${lib_name}lib ${lib_name}dll) FIND_LIBRARY(${lib_name}_LIBRARY NAMES ${${lib_name}_NAMES})
 * 1) --- the IMPROVED_FIND_LIBRARY macro (taken from the Bio++ CMakeLists.txt) ---

IF(${lib_name}_LIBRARY) MESSAGE("-- Library ${lib_name} found here:") MESSAGE("   ${${lib_name}_INCLUDE_DIR}/") MESSAGE("   ${${lib_name}_LIBRARY}") ELSE(${lib_name}_LIBRARY) MESSAGE(FATAL_ERROR "${lib_name} required but not found.") ENDIF(${lib_name}_LIBRARY) #add the dependency: INCLUDE_DIRECTORIES(${${lib_name}_INCLUDE_DIR}) SET(${OUTPUT_LIBS} ${${OUTPUT_LIBS}} ${${lib_name}_LIBRARY}) ENDMACRO(IMPROVED_FIND_LIBRARY)

include_directories("include/")
 * 1) --- Libraries & includes ---

IMPROVED_FIND_LIBRARY(LIBS_BPP bpp-phyl "Bpp/Phyl/Tree.h") IMPROVED_FIND_LIBRARY(LIBS_BPP bpp-seq "Bpp/Seq/Sequence.h") IMPROVED_FIND_LIBRARY(LIBS_BPP bpp-core "Bpp/Clonable.h")
 * 1) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a ${CMAKE_FIND_LIBRARY_SUFFIXES}") # uncomment for static compilation


 * 1) --- Targets ---

set(exe ${PROJECT_NAME})

file(GLOB sources src/*.cpp) file(GLOB includes include/*.h) add_executable(${exe} ${sources} ${includes})

target_link_libraries(${exe} ${LIBS_BPP})

Compilation
Assuming you want to link Bio++ libraries located in $HOME/local/bpp/dev, the compilation should be something like :