Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

cmake including h files from other directories

I am having trouble including a test under a cmake project. My project is set out like this:

                                       TerrainMap
                                        /     \
                         PointAccumulator     heightQuadGrid
                                                \
                                                 Test

In the TerrainMap Directory the CMakeLists.txt file simply outlines the cmake version the project name and includes the two sub directories.

In heightQuadGrid the CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)

find_package(PCL 1.2 REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_library(heightQuadGrid heightQuadGrid.cpp)

add_subdirectory(Test)

which as I understand makes a library called heightQuadGrid. The CMakeLists.txt in Test looks like this:

FIND_PACKAGE(PCL 1.2 REQUIRED)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(Boost COMPONENTS unit_test_framework REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS} )

link_libraries(heightQuadGrid)

add_executable(heightQuadTreeTest heightQuadGridTest.cpp)
target_link_libraries (heightQuadTreeTest heightQuadGrid ${PCL_LIBRARIES} ${OpenCV_LIBS} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

And finally the cpp file heightQuadGridTest.cpp has this include:

#include <heightQuadGrid/heightQuadGrid.h>

The cmake works correctly but when i go to make the project it tells me that it cannot find heightQuadGrid/heightQuadGrid.h

Whats the deal as I have seen a very similar approach in another working project?

Upvotes: 7

Views: 23148

Answers (1)

tmpearce
tmpearce

Reputation: 12693

#include <heightQuadGrid/heightQuadGrid.h>

This syntax indicates that one of the "include directories" for the project should be the directory above the heightQuadGrid dir. In the cmakelists.txt file for the heightQuadTreeTest executable, you need to go up two directories, and add that as an include directory:

include_directories(../../)

Upvotes: 7

Related Questions