Ask Your Question
0

Multiple Cmakelist.txt

asked 2021-10-19 03:08:36 -0600

Vic gravatar image

I have a Cmakelist.txt that looks as follows in my project

cmake_minimum_required(VERSION 3.0.2)
project(softmanbot)
add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS roscpp rospy)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
find_package(Boost REQUIRED COMPONENTS serialization)
catkin_package()

include_directories( ${catkin_INCLUDE_DIRS})

add_executable(softmanbot_supervisor_node
    common/genericSupervisor.cpp common/genericSupervisor.hpp common/genericLogic.hpp
    supervisor/specificSupervisor.cpp supervisor/specificSupervisor.hpp
    )

add_executable(softmanbot_genericDeformationControl_node 
    common/genericDeformationControl.cpp common/genericDeformationControl.hpp common/genericLogic.hpp   
    deformationControl/specificDeformationControl.cpp deformationControl/specificDeformationControl.hpp
    )

add_executable(softmanbot_genericSkilledWorkcell_node
    common/genericSkilledWorkcell.cpp common/genericSkilledWorkcell.hpp common/genericLogic.hpp
    skilledWorkcell/specificSkilledWorkcell.cpp skilledWorkcell/specificSkilledWorkcell.hpp 
    )

add_executable(softmanbot_genericPerception_node
    common/genericPerception.cpp common/genericPerception.hpp common/genericLogic.hpp
    perception/specificPerception.cpp perception/specificPerception.hpp
    )


target_link_libraries(softmanbot_supervisor_node
    ${catkin_LIBRARIES}
    ${Boost_LIBRARIES}
)

target_link_libraries(softmanbot_genericDeformationControl_node
   ${catkin_LIBRARIES}
   ${Boost_LIBRARIES}
)


target_include_directories(softmanbot_genericSkilledWorkcell_node PUBLIC ${EIGEN3_INCLUDE_DIRS})

target_link_libraries(softmanbot_genericSkilledWorkcell_node
   ${catkin_LIBRARIES}
   ${Boost_LIBRARIES}
)


target_link_libraries(softmanbot_genericPerception_node
   ${catkin_LIBRARIES}
   ${Boost_LIBRARIES}
)

Is this possible to split it in several Cmakelists.txt? I have project-requirement reasons to do this. I'd like to have one by node, which have sources in different folders. Anyone knows how to make so the main project Cmakelists act as a "orchestra chief" that just calls the other one so I can put specific includes in each nodes?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-10-19 20:58:24 -0600

KenYN gravatar image

There has always been the include() command in CMake, so you can just do:

include(buildLibA.txt)
include(LibB/CMakeLists.txt)

Or, for the second case, add_subdirectory() would be better:

include(buildLibA.txt)
add_subdirectory(LibB)
edit flag offensive delete link more

Comments

Will try that and accept answer if that works. Would also update files in a separate answer so someone with same problem can solve in the future

Vic gravatar image Vic  ( 2021-10-20 09:08:04 -0600 )edit
1

answered 2021-10-27 10:04:41 -0600

Vic gravatar image

Answer from @KenYN works. CMakelist.txt now looks like

cmake_minimum_required(VERSION 3.0.2)
project(testBenchMichelin)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

include(deformationControl/deformationControlCMake.txt)
include(supervisor/supervisorCMake.txt)
include(skilledWorkcell/skilledWorkcellCMake.txt)
include(perception/perceptionCMake.txt)

Each specific file hold relevant information. Doesn't looks like there are conflict with same library inclusions in several nodes.

edit flag offensive delete link more

Comments

Be weary if you include some message generations. I had to split up things in cmake1.txt and cmake2.txt to ensure calling catkin_package once after message generations. Haven't tried multiple messages defined on several files yet.

Vic gravatar image Vic  ( 2021-10-28 04:40:12 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-10-19 03:08:36 -0600

Seen: 24 times

Last updated: Oct 27