lbr-stack / fri

CMake support for KUKA's FRI Client SDK
Apache License 2.0
14 stars 16 forks source link

best way to add own project outside of build #16

Closed MightyMirko closed 4 months ago

MightyMirko commented 6 months ago

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 ) ```


➜  fri_cmake git:(fri-1.17) ✗ tree --nolinks -L 1        
.
├── build
├── CMakeLists.txt
├── FRI-Client-SDK_Cpp.zip
├── LICENSE
├── masters
└── README.md

2 directories, 4 files

Im missing something here since iam no pro in cmake.

MightyMirko commented 6 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)

mhubii commented 6 months ago

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):

Out-Of-Tree Build

In-Tree Build

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

int main() { // create new client KUKA::FRI::LBRClient client; return 0; }

MightyMirko commented 6 months ago

Hey Martin,

i've read a bit and got more proficient with cmake. I'm using clion Gist for others to use

CLion Settings: image

mhubii commented 6 months ago

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