[CMake] Re: RPATH and $ORIGIN

James Bigler bigler at cs.utah.edu
Thu Jan 17 12:54:24 EST 2008


On Jan 17, 2008, at 10:22 AM, Iker Arizmendi wrote:

> I did try $$ and it helps, but not always (see the end of
> the original post). The problem is that $ symbols that are

I asked if you had tried various permutations of escapes with the  
original command [SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}: 
$ORIGIN/../xxx")] not the ones with the hard coded -Wl,-rpath.  From  
your original email it appears you only tried various permutations  
with the setting the linker path directly:

"
To get around the two problems above I tried setting the linker
flag variables directly:

    SET (CMAKE_EXE_LINKER_FLAGS
    "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN/../xxx/'" )

    SET (CMAKE_SHARED_LINKER_FLAGS
    "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN/../xxx'" )

"

I'm glad you found a work around, but I hope someone from Kitware  
would pipe in on how they think this should be done or if this is a bug.

It could be you need \\$ instead of $$ also.

James

> part of the _value_ of the CMake *_LINKER_FLAGS variables
> are treated using rules that aren't clear at all (at least
> to me). On my system, a single $ is all that's needed for
> shared library linker flags but $$ is required for exe
> linker flags. But on another system the situation is the
> opposite (shared libs get $$, exes get $).
>
> For the time being, I'm using the macro below to paper over
> the differences (on Linux, at least).
>
> Iker
>
> # =========================================================
> MACRO (APPEND_CMAKE_INSTALL_RPATH RPATH_DIRS)
>   IF (NOT ${ARGC} EQUAL 1)
>     MESSAGE(SEND_ERROR "APPEND_CMAKE_INSTALL_RPATH takes 1 argument")
>   ENDIF (NOT ${ARGC} EQUAL 1)
>   FOREACH ( RPATH_DIR ${RPATH_DIRS} )
>     IF ( NOT ${RPATH_DIR} STREQUAL "" )
>        FILE( TO_CMAKE_PATH ${RPATH_DIR} RPATH_DIR )
>        STRING( SUBSTRING ${RPATH_DIR} 0 1 RPATH_FIRST_CHAR )
>        IF ( NOT ${RPATH_FIRST_CHAR} STREQUAL "/" )
>          # relative path; CMake handling for these is unclear,
>          # add them directly to the linker line. Add both $ORIGIN
>          # and $$ORIGIN to ensure correct behavior for exes and
>          # shared libraries.
>          SET ( RPATH_DIR "$ORIGIN/${RPATH_DIR}:$$ORIGIN/$ 
> {RPATH_DIR}" )
>          SET ( CMAKE_EXE_LINKER_FLAGS
>                "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'${RPATH_DIR}'" )
>          SET ( CMAKE_SHARED_LINKER_FLAGS
>                "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'$ 
> {RPATH_DIR}'" )
>        ELSE ( NOT ${RPATH_FIRST_CHAR} STREQUAL "/" )
>          # absolute path
>          SET ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:$ 
> {RPATH_DIR}" )
>        ENDIF ( NOT ${RPATH_FIRST_CHAR} STREQUAL "/" )
>     ENDIF ( NOT ${RPATH_DIR} STREQUAL "" )
>   ENDFOREACH ( RPATH_DIR )
> ENDMACRO ( APPEND_CMAKE_INSTALL_RPATH )
>
> The macro takes a list of paths and can be used like this:
>
>    APPEND_CMAKE_INSTALL_RPATH(".;../../;/usr/local/lib")
>
> > Oh, sorry.  Rereading your mail message more closely, you want a "$"
> > character to pass through properly.
> >
> > Did you try "$$" in the original code (not the one with the  
> single quotes)?
> >
> >     SET(CMAKE_INSTALL_RPATH
> >        "${CMAKE_INSTALL_RPATH}:$$ORIGIN/../xxx")
> >
> > Or perhaps other stuff like on this recent wiki addition?
> >
> > http://www.cmake.org/Wiki/CMake:VariablesListsStrings#Escaping
> >
> > There was a recent thread called "how to escape the $ dollar sign?"
> >
> > James
>


More information about the CMake mailing list