# (c) 2021 Copyright, Real-Time Innovations, Inc. All rights reserved. # No duplications, whole or partial, manual or electronic, may be made # without express written permission. Any such copies, or revisions thereof, # must display this notice unaltered. # This code contains trade secrets of Real-Time Innovations, Inc. #[[.rst: .. _connextdds_get_shared_library_id: ConnextDdsGetSharedLibraryId ---------------------------- connextdds_get_shared_library_id ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Get a shared library's identifier:: connextdds_get_shared_library_id( LIBRARY IDENTIFIER ) Helper function to extract the shared library ID. #]] include(FindPackageHandleStandardArgs) include(ConnextDdsImportedTargets) function(connextdds_get_shared_library_id library outvar) if(BUILD_SHARED_LIBS) if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # We use `otool` for this task. # otool: object file displaying tool. find_program(OTOOL NAMES "otool" DOC "The otool program" ) if(NOT OTOOL) connextdds_log_message(FATAL_ERROR "otool not found") endif() execute_process( COMMAND ${OTOOL} -D ${library} -X OUTPUT_VARIABLE otool_output OUTPUT_STRIP_TRAILING_WHITESPACE RESULT_VARIABLE otool_retcode ) # If everything goes properly, the return code is 0 if(otool_retcode) connextdds_log_message(FATAL_ERROR "Failed to run otool") endif() string(REPLACE "\n" "" shared_library_id ${otool_output}) # Get the path to the real library set(${outvar} "${shared_library_id}" PARENT_SCOPE) elseif(NOT WIN32) # Get the path to the real library get_filename_component( resolved_library_full ${library} REALPATH ) set(${outvar} ${resolved_library_full} PARENT_SCOPE) else() connextdds_log_message( FATAL_ERROR "This functionality is not supported in Windows" ) endif() else() connextdds_log_message( FATAL_ERROR "This functionality is only supported for shared libs" ) endif() endfunction()