Vincent
Vincent

Reputation: 60491

CMake problem of linking with headers included of the form <src/header.h>

I quite new with CMake, but I have a problem with porting an existing library to it. In order to simplify, I will only work on 2 files : angle.cpp and angle.h. The files are this ones :

/cmaketest/CMakeLists
/cmaketest/src/angle.cpp
/cmaketest/src/angle.h

and I will run CMake and produce the Makefile in /cmaketest/.

My CMakeLists is currently this one :

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(cmaketest)

SET(cmaketest_SRCDIR src)
AUX_SOURCE_DIRECTORY(${cmaketest_SRCDIR} cmaketest_SOURCES)
FILE(GLOB cmaketest_HEADERS ${cmaketest_SRCDIR}/*.h )

ADD_EXECUTABLE(cmaketest ${cmaketest_SOURCES} ${cmaketest_HEADERS})

But the problem is that in angle.cpp, the header is included not by "angle.h" but by <src/angle.h>

So with the current cmake file I got the following error when I execute make :

/cmaketest/src/angle.cpp:1:23: fatal error: src/angle.h: file not found

How to solve the problem ? (for backward compatibility I can't modify <src/angle.h> in the .cpp file)

Thank you very much.

Upvotes: 2

Views: 3012

Answers (1)

sakra
sakra

Reputation: 66001

Try adding the project directory as an include directory by using the include_directories command:

...
file (GLOB cmaketest_HEADERS ${cmaketest_SRCDIR}/*.h )

include_directories(${CMAKE_SOURCE_DIR})
add_executable(cmaketest ${cmaketest_SOURCES} ${cmaketest_HEADERS})

Upvotes: 2

Related Questions