Skip to content
Snippets Groups Projects
Unverified Commit 2ab9108b authored by Tim Kaune's avatar Tim Kaune
Browse files

Fix error when multiple targets are given

The existence check still assumed a single target.
Refactor some other parts of the macro, too.
parent 0fabd2ee
No related branches found
No related tags found
No related merge requests found
#[[ #[[
MIT License MIT License
Copyright (c) 2022 Tim Haase Copyright (c) 2024 Tim Kaune
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
...@@ -96,35 +96,69 @@ macro(load_static_shared_targets) ...@@ -96,35 +96,69 @@ macro(load_static_shared_targets)
_static_shared_load_targets(STATIC) _static_shared_load_targets(STATIC)
# BUILD_SHARED_LIBS variable set to ON # BUILD_SHARED_LIBS variable set to ON
elseif (BUILD_SHARED_LIBS) elseif (BUILD_SHARED_LIBS)
# If shared target is installed, include it. # If shared targets are installed, include them.
if (EXISTS "${${CMAKE_FIND_PACKAGE_NAME}_SHARED_TARGETS}") # Otherwise at least load the static targets
_static_shared_load_targets(SHARED) _static_shared_load_targets(SHARED ALTERNATIVE STATIC)
# Otherwise at least load the static target
else ()
_static_shared_load_targets(STATIC)
endif ()
# BUILD_SHARED_LIBS variable set to OFF # BUILD_SHARED_LIBS variable set to OFF
else () else ()
# If static target is installed, include it. # If static targets are installed, include them.
if (EXISTS "${${CMAKE_FIND_PACKAGE_NAME}_STATIC_TARGETS}") # Otherwise at least load the shared targets
_static_shared_load_targets(STATIC) _static_shared_load_targets(STATIC ALTERNATIVE SHARED)
# Otherwise at least load the shared target
else ()
_static_shared_load_targets(SHARED)
endif ()
endif () endif ()
unset(${CMAKE_FIND_PACKAGE_NAME}_KNOWN_COMPS)
unset(${CMAKE_FIND_PACKAGE_NAME}_COMP_static)
unset(${CMAKE_FIND_PACKAGE_NAME}_COMP_shared)
unset(${CMAKE_FIND_PACKAGE_NAME}_ARGUMENT_KEYWORDS)
unset(${CMAKE_FIND_PACKAGE_NAME}_STATIC_TARGETS)
unset(${CMAKE_FIND_PACKAGE_NAME}_SHARED_TARGETS)
endmacro() endmacro()
# Macro to check, if the requested file with the exported targets is installed. # Macro to check, if the target files for the requested type are all installed.
# Do error handling if not, include it otherwise. # If so, include them. Otherwise, try alternative type, if given. Do error
# handling, if not.
macro(_static_shared_load_targets TYPE) macro(_static_shared_load_targets TYPE)
foreach (${CMAKE_FIND_PACKAGE_NAME}_TARGET ${${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGETS}) cmake_parse_arguments(${CMAKE_FIND_PACKAGE_NAME} "" "ALTERNATIVE" "" ${ARGN})
if (NOT EXISTS "${${CMAKE_FIND_PACKAGE_NAME}_TARGET}") # We now have ${CMAKE_FIND_PACKAGE_NAME}_ALTERNATIVE variable created for us.
set(${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_FOUND TRUE)
foreach (
${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGET
IN LISTS
${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGETS
)
# Check, if any of the targets for the requested TYPE does not exist
if (NOT EXISTS "${${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGET}")
set(${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_FOUND FALSE)
break ()
endif ()
endforeach ()
# If TYPE targets are all installed, include them.
if (${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_FOUND)
foreach (
${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGET
IN LISTS
${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGETS
)
# We know they all exist.
include("${${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_TARGET}")
endforeach ()
# Otherwise at least load the ALTERNATIVE targets, if given
elseif (DEFINED ${CMAKE_FIND_PACKAGE_NAME}_ALTERNATIVE)
message(WARNING
"Requested `${TYPE}` targets for package ${CMAKE_FIND_PACKAGE_NAME} were not found. "
"Trying alternative `${${CMAKE_FIND_PACKAGE_NAME}_ALTERNATIVE}` targets."
)
_static_shared_load_targets(${${CMAKE_FIND_PACKAGE_NAME}_ALTERNATIVE})
else ()
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"${CMAKE_FIND_PACKAGE_NAME} `${TYPE}` libraries were requested but not found.") "${CMAKE_FIND_PACKAGE_NAME} `${TYPE}` libraries were requested but not found.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return() return()
endif () endif ()
include("${${CMAKE_FIND_PACKAGE_NAME}_TARGET}")
endforeach () unset(${CMAKE_FIND_PACKAGE_NAME}_${TYPE}_FOUND)
unset(${CMAKE_FIND_PACKAGE_NAME}_ALTERNATIVE)
endmacro() endmacro()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment