cmake including h files from other directories

2019-05-03 07:12发布

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?

标签: c++ cmake
1条回答
手持菜刀,她持情操
2楼-- · 2019-05-03 07:18
#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(../../)
查看更多
登录 后发表回答