[CMake] Re: RPATH and $ORIGIN
Iker Arizmendi
iker at research.att.com
Thu Jan 17 12:22:57 EST 2008
I did try $$ and it helps, but not always (see the end of
the original post). The problem is that $ symbols that are
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
--
Iker Arizmendi
AT&T Labs - Research
Speech and Image Processing Lab
e: iker at research.att.com
w: http://research.att.com
p: 973-360-8516
More information about the CMake
mailing list