I have some issue with including sub-folders on a CMAKE
project. Below in short the summary of the CMAKE
tree that I have. The first layer works ok, but the second layer does not work properly throwing a linker error
:
ERROR:
CMake Error at src/ROSTemplatesMsgs/CMakeLists.txt:17 (add_executable): Cannot find source file:
actionlib_msgs/goalID/dbGoalID.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
CMake Error: CMake can not determine linker language for target: goalID CMake Error: Cannot determine link language for target "goalID". Generating done
Project tree is shown below:
.
+-- Project-DriveAll[master]
+-- CMakeLists.txt
+-- src
| +-- projectA
| +-- projectB
| +-- ROSTemplatesMsgs
| +-- CMakeLists.txt
| +-- main
| +-- geometry_msgs.h
| +-- main.cpp
| +-- pointField.h
| +-- ros_headers.h
| +-- src
| +-- actionlib_msgs
| +-- goalID
| +-- dbGoalID.cpp
| +-- dbGoalID.h
| +-- goalIDItem.cpp
| +-- goalIDItem.h
| +-- goalStatus
| +-- dbGoalStatus.cpp
| +-- dbGoalStatus.h
| +-- goalStatusItem.cpp
| +-- goalStatusItem.h
| +-- sensor_msgs
| +-- laserscan
| ........
For a better visualization see also this:
so the root file is below and this works well:
cmake_minimum_required(VERSION 3.1)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(INCLUDE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g")
project(Project-DriveAll)
add_subdirectory(src/projectA)
add_subdirectory(src/projectB)
add_subdirectory(src/ROSTemplatesMsgs)
However, below is the CMakeLists.txt
under the project src/ROSTemplatesMsgs
that is not compiling properly:
cmake_minimum_required (VERSION 3.1)
project(ROSTemplatesMsgs)
find_package(Qt5Widgets REQUIRED)
set (OpenCV_DIR /home/to/opencv/build)
set (BOOST_LIBRARYDIR /usr/lib/x86_64-linux-gnu)
find_package( OpenCV REQUIRED )
find_package(Boost COMPONENTS system thread filesystem REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Quick Sql)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${OpenCV_INCLUDE_DIRS})
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDE_DIRS})
file(GLOB SRCS
"src/*.h"
"src/*.cpp"
"src/*.hpp"
"src/actionlib_msgs/goalID/dbGoalID.cpp"
"src/actionlib_msgs/goalID/dbGoalID.h"
"src/actionlib_msgs/goalID/dbGoalIDItem.cpp"
"src/actionlib_msgs/goalID/dbGoalIDItem.h"
"src/actionlib_msgs/goalStatusArray/dbGoalStatusArray.cpp"
"src/actionlib_msgs/goalStatusArray/dbGoalStatusArray.h"
"src/actionlib_msgs/goalStatusArray/goalStatusArrayItem.cpp"
"src/actionlib_msgs/goalStatusArray/goalStatusArrayItem.h"
"src/sensor_msgs/laserscan/*.h"
"src/sensor_msgs/laserscan/*.cpp"
"src/sensor_msgs/laserscan/*.hpp"
"src/visualization_msgs/marker/*.h"
"src/visualization_msgs/marker/*.cpp"
"src/visualization_msgs/marker/*.hpp"
"src/visualization_msgs/markerarray/*.h"
"src/visualization_msgs/markerarray/*.cpp"
"src/visualization_msgs/markerarray/*.hpp"
"src/sensor_msgs/pointcloud2/*.h"
"src/sensor_msgs/pointcloud2/*.cpp"
"src/sensor_msgs/pointcloud2/*.hpp"
"src/sensor_msgs/pointcloud/*.h"
"src/sensor_msgs/pointcloud/*.cpp"
"src/sensor_msgs/pointcloud/*.hpp"
"main/*.h"
"main/*.cpp"
"main/*.hpp"
)
file(GLOB UI_SRCS
"ui/*.h"
"ui/*.cpp"
"ui/*.hpp"
)
add_executable(ROSTemplatesMsgs main/main.cpp ${SRCS})
target_link_libraries (ROSTemplatesMsgs Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick Qt5::Sql)
add_library(ROSTemplatesMsgs_lib SHARED ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_include_directories (ROSTemplatesMsgs_lib PUBLIC "src/actionlib_msgs/" )
target_include_directories (ROSTemplatesMsgs_lib PUBLIC "src/sensor_msgs/" )
target_link_libraries (ROSTemplatesMsgs_lib Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick Qt5::Sql)
I consulted a lot of resources such as this one and this one however in my case I am not using the TARGET
option as not always suggested in the CMAKE
documentation. However I tried also to set_target_properties as suggested in this post but nothing changed. I went through this post but wasn't useful to find out what the problem was.
I also tried to add_subdirectory as advised on this post in the following way but that also didn't work:
add_subdirectory(src/actionlib_msgs)
add_subdirectory(src/sensor_msgs)
Another source I counsulted was this one and it actually helped understand the different use if dealing with a complex project and another that is not. My project has other subprojects as shown at the beginning of the question with multiple CMakeLists.txt
but the project ROSTemplatesMsgs
is the one that has multiple subfolders and that is complicating the tree.
The root has the add_subdirectory()
command and that is working well in fact. ProjectA and ProjectB have their own CMakeLists.txt
and no problem (but they also don't have multiple subfolders). When it comes to the last project (the one with subfolders) something does not work properly and I am running out of ideas.
Aucun commentaire:
Enregistrer un commentaire