tags:

views:

41

answers:

1

Hi,

I'm currently using CMake to build a project, and I have the following problem:

I have a library, say 'C', that the files for an executable 'L' need to use (the files in L call on headers from the library in C)

Both the library and the executable have to be built in the same project, and though they both go through CMake fine, the files in L can't seem to see the headers provided by the library C. I'm having to specify relative paths to the exact destination in the header files, which isn't nice at all since some file hierarchy might change at some point of time.

I'm not sure what type of a command to use to make the L files be directly be able to see the C headers, so that I can say something like

#include "display.h" 

directly in L. I don't want to have to copy headers all over the place since I have many files like L.

My Cmake files are as shown:

For the library C (which is closer to the top of the folder heirarchy):

FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_RENDERING)
  MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})

#INCLUDE_DIRECTORIES(${CRANIOLIB_SOURCE_DIR}/include)

SET(cranioDir ${CMAKE_CURRENT_SOURCE_DIR})
SET(SOURCES 
 twoD.cxx 
 display.cxx 
 rotate.cxx 
 symmetry.cxx 
 normalize.cxx 
 real_sym_eigens.cxx 
 debugLib.cxx 
 readInputLib.cxx)
SET(cranioLib_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include)
ADD_LIBRARY(cranioLib ${SOURCES})

and for the executable L:

FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_RENDERING)
  MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})

INCLUDE_DIRECTORIES(${cranioDir})

ADD_EXECUTABLE(RotateSS RotateSideToSide.cxx)
TARGET_LINK_LIBRARIES(RotateSS vtkRendering cranioLib vtkHybrid vtkGraphics)

ADD_EXECUTABLE(RotateST RotateSideTwist.cxx)
TARGET_LINK_LIBRARIES(RotateST vtkRendering cranioLib vtkHybrid vtkGraphics)

ADD_EXECUTABLE(RotateUD RotateUpDown.cxx)
TARGET_LINK_LIBRARIES(RotateUD vtkRendering cranioLib vtkHybrid vtkGraphics)

Note that these files don't completely do the job - I need some help in nailing the 'include' features of CMake, wasn't able to get anything else online that would do the trick for me.

Best.

+1  A: 

Both the library and the executable have to be built in the same project, and though they both go through CMake fine, the files in L can't seem to see the headers provided by the library C. I'm having to specify relative paths to the exact destination in the header files, which isn't nice at all since some file hierarchy might change at some point of time.

In my own projects, one line has always been sufficient:

include_directories(include)

(Where include is relative to the directory the CMakeLists.txt file resides in.) And all of my source files in src can find their headers in include. Specifying the full current source path has never been necessary.

Edit: For example, let's say you've got a project with this layout:

proj
    /src
    /include
    /somelibrary/include

And in proj/, you have a CMakeLists.txt file that references your source files like so:

SET(SOURCES src/file1.cpp src/file2.cpp)

This is the only line you need to use both include and somelibrary/include:

include_directories(include somelibrary/include)

Or, if CMakeLists.txt is in src, like this:

include_directories(../include ../somelibrary/include)
greyfade
So my problem is, that my source files are spread across different folders. What if I wanted the source files in one folder (in this case L) to be able to see the header files in another (C, in this case)?Best.
Ambar C
As in - if I follow what you say - the source files in the library's code manage to find their headers - but I also need the files in L to be able to see those same headers.
Ambar C
@Ambar C: See edit.
greyfade