<div class="gmail_quote">Hello all,<br><br>Here we are struggling again with cmake and yarp devices. Now we're trying to break a device I already had into a directory and a subdirectory in order to provide yarp decoupling with the device class.<br>
<br>So thats my directory structure<br>yarp-2.2.2/src/modules/wamArm/<br>|-- CMakeLists.txt<br>|-- libwamarm.a<br>|-- sockcmds.c<br>|-- sockcmds.h<br>|-- wamDriver<br>| |-- CMakeLists.txt<br>| |-- cmake_install.cmake<br>
| |-- constants.h<br>| |-- libsockcmds.a<br>| |-- libwamdrive.a<br>| |-- sockcmds.cpp<br>| |-- sockcmds.h<br>| |-- wamDriver.cpp<br>| |-- wamDriver.h<br>| |-- wamDriverTest<br>| `-- wamDriverTest.cpp<br>
|-- wamarm.cpp<br>|-- wamarm.h<br>`-- wamtest.cpp<br><br>And we have three libraries there, wamarm, wamdrive and sockcmds. When building the wamDriver directory, we create wamdrive and sockcmds libraries and link them, as wamdrive uses sockcmds. Later, when building the wamArm directory wamarm library is created and linked to wamdrive. Finally, we'll be building the yarp devices which include the wamArm directory with the ADD_SUBDIRECTORY(wamArm) statement.<br>
<br>Here are my CMakeLists<br><br>In the wamArm/ directory<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">PROJECT(wamArm)<br>cmake_minimum_required(VERSION 2.4)<br>
FIND_PACKAGE(YARP REQUIRED)<br><br></blockquote><div><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">IF (COMPILE_DEVICE_LIBRARY)<br>
PREPARE_DEVICE(wamArm TYPE Wamarm INCLUDE wamarm.h WRAPPER controlboard)<br>
ENDIF (COMPILE_DEVICE_LIBRARY)<br></blockquote><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><div> </div></blockquote></div><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
ADD_SUBDIRECTORY(wamDriver)<br>INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/wamDriver)<br>LINK_DIRECTORIES(wamDriver)<br><br>ADD_LIBRARY(wamarm wamarm.h wamarm.cpp)<br>LINK_LIBRARIES(wamarm wamdrive)<br>LINK_LIBRARIES(wamarm sockcmds)<br>
</blockquote><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><div> </div></blockquote><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
IF (NOT COMPILE_DEVICE_LIBRARY)<br> ADD_EXECUTABLE(wamtest wamtest.cpp)<br> TARGET_LINK_LIBRARIES(wamtest wamarm)<br>ENDIF (NOT COMPILE_DEVICE_LIBRARY)<br><br></blockquote><br>in the wamArm/wamDriver/ directory<br><br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
PROJECT(wamArm)<br><br>cmake_minimum_required(VERSION 2.4)<br><br> #build a shared library<br> ADD_LIBRARY(sockcmds sockcmds.cpp sockcmds.h)<br> ADD_LIBRARY(wamdrive wamDriver.cpp wamDriver.h)<br> LINK_LIBRARIES(wamdrive sockcmds)<br>
<br>IF (NOT COMPILE_DEVICE_LIBRARY)<br> ADD_EXECUTABLE(wamDriverTest wamDriverTest.cpp)<br> TARGET_LINK_LIBRARIES(wamDriverTest wamdrive)<br> TARGET_LINK_LIBRARIES(wamDriverTest sockcmds)<br>ENDIF (NOT COMPILE_DEVICE_LIBRARY)<br>
</blockquote><br>The output of building both wamArm and wamDriver goes fine.<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">pmonso@delucia:~/YARP/yarp-2.2.2/src/modules/wamArm/wamDriver$ make<br>
Scanning dependencies of target sockcmds<br>[ 33%] Building CXX object CMakeFiles/sockcmds.dir/sockcmds.o<br>Linking CXX static library libsockcmds.a<br>[ 33%] Built target sockcmds<br>Scanning dependencies of target wamdrive<br>
[ 66%] Building CXX object CMakeFiles/wamdrive.dir/wamDriver.o<br>Linking CXX static library libwamdrive.a<br>[ 66%] Built target wamdrive<br>Scanning dependencies of target wamDriverTest<br>[100%] Building CXX object CMakeFiles/wamDriverTest.dir/wamDriverTest.o<br>
Linking CXX executable wamDriverTest<br>[100%] Built target wamDriverTest<br></blockquote><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
pmonso@delucia:~/YARP/yarp-2.2.2/src/modules/wamArm$ make<br>[ 20%] Built target wamarm<br>[ 40%] Built target wamdrive<br>Scanning dependencies of target sockcmds<br>[ 60%] Building CXX object wamDriver/CMakeFiles/sockcmds.dir/sockcmds.o<br>
Linking CXX static library libsockcmds.a<br>[ 60%] Built target sockcmds<br>Scanning dependencies of target wamtest<br>Linking CXX executable wamtest<br>[ 80%] Built target wamtest<br>Scanning dependencies of target wamDriverTest<br>
[100%] Building CXX object wamDriver/CMakeFiles/wamDriverTest.dir/wamDriverTest.o<br>Linking CXX executable wamDriverTest<br>[100%] Built target wamDriverTest<br></blockquote><br>While building the device<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
pmonso@delucia:~/YARP/yarp-2.2.2/src/modules$ make<br>[ 80%] Built target yarpmod<br>Linking CXX executable yarpmoddev<br>libyarpmod.a(add_yarpmod_devices.o): In function `add_yarpmod_devices':<br>add_yarpmod_devices.cpp:(.text+0x1c): undefined reference to `add_wamArm()'<br>
collect2: ld returned 1 exit status<br>make[2]: *** [yarpmoddev] Error 1<br>make[1]: *** [CMakeFiles/yarpmoddev.dir/all] Error 2<br>make: *** [all] Error 2<br></blockquote><br>Two questions arise there, why do I have to link sockcmds with wamdrive if we already do that on the wamDriver subdirectory? Shouldn't they be linked as were descending upon the directory structure?<br>
<br>and, more important, what am I missing? I'm quite new on cmake and I find it hard to understand how is it dealing with libraries and linking.<br><br>Also, there are two more issues that I avoided as I could. Originally, the sockcmds is in C not in C++ but I had trouble building it although I had marked the prototypes as extern C, there were undefined references when we were linking. And second, as wamarm class is just a wrapper for the actual driver, there wasn't any much code so no .cpp file was needed. However, cmake would not know what compiler to use as it couldn't guess from the extension. The SET_TARGET_PROPERTIES(wamarm PROPERTIES LINKER_LANGUAGE CXX) statement worked when compiling the wamArm directory, but failed when compiling the library on the yarp devices directory.<br>
<br>Anyhow, I'm more concerned on the first issue there, although I don't really know if it's a cmake issue, a yarp issue or both. Any kind of help would be highly appreciated as well as some guidelines on the proper way to do that.<br>
<br>Thanks for your wisdom,<br><font color="#888888">
<br>Pol Monsó<br><br>
</font></div><br>