Closed MightyMirko closed 4 months ago
Found the error.. CMake was adding all files *.cpp to my sources..
file(GLOB_RECURSE MASTERS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/masters/*.cpp)
file(GLOB_RECURSE MASTERS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/masters/ *.cpp)
hi @MightyMirko and sorry for the late response. Sorry I haven't used clion before.
However, one way to achieve what you are trying to do is the following (tested on Linux):
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build
FRIClient::FRIClient
target
project(demo)
cmake_minimum_required(VERSION 3.18)
find_package(FRIClient REQUIRED)
add_executable(demo main.cpp)
target_link_libraries(demo FRIClient::FRIClient)
git submodule add https://github.com/lbr-stack/fri.git
CMakeLists.txt
add
add_subdirectory(fri) # defines FRIClient::FRIClient target
...
target_link_libraries(your_target FRIClient::FRIClient)
The FRIClient::FRIClient
is an alias for in tree builds: https://github.com/lbr-stack/fri/blob/fri-1.15/CMakeLists.txt#L81
Let me know if this helps.
Full example below:
.
├── fri/
├── CMakeLists.txt
├── main.cpp
CMakeLists.txt
project(demo)
cmake_minimum_required(VERSION 3.18)
add_subdirectory(fri)
add_executable(demo main.cpp)
target_link_libraries(demo FRIClient::FRIClient)
main.cpp
(not this code doesn't do anything)
#include "friLBRClient.h"
int main() { // create new client KUKA::FRI::LBRClient client; return 0; }
Hey Martin,
i've read a bit and got more proficient with cmake. I'm using clion Gist for others to use
CLion Settings:
cool thanks for sharing @MightyMirko . So one note, you won't have to add the include directories explicitly, as they are all included in the FRIClient::FRIClient
CMake target. There exist tutorials on CMake, e.g. here https://cliutils.gitlab.io/modern-cmake/
You can simply use find_package
or add_subdirectory
to make the target available in your project, as explained above
Hello and thanks so far
Im trying to add my own executable working in clion:
Details
```bash ====================[ Build | mastersAPP | Release ]============================ /home/mirko/Downloads/clion/bin/cmake/linux/x64/bin/cmake --build /home/mirko/OneDrive/codespace/fri_cmake/build --target mastersAPP -- -j 6 [ 33%] Built target FRIClient [ 35%] Building CXX object CMakeFiles/mastersAPP.dir/masters/masters.cpp.o [ 38%] Building CXX object CMakeFiles/mastersAPP.dir/masters/mastersclient.cpp.o [ 41%] Building CXX object CMakeFiles/mastersAPP.dir/CMakeFiles/3.27.8/CompilerIdCXX/CMakeCXXCompilerId.cpp.o [ 43%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/IOAccess/IOAccessApp.cpp.o [ 46%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/IOAccess/IOAccessClient.cpp.o [ 48%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRClientTemplate/MyLBRApp.cpp.o [ 51%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRClientTemplate/MyLBRClient.cpp.o [ 53%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRJointSineOverlay/LBRJointSineOverlayApp.cpp.o [ 56%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRJointSineOverlay/LBRJointSineOverlayClient.cpp.o [ 58%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRTorqueSineOverlay/LBRTorqueSineOverlayApp.cpp.o [ 61%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRTorqueSineOverlay/LBRTorqueSineOverlayClient.cpp.o [ 64%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRWrenchSineOverlay/LBRWrenchSineOverlayApp.cpp.o [ 66%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/LBRWrenchSineOverlay/LBRWrenchSineOverlayClient.cpp.o [ 69%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/SimulatedTransformationProvider/SimulatedTransformationProviderApp.cpp.o [ 71%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/SimulatedTransformationProvider/SimulatedTransformationProviderClient.cpp.o [ 74%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/TransformationProvider/TransformationProviderApp.cpp.o [ 76%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/example/TransformationProvider/TransformationProviderClient.cpp.o [ 79%] Building CXX object CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/src/base/friClientApplication.cpp.o In file included from /home/mirko/OneDrive/codespace/fri_cmake/build/FRI-Client-SDK_Cpp/src/base/friClientApplication.cpp:64: /home/mirko/OneDrive/codespace/fri_cmake/build/FRI-Client-SDK_Cpp/src/base/friClientData.h:65:10: fatal error: FRIMessages.pb.h: No such file or directory 65 | #include "FRIMessages.pb.h" | ^~~~~~~~~~~~~~~~~~ compilation terminated. gmake[3]: *** [CMakeFiles/mastersAPP.dir/build.make:314: CMakeFiles/mastersAPP.dir/FRI-Client-SDK_Cpp/src/base/friClientApplication.cpp.o] Error 1 gmake[3]: *** Waiting for unfinished jobs.... gmake[2]: *** [CMakeFiles/Makefile2:279: CMakeFiles/mastersAPP.dir/all] Error 2 gmake[1]: *** [CMakeFiles/Makefile2:286: CMakeFiles/mastersAPP.dir/rule] Error 2 ```
Details
```cmake ################ # build masters ################ file(GLOB_RECURSE MASTERS_SOURCES RELATIVE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/masters *.cpp) #file(GLOB_RECURSE MASTERS_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/masters/src *.cpp) add_executable(mastersAPP ${MASTERS_SOURCES} ) target_include_directories(mastersAPP PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/ ${CMAKE_CURRENT_SOURCE_DIR}/masters/include # Add other include directories if needed ) target_link_libraries(mastersAPP PRIVATE FRIClient #${CMAKE_CURRENT_BINARY_DIR}/${FRIClient_SDK_NAME}/FRIClient # Add other libraries if needed ) ```
Im missing something here since iam no pro in cmake.