title: Setting the RPATH for external projects?
body: <p>I'm trying to setup a project where my repository imports all dependencies as git submodules for easy development. My colleagues can simply clone the repo, <code>git submodule update --init --recursive</code>, <code>cmake .</code> and <code>make</code> and have a fully working dev environment in place. The directory structure is setup as a superbuild with a <code>CMakeLists.txt</code> at the top level that builds all the submodules using <code>ExternalProject_Add</code>, resulting in the following structure:</p>
  
  <pre><code>root
   - CMakeLists.txt (superbuild)
   - git_submodule_1
   - git_submodule_2
   - usr
      - lib
      - include
   - my_project
      - CMakeLists.txt (project)
  </code></pre>
  
  <p>The <code>CMakeLists.txt</code> looks something like this:</p>
  
  <pre><code>SET (INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/usr)
  
  # Install git_submodule_1 with ${INSTALL_PREFIX} as a prefix
  ExternalProject_Add( ... )
  
  # Install git_submodule_2 with ${INSTALL_PREFIX} as a prefix
  ExternalProject_Add( ... )
  
  ExternalProject_Add(
      MyProject
      PREFIX ${CMAKE_SOURCE_DIR}/my_project
      DEPENDS ExternalProject_git_submodule_1 ExternalProject_git_submodule_2
  
      SOURCE_DIR ${CMAKE_SOURCE_DIR}/my_project
      CMAKE_ARGS
        -DCMAKE_LIBRARY_PATH:string=${INSTALL_PREFIX}/lib
        -DCMAKE_PROGRAM_PATH:string=${INSTALL_PREFIX}/bin
        -DCMAKE_INCLUDE_PATH:string=${INSTALL_PREFIX}/include
  
      # etc, nothing nonstandard here
  )
  </code></pre>
  
  <p>The build process works great. I <code>make</code> at the top level, dependencies are installed into <code>usr</code>, I <code>cd</code> into <code>my_project</code>, I do my work, all the built shared libraries are found and linked, I'm happy. </p>
  
  <p>However, when I go to run an executable on OS X built inside <code>my_project</code>, I find that the dynamic libs placed into the <code>usr/lib</code> directory cannot be found. It appears that CMake only sets the <code>RPATH</code> for libraries <em>built within the project directory</em>, which in this case is just <code>my_project</code>. </p>
  
  <p>Is there any way I can add the custom install location to the the <code>RPATH</code> for build-time libraries and executables? </p>
  
  <p>A few notes:</p>
  
  <ul>
  <li>This issue only appears to affect OS X. Linux doesn't exhibit these problems at all.</li>
  <li>Setting the <code>DYLD_LIBRARY_PATH</code> to include the custom install location works. However, this adds an additional step to the setup, and it gets annoying when I try to debug installation issues. </li>
  <li>Setting the <code>DYLD_FALLBACK_LIBRARY_PATH</code> also works, although that's also not a good option because it also adds an additional set, and homebrew users won't like this option. </li>
  </ul>