Skip to content

Commit

Permalink
Fix unusual error when printing target properties on edge-case import…
Browse files Browse the repository at this point in the history
…ed interface libraries.
  • Loading branch information
DavidAce committed May 31, 2021
1 parent 522db66 commit 8a4a23d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions cmake/PrintTargetProperties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ cmake_minimum_required(VERSION 3.14)

# Get all propreties that cmake supports
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
list(APPEND CMAKE_PROPERTY_LIST IMPORTED_LOCATION IMPORTED_LOCATION_RELEASE IMPORTED_LOCATION_DEBUG)

# Convert command output into a CMake list
STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
# Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i
#list(FILTER CMAKE_PROPERTY_LIST EXCLUDE REGEX "^LOCATION$|^LOCATION_|_LOCATION$")

list(FILTER CMAKE_PROPERTY_LIST EXCLUDE REGEX "^LOCATION$|^LOCATION_|_LOCATION$")
# For some reason, "TYPE" shows up twice - others might too?
list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST)

Expand All @@ -26,16 +25,12 @@ foreach(prop ${CMAKE_PROPERTY_LIST})
endforeach()

function(print_properties)
foreach(prop ${CMAKE_PROPERTY_LIST})
message(${prop})
endforeach()
endfunction(print_properties)
message ("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}")
endfunction()

function(print_whitelisted_properties)
foreach(prop ${CMAKE_WHITELISTED_PROPERTY_LIST})
message(${prop})
endforeach()
endfunction(print_whitelisted_properties)
message ("CMAKE_WHITELISTED_PROPERTY_LIST = ${CMAKE_WHITELISTED_PROPERTY_LIST}")
endfunction()

function(print_target_properties tgt)
if(NOT TARGET ${tgt})
Expand All @@ -44,7 +39,7 @@ function(print_target_properties tgt)
endif()

get_target_property(target_type ${tgt} TYPE)
if(target_type MATCHES "INTERFACE" OR target_type MATCHES "EXECUTABLE")
if(target_type MATCHES "INTERFACE_LIBRARY" OR target_type MATCHES "EXECUTABLE")
set(PROP_LIST ${CMAKE_WHITELISTED_PROPERTY_LIST})
else()
set(PROP_LIST ${CMAKE_PROPERTY_LIST})
Expand All @@ -58,5 +53,5 @@ function(print_target_properties tgt)
get_target_property(propval ${tgt} ${prop})
message (STATUS "${tgt} ${prop} = ${propval}")
endif()
endforeach(prop)
endfunction(print_target_properties)
endforeach()
endfunction()

0 comments on commit 8a4a23d

Please sign in to comment.