Using CMake with ROS, one can end up with a directory tree like this:
+src
-CMakeLists.txt (symbolic link to toplevel.cmake)
-CMakeExtras.txt (I want to use this)
+computing
+perception
+per1
-CMakeLists.txt
+per2
-CMakeLists.txt
+detection
+det1
-CMakeLists.txt
+sensing
+dev1
-CMakeLists.txt
In the CMakeExtras.txt
I want to set up CMake variable, load common packages just once, etc like for example:
set(CMAKE_CXX_FLAGS "-O3 -Wall ${CMAKE_CXX_FLAGS}")
find_package(Boost REQUIRED COMPONENTS thread)
How can I do this? The INCLUDE()
command is obvious, but I cannot edit the root level CMakeLists.txt
and there doesn't seem to be a variable that will allow something like INCLUDE("${OVERALL_SRC_DIR}/CMakeExtras.txt)
. I suppose:
catkin_make -DOVERALL_SRC_DIR=~/project/src
Would be one solution, but is there a neater way?
Disclaimer: the question is still a bit unclear to me, so apologies in advance if the answer does not reflect your needs.
If the problem you want to solve is that you have a lot of directories like src
in which the same top-level CMakeLists.txt
is linked and you want to include a specific CMakeExtras.txt
that resides in each particular directory, then you can solve this by adding:
include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeExtras.txt)
to your top-level CMakeLists.txt
. According to the documentation:
This the full path to the source directory that is currently being processed by cmake
and should solve this issue (i.e. the variable refers to the directory being processed, not to the CMakeLists.txt
where it is used).
If instead your issue is how to compute the src
path, given that a link to the top level CMakelists.txt
is there, then you simply want to use PROJECT_SOURCE_DIR which:
is the source directory of the most recent project() command.