BlazePascal
BlazePascal

Reputation: 401

Specify RPATH for externally built CMAKE project

How do I specify an RPATH for a project that was built externally in CMake (using 3.0.0) via ExternalProject_Add() macro?

For reference, let's say my ExternalProject is SFML. My external project call looks like:

  set(SFML_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/ext-deps/ext-sfml-build")
  set(SFML_RPATH "${SFML_INSTALL_PATH}/src/lib")
  set(SFML_CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=Release -DUSE_STATIC_LIBS:BOOL=true
    -DCMAKE_INSTALL_PREFIX:PATH=${SFML_INSTALL_PATH}
    -DCMAKE_INSTALL_RPATH:PATH=${SFML_RPATH})

  ExternalProject_Add(ext-sfml
    GIT_REPOSITORY "${SFML_REPO}"
    GIT_TAG        "${SFML_TAG}"
    URL             SFML_URL
    URL_HASH        256=${SFML_SHA256}
    CMAKE_ARGS     "${SFML_CMAKE_ARGS}"
    TMP_DIR        "${CMAKE_CURRENT_BINARY_DIR}/${EXT_DEPS_PREFIX}/ext-sfml-tmp"
    STAMP_DIR      "${CMAKE_CURRENT_BINARY_DIR}/${EXT_DEPS_PREFIX}/ext-sfml-stamp"
    INSTALL_DIR    "${CMAKE_CURRENT_BINARY_DIR}/${EXT_DEPS_PREFIX}/ext-sfml-build"
    SOURCE_DIR     "${CMAKE_CURRENT_BINARY_DIR}/${EXT_DEPS_PREFIX}/ext-sfml"
    BINARY_DIR     "${CMAKE_CURRENT_BINARY_DIR}/${EXT_DEPS_PREFIX}/ext-sfml-build"
    TEST_COMMAND "")

The error command I get when I run the build step (configuration is fine) is

Make Error at src/cmake_install.cmake:45 (file):
  file RPATH_CHANGE could not write new RPATH:

    /home/hendrix/repo/project/build/ext_deps/ext_sfml-build/lib

  to the file:

    /home/hendrix/repo/project/build/ext_deps/ext_sfml-build/bin/exe

Finally, this "/home/hendrix/repo/project/build/ext_deps/ext_sfml-build/lib" is the line I'm trying to modify. It appears that it is the value of my ${CMAKE_INSTALL_RPATH} variable but containing the install prefix of my ext-dep project and not the top-level master project.

Upvotes: 2

Views: 1214

Answers (1)

BlazePascal
BlazePascal

Reputation: 401

I figured it out (thanks to Tsyvarev's comments). The externally built project that I was using set it's own RPATH. So the string that I found in the error message was that RPATH, not any RPATH which I set in my "top-level" project.

It appears that setting the RPATH of an external project can not override that external project's internally set RPATH (if it is using CMAKE).

Upvotes: 2

Related Questions