From 0b1c4574bfbf0f26fc63e8cda61a746089faa65b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 19 Mar 2019 16:31:49 +0000 Subject: [PATCH] Add option to replace TPL absolute paths with library names This should help with relocatability: instead of generating eccodes-config.cmake with an absolute path to Third Party Libraries (TPLs) (e.g. /lib/x86_64-linux-gnu/libm.so.6) we have the option to use the library name instead (e.g. -lm). We also use library names in eccodes-targets.cmake and eccodes.pc if the option is set. The motivation is so that we can distribute packages with conda-forge. Without this change, the conda-forge build leaves its build path in the files above. When we come to build another package downstream, e.g. Magics, we are unable to find the ecCodes libraries because the absolute paths to the TPLs are no longer valid. Using library names instead lets cmake find the TPLs on the downstream build system. --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c81aaaace..ac1069483 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,6 +351,21 @@ get_directory_property( COMPILE_DEFINITIONS ECCODES_DEFINITIONS ) foreach( _tpl ${ECCODES_TPLS} ) string( TOUPPER ${_tpl} TPL ) if( ${TPL}_FOUND ) + if( REPLACE_TPL_ABSOLUTE_PATHS ) + # replace TPL absolute paths with their library names + # this helps make ecCodes relocatable + set( _TMP "" ) + + foreach( _lib ${${TPL}_LIBRARIES} ) + get_filename_component( _lib_name ${_lib} NAME_WE ) + string( REGEX REPLACE "^lib" "" _name ${_lib_name} ) + list( APPEND _TMP "-l${_name}" ) + endforeach() + + set( ${TPL}_LIBRARIES ${_TMP} ) + set( _TMP "" ) + endif() + list( APPEND ECCODES_EXTRA_DEFINITIONS ${${TPL}_DEFINITIONS} ) list( APPEND ECCODES_EXTRA_INCLUDE_DIRS ${${TPL}_INCLUDE_DIRS} ${${TPL}_INCLUDE_DIR} ) list( APPEND ECCODES_EXTRA_LIBRARIES ${${TPL}_LIBRARIES} )