| cmake_policy(SET CMP0057 NEW) | |
| include("${dir}/paths-${config}.cmake") | |
| function(check_rpath file expected) | |
| if(format STREQUAL "ELF") | |
| file(READ_ELF "${file}" RPATH rpath RUNPATH runpath CAPTURE_ERROR error) | |
| if(error) | |
| message(FATAL_ERROR "Cannot read runtime paths from ${file}: ${error}") | |
| endif() | |
| string(REPLACE ":" ";" paths "${rpath};${runpath}") | |
| else() | |
| execute_process(COMMAND "${otool}" -l "${file}" | |
| RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error) | |
| if(result) | |
| message(FATAL_ERROR "Cannot read runtime paths from ${file}: ${error}") | |
| endif() | |
| string(REGEX MATCHALL "cmd LC_RPATH[^\n]*\n[^\n]*\n[^\n]*" commands "${output}") | |
| set(paths) | |
| foreach(command IN LISTS commands) | |
| string(REGEX REPLACE ".*path ([^\n]*) [(]offset [0-9]+[)].*" "\\1" path "${command}") | |
| list(APPEND paths "${path}") | |
| endforeach() | |
| endif() | |
| if(NOT expected IN_LIST paths) | |
| message(FATAL_ERROR "Expected runtime path '${expected}' in ${file}, got '${paths}'") | |
| endif() | |
| # Some toolchains add their own runtime library directories, so only reject | |
| # unexpected entries under the /cmake/ prefix owned by this fixture. | |
| foreach(path IN LISTS paths) | |
| if(path MATCHES "^/cmake/" AND NOT path STREQUAL expected) | |
| message(FATAL_ERROR "Unexpected runtime path '${path}' in ${file}") | |
| endif() | |
| endforeach() | |
| endfunction() | |
| foreach(file IN LISTS build_files) | |
| get_filename_component(name "${file}" NAME) | |
| check_rpath("${file}" "/cmake/build/${name}/${config}") | |
| check_rpath("${dir}/install/bin/${name}" "/cmake/install/${name}/${config}") | |
| endforeach() |