When i catkin_make when module_one find package module_two and module_two find package module_one, there is error like below
-- +++ processing catkin package: 'module_one'
-- ==> add_subdirectory(module_one)
-- Could NOT find module_two (missing: module_two_DIR)
-- Could not find the required component 'module_two'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by "module_two" with
any of the following names:
module_twoConfig.cmake
module_two-config.cmake
Add the installation prefix of "module_two" to CMAKE_PREFIX_PATH or set
"module_two_DIR" to a directory containing one of the above files. If
"module_two" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
module_one/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/ri/workspace/catkin_playground/build/CMakeFiles/CMakeOutput.log".
See also "/home/ri/workspace/catkin_playground/build/CMakeFiles/CMakeError.log".
the workspace folder tree is below
├── build
│ ├── atomic_configure
│ ├── catkin
│ │ └── catkin_generated
│ │ └── version
│ ├── catkin_generated
│ │ ├── installspace
│ │ └── stamps
│ │ └── Project
│ ├── CMakeFiles
│ │ ├── 3.11.0
│ │ │ ├── CompilerIdC
│ │ │ │ └── tmp
│ │ │ └── CompilerIdCXX
│ │ │ └── tmp
│ │ └── CMakeTmp
│ ├── gtest
│ │ ├── CMakeFiles
│ │ └── googlemock
│ │ ├── CMakeFiles
│ │ └── gtest
│ │ └── CMakeFiles
│ ├── module_one
│ │ └── CMakeFiles
│ └── test_results
├── devel
│ └── lib
└── src
├── module_one
└── module_two
module_one's CMakeLists.txt has
find_package(catkin REQUIRED module_two)
module_two's CMakeLists.txt has
find_package(catkin REQUIRED module_one)
like above project,
Is there a CMakeLists configuration for referencing packages to each other?
I tried to imitate your setup: I made a new workspace, I make two new packages using catkin_create_pkg, and I got your error. This happens when some of the following setup issues aren't addressed:
In CMakeLists.txt, you must find_package(catkin REQUIRED COMPONENTS ...) the neccessary packages (don't forget roscpp if you use C++!)
# In module_1
find_package(catkin REQUIRED COMPONENTS
roscpp
module_2
)
In CMakeLists.txt, you must declare to catkin your dependencies as well (this CATKIN_DEPENDS list is a mirror of the find_package list above):
# In module_1
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES mod2
CATKIN_DEPENDS roscpp module_2
# DEPENDS system_lib
)
In package.xml you need a <depend> for that module as well.
<!-- In module_1 -->
<depend>module_2</depend>
If you do all that, then that error goes away. But then you have a new error:
Circular dependency in subset of packages: module_1, module_2
I would recommend you re-structure your code to avoid circular dependencies, either by combining packages, or if you prefer tiny packages, pulling out the common dependencies to a third package.
Related
Consider a multi binary project with the following structure.
.
├── bin1
│ ├── config
│ │ ├── config.go
│ │ └── config_test.go
│ └── utils
│ ├── utils.go
│ └── utils_test.go
├── bin2
│ ├── config
│ │ ├── config.go
│ │ └── config_test.go
│ └── utils
│ ├── utils.go
│ └── utils_test.go
├── cmd
│ ├── bin1
│ │ └── bin1.go
│ ├── bin2
│ │ └── bin2.go
│ └── bin3
│ └── bin3.go
├── go.mod
├── go.sum
└── shared
├── db
│ ├── db.go
│ └── db_test.go
├── model
│ ├── modela.go
│ ├── modela_test.go
│ ├── modelb.go
│ └── modelb_test.go
└── utils
├── utils.go
└── utils_test.go
This project has three binaries bin1, bin2 and bin3. Packages in the /shared directory (e.g. package shareddb, sharedmodel and sharedutils) are shared with binary specific packages (e.g. package bin1config, bin1utils in /bin1 directory and package bin2config, bin2utils in /bin2 directory).
How can we run
all the unit tests in this project altogether?
all the tests in a package (e.g. in shared/model)?
each tests separately?
I attempted the following.
Running go test from the project root resulted in no Go files in /projectroot.
# run all tests
go test ./...
# run all tests under a specific directory (including subdiretories)
go test ./bin2/...
# test package located in specific directory
go test ./shared/model
# test package that has specific import path
go test projectroot/shared/model
# test package in current working directory
go test
# ditto
go test .
# test package in parent directory
go test ..
# run a specific test within the package under test
go test -run=X
# run a specific sub-test within the package under test
go test -run=X/Y
For more details on the go test command, see Test packages.
For more details on the [packages] argument to go test, see Packge lists and patters.
For more details on the testing flags, see Testing flags.
I'm doing some experiments to learn CMake. So the commands stay in my mind. I created a project to test what I just learned. However, I have a problem.
The structure of my project is as follows:
├── bin
├── CMakeLists.txt
└── src
├── Configuration
│ ├── CMakeLists.txt
│ ├── Test
│ │ └── TestConfiguration.h
├── Array
│ └── Array.h
├── CMakeLists.txt
├── Test2
│ ├── CMakeLists.txt
│ ├── Test2.cpp
│ ├── Test2.h
│ └── Test2-1.h
├── Main
│ ├── CMakeLists.txt
│ ├── Config.h
│ └── Main.h
├── Test3
│ ├── CMakeLists.txt
│ ├── Time.h
│ ├── Timer
│ │ ├── CMakeLists.txt
│ │ ├── Iterate.h
│ │ ├── Run.h
│ │ ├── Serial.cmpl.cpp
│ │ └── Serial.h
│ ├── Smart.h
│ ├── Counting.h
│ ├── Mute.h
│ └── MainTest.h
└── Utilities
├── CMakeLists.txt
├── Inform.h
├── Settings.h
├── Print.h
└── Const.h
But I didn't understand how I should make these CMakeLists.txt files. For example, the file src/Utilities/Inform.h uses the following header:
// src/Utilities/Inform.h
#include "Main/Config.h"
I've tried everything I've seen on the internet and stackoverflow to edit the src/Utilities/CMakeLists.txt file. But no matter what I do, it never sees the Main/Config.h file. I just need to do something like ../../Main/Config.h.
The same problem applies to other folders. What I want to learn here is to be able to navigate and call all files in the project with CMakeLists.txt. While doing this, I tried many of the following parameters:
add_library
target_include_directories
target_link_libraries
link_directories
link_libraries
I think there's something I'm missing or misunderstood. I would be glad if you help me in this regard. If you tell me how to edit the src/Utilities/CMakeLists.txt file, I will try to fill the others accordingly.
Additionally, there is something I'm curious about. Do I also need to edit the src/CMakeLists.txt file? Or is it enough if I just edit for example src/Utilities/CMakeLists.txt?
Also, I don't know if it will be needed additionally, but I'm using cmake version 3.16.3. My development environment is an x86_64 20.04.1 Ubuntu-based Elementary OS.
I've read the official documentation for CMake 3.16 and the answers from fellow developers on StackOverFlow. I want to use the header file in the parent folder in a header in subdirectories. But many ways I've tried are wrong. There is always an error in the include path I entered. I want to learn from experienced developers what I did wrong.
How can I do it in a good practice. This is the repo structure:
~/workspace$ tree -L 3
.
├── my_program
│ ├── src
│ │ ├── module1
│ │ ├── module2
│ │ ├── CMakeLists.txt
│ │ └── ...
├── needed_library
│ ├── src
│ │ ├── module3
│ │ ├── module4
│ │ ├── CMakeLists.txt
│ │ ├── README.md
│ │ └── ...
For needed_library, I learned from the README that I can build it manually by:
mkdir build
cd build
cmake ../src
make
make install
And needed library and headers will be installed.
How can I integrate this process into my own program's CMakelists.txt? And link the desired library and header to my program?
I'm working on a project that encompasses an SDL-based game framework, an editor, and a game. The directory structure is shaping up to be something like this (edited for brevity)
├── CMake
├── Libraries
├── Resources
└── Source
├── Editor
├── Framework
│ └── Source
│ ├── AI
│ │ ├── Private
│ │ └── Public
│ ├── Game
│ │ ├── Private
│ │ └── Public
│ ├── Graphics
│ │ ├── Private
│ │ └── Public
│ └── Networking
├── Game
│ └── Source
│ └── Runtime
│ └── Launch
│ ├── Private
│ └── Public
└── Server
My add_executable command is being ran in Game/Source/Runtime/Launch/Private, and is dependent on files from the other modules.
According to some CMake how-tos and the accepted response for the following question, the headers for a given target should be included in the add_executable call in order for them to be listed as dependencies in the makefile.
How to properly add include directories with CMake
My question is, what is the cleanest way to accomplish this, given the abundance of header files and directories in my project? I can't imagine that the best practice would be to maintain a huge list of files directly in the add_executable call, but I could be wrong.
I was thinking that each directory's CMakeLists.txt could be responsible for adding to a variable that would eventually be used in add_executable, but distributing that intent through so many files seems like poor practice. Is there a better way?
You can follow exactly the pattern in the link you sent. For each library (I suppose they are libraries/targets in CMake), use:
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Private PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Public)
By doing this, you tell CMake that the Private folders are just for the current target, but if someone uses the target for another target, it should add the Public include directories.
Now, you just need to do:
target_link_libraries(${target} PRIVATE Framework_Source)
If Framework_Source is the name of a target. ${target} is the name of the target you are currently building.
I downloaded the Protocol Buffers source from GitHub. I don't want to install it globally and just want to use it in my ROS package. I found cmake files here but not sure how to use them in my project.
Below is the content of my CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(local_protobuf_ros_example)
find_package(catkin REQUIRED COMPONENTS roscpp)
find_package(Protobuf REQUIRED)
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS})
add_library(addressbook_protobuf include/addressbook.pb.cc)
add_executable(main src/main.cpp)
target_link_libraries(main ${catkin_LIBRARIES} addressbook_protobuf ${PROTOBUF_LIBRARIES})
Below is the file structure of ROS Package:
├── CMakeLists.txt
├── include
│ ├── addressbook.pb.cc
│ ├── addressbook.pb.h
│ └── addressbook.proto
├── lib
│ ├── protobuf-3.5.0
│ │ ├── cmake
│ │ │ ├── CMakeLists.txt
│ │ │ ├── examples.cmake
│ │ │ ├── extract_includes.bat.in
│ │ │ ├── install.cmake
│ │ │ ├── libprotobuf.cmake
│ │ │ ├── libprotobuf-lite.cmake
│ │ │ ├── libprotoc.cmake
│ │ │ ├── protobuf-config.cmake.in
│ │ │ ├── protobuf-config-version.cmake.in
│ │ │ ├── protobuf-lite.pc.cmake
│ │ │ ├── protobuf-module.cmake.in
│ │ │ ├── protobuf-options.cmake
│ │ │ ├── protobuf.pc.cmake
│ │ │ ├── protoc.cmake
│ │ │ ├── README.md
│ │ │ └── tests.cmake
│ │ ├──SOME_FILES_ARE_NOT_BEING_SHOWN_HERE
│ └── protobuf-cpp-3.5.0.zip
├── package.xml
└── src
└── main.cpp
I want to know that how to configure above CMakeLists.txt so that it uses locally installed Protocol Buffers?
You can set CMAKE_MODULE_PATH when you configure your build directory to specify a custom location to search for packages. You are not required to modify your CMakeLists.txt, configure your build for example like this:
cmake -DCMAKE_MODULE_PATH=/path/to/protobuf/cmake/config /path/to/source