Skip to content

Commit

Permalink
Add sharedness-check to target_get_dynamic_library
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr authored and sezero committed Sep 19, 2022
1 parent 6cfda9f commit a3d843b
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions cmake/PrivateSdlFunctions.cmake
Expand Up @@ -135,13 +135,20 @@ function(win32_implib_identify_dll DEST IMPLIB)
endif()
endfunction()

function(get_actual_target)
set(dst "${ARGV0}")
set(target "${${dst}}")
get_target_property(alias "${target}" ALIASED_TARGET)
while(alias)
set(target "${alias}")
get_target_property(alias "${target}" ALIASED_TARGET)
endwhile()
set("${dst}" "${target}" PARENT_SCOPE)
endfunction()

function(target_get_dynamic_library DEST TARGET)
set(result)
get_target_property(alias "${TARGET}" ALIASED_TARGET)
while (alias)
set(TARGET "${alias}")
get_target_property(alias "${TARGET}" ALIASED_TARGET)
endwhile()
get_actual_target(TARGET)
if (WIN32)
# Use the target dll of the import library
set(props_to_check IMPORTED_IMPLIB)
Expand Down Expand Up @@ -205,7 +212,30 @@ function(target_get_dynamic_library DEST TARGET)
endif()
endforeach()
endif()
if (NOT result)
if(result)
string(TOLOWER "${result}" result_lower)
if(WIN32 OR OS2)
if(NOT result_lower MATCHES ".*dll")
message(FATAL_ERROR "\"${result}\" is not a .dll library")
endif()
elseif(APPLE)
if(NOT result_lower MATCHES ".*dylib.*")
message(FATAL_ERROR "\"${result}\" is not a .dylib shared library")
endif()
else()
if(NOT result_lower MATCHES ".*so.*")
message(FATAL_ERROR "\"${result}\" is not a .so shared library")
endif()
endif()
else()
get_target_property(target_type ${TARGET} TYPE)
if(target_type MATCHES "SHARED_LIBRARY|MODULE_LIBRARY")
# OK
elseif(target_type MATCHES "STATIC_LIBRARY|OBJECT_LIBRARY|INTERFACE_LIBRARY|EXECUTABLE")
message(SEND_ERROR "${TARGET} is not a shared library, but has type=${target_type}")
else()
message(WARNING "Unable to extract dynamic library from target=${TARGET}, type=${target_type}.")
endif()
set (result "$<TARGET_FILE_NAME:${TARGET}>")
endif()
set(${DEST} ${result} PARENT_SCOPE)
Expand Down

0 comments on commit a3d843b

Please sign in to comment.