views:

45

answers:

2

Hi folks,

I've been googling for a while and I no result yet so I turn to you guys ^^ 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 ? Thanks a lot in advance.


My output when trying to make

/exp/appstat/benbou/multiboost/BanditsLS/GenericBanditAlgorithmLS.h:45:25: Utils/Utils.h: No such file or directory
/exp/appstat/benbou/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/
    )
+1  A: 

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    
stijn
Thanks stjin. Btw, the CMake config file must be platform independent, it can be done with sone IF statements. Good luck!
Archy
+1  A: 

You need something like this in CMakeLists.txt:

SET(BASEPATH "${CMAKE_SOURCE_DIR}")
INCLUDE_DIRECTORIES("${BASEPATH}")
fschmitt
Nice! I think this is exactly what was missing (the BASEPATH var)Thanks fschmitt!
Archy