Skip to content

Instantly share code, notes, and snippets.

@daverigby
Created November 16, 2018 12:09
Show Gist options
  • Save daverigby/d7545ace450b66b2099374b0a3af2840 to your computer and use it in GitHub Desktop.
Save daverigby/d7545ace450b66b2099374b0a3af2840 to your computer and use it in GitHub Desktop.
# Need to install libasan to be able to run sanitized
# binaries on a machine different to the build machine
# (for example for RPM sanitized packages).
# First need to get the compiler search dirs; then locate
# where the library file exists.
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-search-dirs
OUTPUT_VARIABLE cc_search_dirs)
# Extract the line listing the library paths
string(REGEX MATCH "libraries: =(.*)\n" _ ${cc_search_dirs})
# CMAKE expects lists to be semicolon-separated instead of colon.
string(REPLACE ":" ";" cc_library_dirs ${CMAKE_MATCH_1})
find_file(asan_lib libasan.so.4
PATHS ${cc_library_dirs})
if(NOT asan_lib)
message(FATAL_ERROR "ASan library not found.")
endif()
message(STATUS "Found libasan at: ${asan_lib}")
install(FILES ${asan_lib} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
if(IS_SYMLINK ${asan_lib})
# Often a shared library is actually a symlink to a versioned file - e.g.
# libasan.so.4 -> libasan.so.4.0.0
# In which case we also need to install the real file.
get_filename_component(asan_lib_realpath ${asan_lib} REALPATH)
install(FILES ${asan_lib_realpath} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment