How can I modify RPATH for the build in cmake?

25 Views Asked by At

In a project I'm using custom precompiler as a part of a build. In this case I'm using Pro*C compiler that requires a shared library for runtime (libclntsh). The project should build on Linux Windows and macOs.

How can I modify the RPATH for the proc executable? In the best case this should by in a system independent way.

Currently I do this using a system check and then I use cmake command line tool to set the variable as follows:


# Set the correct env variable name based on the OS
if(WIN32)
    set(SystemRpathName "PATH")
elseif(APPLE)
    set(SystemRpathName "LD_LIBRARY_PATH")
elseif(UNIX)
    set(SystemRpathName "/DYLD_LIBRARY_PATH")
else()
    message(FATAL_ERROR "Unable to set RPATH: unsupported OS.")
endif()

# Now we can use the ProCCommand variable in a custom command
# suppose that we found the location of the binary and the .so earlier 
set(ProCCommand "${CMAKE_COMMAND} -E env ORACLE_HOME=${ORACLE_HOME} --modify ${SYSTEM_RPATH_NAME}=path_list_prepend:${PathToLibDir} ${PathToProCCompiler}")

I would like do it in a more system independent way if possible.

Here is a related question that tries to solve the same problem in a similar but system dependent way (only for Linux).

0

There are 0 best solutions below