Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake and absolute header paths

I'm trying to use CMake to build my C++ project and I have a problem in the header paths.

Since I'm using a lot of classes organized in several directories, all my include statements are with absolute paths (so no need to use "../../") but when try to make the CMake-generated Makefile it just doesn't work.

Does anyone know how to specify in CMakeLists.txt that all the includes are with absolute paths?


My output when trying to make

~/multiboost/BanditsLS/GenericBanditAlgorithmLS.h:45:25: Utils/Utils.h: No such file or directory
~/multiboost/BanditsLS/GenericBanditAlgorithmLS.h:46:35: Utils/StreamTokenizer.h: No such file or directory

My CMakeLists.txt file :

#The following command allows the use of the "file" command
cmake_minimum_required(VERSION 2.6)  

#The declaration of the project
project(multiboost)  

#This allows recursive parsing of the source files
file(
    GLOB_RECURSE
    source_files
    *
    )  
list(REMOVE_ITEM source_files ./build/* )

#This indicates the target (the executable)  
add_executable(
    multiboost
    ${source_files} #EXCLUDE_FROM_ALL build/
    )
like image 883
Archy Avatar asked Sep 28 '10 07:09

Archy


2 Answers

You need something like this in CMakeLists.txt:

SET(BASEPATH "${CMAKE_SOURCE_DIR}")
INCLUDE_DIRECTORIES("${BASEPATH}")
like image 57
fschmitt Avatar answered Oct 19 '22 17:10

fschmitt


set the correct include path: suppose your Utils directory is in /exp/appstat/benbou/multiboost, then cmake (well actually, gcc) has to know this:

include_directories( /exp/appstat/benbou/multiboost )

or it might be more convenient to pass this as an option which is passed on the command line:

include_directories( ${MyProjectRoot} )

cmake -DMyProjectRoot=/exp/appstat/benbou/multiboost    
like image 6
stijn Avatar answered Oct 19 '22 15:10

stijn