Skip to content

Commit

Permalink
Bindings: Use swig_add_library instead of swig_add_module
Browse files Browse the repository at this point in the history
This is now in YCM UseSWIG version
  • Loading branch information
drdanz committed Nov 18, 2016
1 parent bed896a commit 86b118c
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ if(CREATE_JAVA)
Example1.java)
include_directories(SYSTEM ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
set(target_name jyarp)
swig_add_module(${target_name} java yarp.i)
swig_add_library(${target_name}
LANGUAGE java
SOURCES yarp.i)
if(PREPARE_CLASS_FILES)
set(CLASS_FILES)
foreach(java_file ${JAVA_SRCS})
Expand Down Expand Up @@ -213,7 +215,9 @@ if(CREATE_PYTHON)
set(CMAKE_SWIG_OUTDIR_SAVE ${CMAKE_SWIG_OUTDIR})
set(CMAKE_SWIG_OUTDIR "${CMAKE_BINARY_DIR}/lib/python")
endif()
swig_add_module(${target_name} python yarp.i)
swig_add_library(${target_name}
LANGUAGE python
SOURCES yarp.i)
target_link_libraries(_${target_name} ${PYTHON_LIBRARY})
# uncomment if we want a debug version of the library
#add_definitions(-DPy_DEBUG)
Expand Down Expand Up @@ -276,7 +280,9 @@ if(CREATE_PERL)
set(CMAKE_SWIG_OUTDIR "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_PERLDIR}")
endif()

swig_add_module(${target_name} perl5 yarp.i)
swig_add_library(${target_name}
LANGUAGE perl5
SOURCES yarp.i)
set_target_properties(${target_name} PROPERTIES PREFIX "")
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME "yarp")
if(YARP_COLLISION_AVOIDANCE)
Expand Down Expand Up @@ -315,7 +321,9 @@ endif(CREATE_PERL)

if(CREATE_CHICKEN)
set(CMAKE_SWIG_FLAGS "-Wall;-module;cyarp;${SWIG_COMMON_FLAGS}")
swig_add_module(libcyarp chicken yarp.i)
swig_add_library(libcyarp
LANGUAGE chicken
SOURCES yarp.i)
set(YARP_COLLISION_AVOIDANCE TRUE)
endif(CREATE_CHICKEN)

Expand All @@ -334,7 +342,9 @@ if(CREATE_ALLEGRO)
set(allegro_LIBS yarp-allegro.so)

set(CMAKE_SWIG_FLAGS "-Wall;-module;yarp;-identifier-converter;lispify;${SWIG_COMMON_FLAGS}")
swig_add_module(yarp-allegro allegrocl yarp.i)
swig_add_library(yarp-allegro
LANGUAGE allegrocl
SOURCES yarp.i)

string(REGEX REPLACE "\\.cl" ".lisp" allegro_DEST_FILE ${allegro_SRC_FILE})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${allegro_PROJ_FILE}
Expand All @@ -356,7 +366,9 @@ if(CREATE_TCL)
find_package(TCL REQUIRED)
include_directories(SYSTEM ${TCL_INCLUDE_PATH})
link_libraries(${TCL_LIBRARY})
swig_add_module(libtclyarp tcl yarp.i)
swig_add_library(libtclyarp
LANGUAGE tcl
SOURCES yarp.i)
set(YARP_COLLISION_AVOIDANCE TRUE)
endif(CREATE_TCL)

Expand Down Expand Up @@ -385,7 +397,9 @@ if(CREATE_CSHARP)

if(WIN32 AND NOT CYGWIN)
option(PREPARE_CLASS_FILES "Prepare NET library" ON)
swig_add_module(${target_name} csharp yarp.i)
swig_add_library(${target_name}
LANGUAGE csharp
SOURCES yarp.i)
if(PREPARE_CLASS_FILES)
add_custom_command(TARGET ${target_name}
POST_BUILD
Expand All @@ -398,7 +412,9 @@ if(CREATE_CSHARP)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
else(WIN32 AND NOT CYGWIN)
swig_add_module(${target_name} csharp yarp.i)
swig_add_library(${target_name}
LANGUAGE csharp
SOURCES yarp.i)
endif(WIN32 AND NOT CYGWIN)
set(YARP_COLLISION_AVOIDANCE TRUE)
endif(CREATE_CSHARP)
Expand All @@ -416,7 +432,9 @@ if(CREATE_RUBY)
if(YARP_COLLISION_AVOIDANCE)
set(target_name yarp_ruby)
endif()
swig_add_module(${target_name} ruby yarp.i)
swig_add_library(${target_name}
LANGUAGE ruby
SOURCES yarp.i)
swig_link_libraries(${target_name} ${RUBY_LIBRARY})
set_target_properties(${target_name} PROPERTIES PREFIX "")
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME "yarp")
Expand All @@ -434,7 +452,9 @@ if(CREATE_LUA)
find_package(Lua REQUIRED)
set(target_name yarp_lua)
include_directories(SYSTEM ${LUA_INCLUDE_DIR})
swig_add_module(${target_name} lua yarp.i)
swig_add_library(${target_name}
LANGUAGE lua
SOURCES yarp.i)
swig_link_libraries(${target_name} ${LUA_LIBRARY})
set_target_properties(${target_name} PROPERTIES PREFIX "")
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME "yarp")
Expand Down Expand Up @@ -478,7 +498,9 @@ if(CREATE_OCTAVE)
set(target_name yarp_octave)
get_filename_component(OCTAVE_INCLUDE_TOP ${OCTAVE_INCLUDE_DIR} DIRECTORY)
include_directories(SYSTEM ${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_TOP})
swig_add_module(${target_name} octave yarp.i)
swig_add_library(${target_name}
LANGUAGE octave
SOURCES yarp.i)
swig_link_libraries(${target_name} ${OCTAVE_LIBRARIES})
set_target_properties(${target_name} PROPERTIES PREFIX "")
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME "yarp")
Expand Down

15 comments on commit 86b118c

@Tobias-Fischer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @drdanz,
I get the following error: Unknown CMake command "swig_add_library".
Where does the swig_add_library come from?

Best, Tobi

@drdanz
Copy link
Member Author

@drdanz drdanz commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobias-Fischer it is in UseSWIG.cmake in cmake/ycm-0.2/cmake-next/
If it is not used there might be a problem.

I need a few information to debug this:

  • CMake version?
  • Do you have or not YCM installed?
  • Are you building the bindings with YARP or in a separate build?
  • Have you tried a clean build?

@Tobias-Fischer
Copy link
Member

@Tobias-Fischer Tobias-Fischer commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks! Here the debug info:

  • cmake version 2.8.12.2
  • YCM is installed and found (YCM_USE_CMAKE_NEXT is ON)
  • separate build (./yarp/bindings/build_python)
  • yes it happens in a clean build as well

@traversaro
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhh, I wonder how the external build is working after ba16979 ... ?_?
If you don't have some use cases for which you strongly need that behaviour, I think we should just remove the "separate build" support for building bindings, also from documentation, see #318 .

@drdanz
Copy link
Member Author

@drdanz drdanz commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@traversaro To be honest I haven't tested it yet, and it is not tested by any unit test... I just remembered about that when I saw @Tobias-Fischer comment
I agree that we should remove the "separate build" support, but I think it is still there to support binary releases that come without the bindings

@Tobias-Fischer Can you try re-building yarp and enable the binding there instead of using a separate build?

@Tobias-Fischer
Copy link
Member

@Tobias-Fischer Tobias-Fischer commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @traversaro @drdanz,
Thanks for the hint. Yes, it compiles properly if I do it directly within yarp/build. However, when I try to import yarp, it fails:

ImportError: libYARP_OS.so.1: cannot open shared object file: No such file or directory

Although it is installed:

/home/tobias/robot/yarp/build/lib/x86_64-linux-gnu/libYARP_OS.so.1
/home/tobias/robot/yarp/build_clang/lib/libYARP_OS.so.1
/usr/local/src/robot/install/yarp/lib/libYARP_OS.so.1
/usr/local/src/robot/install/yarp/lib/x86_64-linux-gnu/libYARP_OS.so.1

However, I don't have /usr/local/src/robot/install/yarp/lib/x86_64-linux-gnu/ in my LD_LIBRARY_PATH. Do I need to do this now? On another machine which has the path in its LD_LIBRARY_PATH, it all works fine.

@drdanz
Copy link
Member Author

@drdanz drdanz commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it still in x86_64-linux-gnu? That should no longer happen... Are you sure that they are not left by some older installation?

Anyway,

  • which _yarp.so version are you using, the one in the build directory or the one installed?
  • Did you change CMAKE_SKIP_INSTALL_RPATH and/or CMAKE_SKIP_RPATH in CMake?
  • Can you post the output ofobjdump -x <lib/python/_yarp.so> | grep RPATH

@drdanz
Copy link
Member Author

@drdanz drdanz commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I just noticed that the RPATH is fixed only for lua and perl, so yes, I think you have to add the path to LD_LIBRARY_PATH, even though I don't think the path is supposed to have x86_64-linux-gnu in it...

@Tobias-Fischer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I'm using the installed _yarp.so. Both CMAKE_SKIP_INSTALL_RPATH and CMAKE_SKIP_RPATH are OFF.
Output of objdump: RPATH $ORIGIN/:$ORIGIN/../lib/x86_64-linux-gnu:$ORIGIN/../:/usr/local/cuda/lib64

@Tobias-Fischer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh I see. Shall I open an issue to fix the RPATH for the other bindings as well?

@drdanz
Copy link
Member Author

@drdanz drdanz commented on 86b118c Nov 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now I definitely believe there's an issue with this x86_64-linux-gnu.
Is this a very old build or a new one? Can you try to remove the CMAKE_INSTALL_LIBDIR variable from ccmake (select it and hit 'd') and see how it is re-created? You should see lib/x86_64-linux-gnu, if it is working correctly it should become just lib.

@Tobias-Fischer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the build folder and recompiled (and installed) from scratch. The output of objdump is now: RPATH $ORIGIN/:$ORIGIN/../lib:$ORIGIN/../. I still get the error ImportError: libYARP_OS.so.1: cannot open shared object file: No such file or directory but I guess this is expected if the RPATH is not fixed for python yet.

@drdanz
Copy link
Member Author

@drdanz drdanz commented on 86b118c Nov 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, I'm a bit less worried now 😜
I will continue the discussion on the PR.

@frank-foerster
Copy link

@frank-foerster frank-foerster commented on 86b118c Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran into the very same issue as @Tobias-Fischer above when trying to compile the Python bindings separately from within $YARP_ROOT/bindings/build. So far I couldn't fix the build, even after installing YCM and hinting cmake manually to its installation directory. I also tried to copy the relevant *.cmake files from YCM in to YARP's cmake dir in the hope it would pick them up but that didn't do any good neither.

I can use the python bindings generated by global build and located in $YARP_DIR/lib/python2.7/dist-packages, but the difference to using separately compiled bindings appears to be that the generated yarp python module doesn't contain the comments necessary for generating the interface documentation with pydoc.
When I run pydoc on that yarp.py it just tells me that no Python documentation was found.
Am I doing something wrong?

Also: is there a more elegant way to let YARP know where YCM is installed like via some environment variable akin to $YARP_ROOT or $OPENCV_ROOT, etc.? I tried to locate the cmake resource finder for YCM in YARP but couldn't find it, so I couldn't inspect whether it reads out some environment variable.
In my current built I figured out by trial and error to set YCM_DIR in YARP's cmake to $YCM_DIR/share/YCM/cmake, with $YCM_DIR referring to my YCM installation directory as specified in in cmake. But that doesn't solve the "Unkown cmake command" cmake error when activating the Python bindings for building.
Note, that I use a non-standard installation directory in the `make install' step of the YCM built, so I need to tell the YARP and icub-main builds manually where my YDM installation directory is located.

Side note: Prior to doing this I upgraded (git pull'ed) YARP, icub-main, ycm, and built the whole batch anew (including deleting all old built artifacts prior to building anew).

@frank-foerster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a mistake when calling pydoc, so the interface documentation can be generated after all.
I ran pydoc -w yarp.py instead of pydoc -w yarp. Instead of a warning you get the above message that no documentation was found.

Please sign in to comment.