Problem: I am struggling to link the header files in the project correctly using CMake lists. All the example online seem to be simpler and the projects use "Modern CMake" with relations which I’m also unfamiliar with.
Error:
warn
XXXXX.hpp is not a directory
fatal error
#include XXXXX.hpp: No such file or directory
Back Ground Statement:
The root dir is a node within a larger ROS based project utilising catkin tools. It is a Unix system Ubuntu 20.04. I will replicate the system directory using generic titles below, it will include all build related files ( I can expand where necessary upon request ).
File sys:
File Sys Diagram
Details of CMakeLists.txt
root_dir/CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
project(project_name LANGUAGES CXX)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/orange ${PROJECT_BINARY_DIR}/orange)
add_executable(${PROJECT_NAME}_node src/project_name_node.cpp)
target_link_libraries(${PROJECT_NAME}_node
orange-lib
)
root_dir/include/project_name/orange/CMakeLists.txt
project(project_name LANGUAGES CXX)
set(INCLUDE_DIRS
/full/path/to/navel.hpp
/full/path/to/blood.hpp
/full/path/to/tangelo.hpp
)
set(CXX_SRCS
navel.cpp
blood.cpp
tangelo.cpp
)
add_library(orange-lib ${CXX_SRCS})
include_directories(${INCLUDE_DIRS})
Can someone please inform me on how I’m messing this up. The documentation for CMake is difficult to approach as all the methods of linking and lack of consistency in git examples is causing me a lot of confusion.
>Solution :
Your root_dir/include/project_name/orange/CMakeLists.txt should be
project(project_name LANGUAGES CXX)
set(INCLUDE_DIRS
/full/path/to
)
set(CXX_SRCS
navel.cpp
blood.cpp
tangelo.cpp
)
add_library(orange-lib ${CXX_SRCS})
include_directories(${INCLUDE_DIRS})
You don’t want to provide the full path to the file as include directory, but the path to the parent directory /full/path/to. In your cpp file you then can use
#include "navel.hpp"
#include "blood.hpp"
#include "tangelo.hpp"