[CMake] RPATH on Mac

tog guillaume.alleon at gmail.com
Tue Apr 19 11:21:37 EDT 2011


Hi Mike

Thanks for this very helpful answer.
I am nevertheless still facing few problems. My project contains:
  - a shared library
  - an executable using the shared lib
  - a plugin lib (loaded using dylib)

I have modified my exec target to be
ADD_EXECUTABLE(main MACOSX_BUNDLE  main.cpp sub.cpp)
then I have something like
INSTALL(TARGETS main  BUNDLE    DESTINATION Applications  RUNTIME)

the make install does create Application.app and add the main exec.

Fir the lib I am facing 2 problems:
  1- I don't understand how to add them to the bundle. They are both
created using:

      ADD_LIBRARY(foo ${EXAMPLE_LIBRARY_TYPE} foo.cpp)
EXAMPLE_LIBRARY_TYPE=SHARED

      INSTALL(TARGETS foo
              RUNTIME DESTINATION ${EXAMPLE_INSTALL_LIB_DIR} COMPONENT
RuntimeLibraries
              LIBRARY DESTINATION ${EXAMPLE_INSTALL_LIB_DIR} COMPONENT
RuntimeLibraries
              ARCHIVE DESTINATION ${EXAMPLE_INSTALL_LIB_DIR} COMPONENT
Development

      nothing is added to the app.

  2- According to the doc. For a library loaded at runtime the doc
suggests to use MODULE but I end up having this error. Is that
supported on Mac

Linking CXX shared module libplugin.so
cd /Users/alleon/PROJECTS/example_build/plugin && "/Applications/CMake
2.8-4.app/Contents/bin/cmake" -E cmake_link_script
CMakeFiles/plugin.dir/link.txt --verbose=1
/usr/bin/c++   -bundle -Wl,-headerpad_max_install_names
-compatibility_version 1.0.0 -current_version 1.2.3 -o
libplugin.1.2.3.so CMakeFiles/plugin.dir/plugin.cpp.o
i686-apple-darwin10-g++-4.2.1: -compatibility_version only allowed
with -dynamiclib
make[2]: *** [plugin/libplugin.1.2.3.so] Error 1


Thanks
Guillaume


On Sat, Apr 16, 2011 at 6:51 PM, Michael Jackson
<mike.jackson at bluequartz.net> wrote:
> You need to process your executable with "install_name_tool" either manually or using the "BundleUtilities" functionality built into CMake. Note that there is a bug in the current CMake 2.8.4 that will NOT allow bundleUtilities to work on a command line type app. Your app MUST be in a .app bundle. If you search for BUndleUtilities on the Wiki there is a small Qt based project that shows a simple use of BundleUtilities.
>
> Hope that helps.
> ___________________________________________________________
> Mike Jackson                      www.bluequartz.net
> Principal Software Engineer       mike.jackson at bluequartz.net
> BlueQuartz Software               Dayton, Ohio
>
>
>
> On Apr 15, 2011, at 7:17 AM, tog wrote:
>
>> Dear all
>>
>> I have a project in which I would like to use rpath on Mac OS.
>> Everything is going fine if I am building everything manually (i.e.
>> without CMake)
>>
>> With CMake all is fine for the libs between the build and the
>> installation, all libs are processed with install_name_tool.
>> But nothing is done for the executable (checked from cmake_install.cmake)
>>
>> In the build phase, I don't see any -Wl,-rpath,... added on the command line.
>>
>> What do I miss there ?
>>
>> I have been using:
>>
>> SET(CMAKE_SKIP_BUILD_RPATH FALSE)
>> SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
>> SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
>> SET(CMAKE_INSTALL_RPATH "${EXAMPLE_INSTALL_LIB_DIR}")
>>
>> as indicated in the Wiki.
>>
>> Is there  tool on the Mac to get rpath from the executable ?
>>
>>
>> Thanks for your help
>> Guillaume
>>
>> --
>> PGP KeyID: 2048R/EA31CFC9  subkeys.pgp.net
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>



-- 
PGP KeyID: 2048R/EA31CFC9  subkeys.pgp.net


More information about the CMake mailing list