With CMake you can do something like:

 add_library(foo ....)

 add_executable( bar .. )
 target_link_libraries (bar foo)

and CMake will make sure all the link paths are correct. There generally should not be a need to set the "install_name" of built libraries _within_ a build tree.

Now, setting the install_name for an installation is a different matter. If you are creating OS X .app bundles then you should look into CMake's "BundleUtilities" module that "fixes up" OS X .app bundles for self contained deployment.

If you are building libraries that you are installing onto your system to mimic an actual installation on another machine then I have the following bit of code in my CMakeLists.txt file for each library project:

IF (APPLE)
OPTION (MXA_BUILD_WITH_INSTALL_NAME "Build Libraries with the install_name set to the installation prefix. This is good if you are going to run from the installation location" OFF)
  IF(MXA_BUILD_WITH_INSTALL_NAME)
      SET_TARGET_PROPERTIES(${MXADATAMODEL_LIB_NAME}
         PROPERTIES
LINK_FLAGS "-current_version ${${PROJECT_NAME}_VERSION} - compatibility_version ${${PROJECT_NAME}_VERSION}"
         INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
         BUILD_WITH_INSTALL_RPATH ${MXA_BUILD_WITH_INSTALL_NAME}
      )
  ENDIF(MXA_BUILD_WITH_INSTALL_NAME)
ENDIF (APPLE)

So when I want to do an actual install of the project somewhere else on my system I launch "ccmake" or cmake-gui.app and set the MXA_BUILD_WITH_INSTALL_NAME option to ON then do a "make install" and the makefiles that cmake generates will have the correct OS X 'install_name' set for the particular CMAKE_INSTALL_PREFIX that was set during configuration.

Does any of that make sense?
_________________________________________________________
Mike Jackson                  mike.jack...@bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

On Sep 25, 2009, at 7:28 AM, Eugen-Andrei Gavriloaie wrote:

Hello,

Is there any way to tell cmake to use relative paths when linking an executable? Here some info about a sample exec:

$ otool -L ./rtmpserver/rtmpserver
./rtmpserver/rtmpserver:
/Users/shiretu/work/crtmpserver/trunk/builders/cmake/thelib/ libthelib.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8) /usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8) /Users/shiretu/work/crtmpserver/trunk/builders/cmake/common/ libcommon.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 124.1.1)


What I want is to transform

/Users/shiretu/work/crtmpserver/trunk/builders/cmake/thelib/ libthelib.dylib (compatibility version 0.0.0, current version 0.0.0)

into

thelib/libthelib.dylib (compatibility version 0.0.0, current version 0.0.0)

So, when I do

TARGET_LINK_LIBRARIES(rtmpserver thelib.....) is there any way to tell cmake to build the Makefile in such a way that the final executable will have relative references to the used libraries?

I only want to do that for the libraries in my project, not all of them (ibSystem.B.dylib,libstdc++.6.dylib, etc) should remain the same

Thank you


_______________________________________________
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

_______________________________________________
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

Reply via email to