Hamlib package finder for static and dynamic linking on Windows

This commit is contained in:
Bill Somerville 2021-04-17 02:06:47 +01:00
parent c143c2c279
commit 3591f13ff0
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F

View File

@ -11,6 +11,74 @@
# Hamlib::Hamlib - The hamlib library # Hamlib::Hamlib - The hamlib library
# #
function(dump_cmake_variables)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
if (ARGV0)
unset(MATCHED)
string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
if (NOT MATCHED)
continue()
endif()
endif()
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endfunction()
# Get all propreties that cmake supports
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
# 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$")
# For some reason, "TYPE" shows up twice - others might too?
list(REMOVE_DUPLICATES CMAKE_PROPERTY_LIST)
# build whitelist by filtering down from CMAKE_PROPERTY_LIST in case cmake is
# a different version, and one of our hardcoded whitelisted properties
# doesn't exist!
unset(CMAKE_WHITELISTED_PROPERTY_LIST)
foreach(prop ${CMAKE_PROPERTY_LIST})
if(prop MATCHES "^(INTERFACE|[_a-z]|IMPORTED_LIBNAME_|MAP_IMPORTED_CONFIG_)|^(COMPATIBLE_INTERFACE_(BOOL|NUMBER_MAX|NUMBER_MIN|STRING)|EXPORT_NAME|IMPORTED(_GLOBAL|_CONFIGURATIONS|_LIBNAME)?|NAME|TYPE|NO_SYSTEM_FROM_IMPORTED)$")
list(APPEND CMAKE_WHITELISTED_PROPERTY_LIST ${prop})
endif()
endforeach(prop)
function(print_properties)
message ("CMAKE_PROPERTY_LIST = ${CMAKE_PROPERTY_LIST}")
endfunction(print_properties)
function(print_whitelisted_properties)
message ("CMAKE_WHITELISTED_PROPERTY_LIST = ${CMAKE_WHITELISTED_PROPERTY_LIST}")
endfunction(print_whitelisted_properties)
function(print_target_properties tgt)
if(NOT TARGET ${tgt})
message("There is no target named '${tgt}'")
return()
endif()
get_target_property(target_type ${tgt} TYPE)
if(target_type STREQUAL "INTERFACE_LIBRARY")
set(PROP_LIST ${CMAKE_WHITELISTED_PROPERTY_LIST})
else()
set(PROP_LIST ${CMAKE_PROPERTY_LIST})
endif()
foreach (prop ${PROP_LIST})
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" prop ${prop})
# message ("Checking ${prop}")
get_property(propval TARGET ${tgt} PROPERTY ${prop} SET)
if (propval)
get_target_property(propval ${tgt} ${prop})
message ("${tgt} ${prop} = ${propval}")
endif()
endforeach(prop)
endfunction(print_target_properties)
include (LibFindMacros) include (LibFindMacros)
libfind_pkg_detect (Hamlib hamlib libfind_pkg_detect (Hamlib hamlib
@ -24,7 +92,9 @@ libfind_process (Hamlib)
if (NOT Hamlib_PKGCONF_FOUND) if (NOT Hamlib_PKGCONF_FOUND)
if (WIN32) if (WIN32)
set (Hamlib_LIBRARIES ${Hamlib_LIBRARIES};ws2_32) set (Hamlib_LIBRARIES ${Hamlib_LIBRARIES};${Usb_LIBRARY};ws2_32)
# pretend pkg-config worked
set (Hamlib_PKGCONF_LDFLAGS ${Usb_LIBRARY};ws2_32)
else () else ()
set (Hamlib_LIBRARIES ${Hamlib_LIBRARIES};m;dl) set (Hamlib_LIBRARIES ${Hamlib_LIBRARIES};m;dl)
endif () endif ()
@ -57,6 +127,9 @@ if (Hamlib_FOUND AND NOT TARGET Hamlib::Hamlib)
) )
endif () endif ()
dump_cmake_variables ("Hamlib")
print_target_properties (Hamlib::Hamlib)
mark_as_advanced ( mark_as_advanced (
Hamlib_INCLUDE_DIR Hamlib_INCLUDE_DIR
Hamlib_LIBRARY Hamlib_LIBRARY