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?
To include headers in CMake targets, use the command target_include_directories(...) . Depending on the purpose of the included directories, you will need to define the scope specifier – either PUBLIC , PRIVATE or INTERFACE .
Add include directories to the build. Add the given directories to those the compiler uses to search for include files. Relative paths are interpreted as relative to the current source directory.
First, you use include_directories() to tell CMake to add the directory as -I to the compilation command line. Second, you list the headers in your add_executable() or add_library() call.
Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.
First, you use include_directories () to tell CMake to add the directory as -I to the compilation command line. Second, you list the headers in your add_executable () or add_library () call.
First, you use include_directories () to tell CMake to add the directory as -I to the compilation command line. Second, you list the headers in your add_executable () or add_library () call. As an example, if your project's sources are in src, and you need headers from include, you could do it like this:
In the TerrainMap Directory the CMakeLists.txt file simply outlines the cmake version the project name and includes the two sub directories.
At least, when generating a Code::Blocks project the header files do not appear within the project (the source files do). It therefore seems to me that CMake consider those headers to be externalto the project, and does not track them in the depends.
#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(../../)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With