Browse Source

modules: skip all target setup in FindMagnum if the component isn't found.

Before, if e.g. find_package(Magnum REQUIRED Vk) was called and the
installed Magnum didn't have Magnum::Vk enabled at all, it would still
try to call find_package(Vulkan) and do all other setup which could then
fail as well, resulting in way too many noise printed.

Now the decision about the _FOUND variable is moved all the way to the
top, and the actual target setup is only done afterwards.
pull/650/head
Vladimír Vondruš 2 years ago
parent
commit
f7079cd174
  1. 110
      modules/FindMagnum.cmake

110
modules/FindMagnum.cmake

@ -563,6 +563,15 @@ if(Magnum_FIND_COMPONENTS)
list(REMOVE_DUPLICATES Magnum_FIND_COMPONENTS) list(REMOVE_DUPLICATES Magnum_FIND_COMPONENTS)
endif() endif()
# Special cases of include paths. Libraries not listed here have a path suffix
# and include name derived from the library name in the loop below.
set(_MAGNUM_MATERIALTOOLS_INCLUDE_PATH_NAMES PhongToPbrMetallicRoughness.h)
set(_MAGNUM_MESHTOOLS_INCLUDE_PATH_NAMES CompressIndices.h)
set(_MAGNUM_OPENGLTESTER_INCLUDE_PATH_SUFFIX Magnum/GL)
set(_MAGNUM_VULKANTESTER_INCLUDE_PATH_SUFFIX Magnum/Vk)
set(_MAGNUM_PRIMITIVES_INCLUDE_PATH_NAMES Cube.h)
set(_MAGNUM_SCENETOOLS_INCLUDE_PATH_NAMES Hierarchy.h)
# Find all components. Maintain a list of components that'll need to have # Find all components. Maintain a list of components that'll need to have
# their optional dependencies checked. # their optional dependencies checked.
set(_MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD ) set(_MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD )
@ -579,9 +588,20 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS) if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS)
add_library(Magnum::${_component} UNKNOWN IMPORTED) add_library(Magnum::${_component} UNKNOWN IMPORTED)
# Set library defaults, find the library # Include path names to find, unless specified above already.
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/${_component}) # Application and context libraries are a special case as well.
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h) if(_component MATCHES ".+Application")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
elseif(_component MATCHES ".+Context")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES GLContext.h)
endif()
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/${_component})
endif()
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h)
endif()
# Try to find both debug and release version # Try to find both debug and release version
find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG Magnum${_component}-d) find_library(MAGNUM_${_COMPONENT}_LIBRARY_DEBUG Magnum${_component}-d)
@ -600,7 +620,9 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Audio importer class is Audio::*Importer, thus we need to # Audio importer class is Audio::*Importer, thus we need to
# convert *AudioImporter.h to *Importer.h # convert *AudioImporter.h to *Importer.h
string(REPLACE "AudioImporter" "Importer" _MAGNUM_${_COMPONENT}_HEADER_NAME "${_component}") string(REPLACE "AudioImporter" "Importer" _MAGNUM_${_COMPONENT}_HEADER_NAME "${_component}")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_MAGNUM_${_COMPONENT}_HEADER_NAME}.h) if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_MAGNUM_${_COMPONENT}_HEADER_NAME}.h)
endif()
# ShaderConverter plugin specific name suffixes # ShaderConverter plugin specific name suffixes
elseif(_component MATCHES ".+ShaderConverter$") elseif(_component MATCHES ".+ShaderConverter$")
@ -627,8 +649,10 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fontconverters) set(_MAGNUM_${_COMPONENT}_PATH_SUFFIX fontconverters)
endif() endif()
# Don't override the exception for *AudioImporter plugins # Include path names to find, unless specified above
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX MagnumPlugins/${_component}) if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX MagnumPlugins/${_component})
endif()
if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES) if(NOT _MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${_component}.h)
endif() endif()
@ -676,6 +700,23 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
continue() continue()
endif() endif()
# Find library/plugin includes
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS)
find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR
NAMES ${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES}
HINTS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
mark_as_advanced(_MAGNUM_${_COMPONENT}_INCLUDE_DIR)
endif()
# Decide if the library was found. If not, skip the rest, which
# populates the target properties and finds additional dependencies.
if(((_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS) AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR AND (MAGNUM_${_COMPONENT}_LIBRARY_DEBUG OR MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)) OR (_component IN_LIST _MAGNUM_EXECUTABLE_COMPONENTS AND MAGNUM_${_COMPONENT}_EXECUTABLE))
set(Magnum_${_component}_FOUND TRUE)
else()
set(Magnum_${_component}_FOUND FALSE)
continue()
endif()
# Library location for libraries/plugins # Library location for libraries/plugins
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS) if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS)
if(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE) if(MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)
@ -695,8 +736,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Applications # Applications
if(_component MATCHES ".+Application") if(_component MATCHES ".+Application")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
# Android application dependencies # Android application dependencies
if(_component STREQUAL AndroidApplication) if(_component STREQUAL AndroidApplication)
find_package(EGL) find_package(EGL)
@ -859,9 +898,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# Context libraries # Context libraries
elseif(_component MATCHES ".+Context") elseif(_component MATCHES ".+Context")
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Platform)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES GLContext.h)
# GLX context dependencies # GLX context dependencies
if(_component STREQUAL GlxContext) if(_component STREQUAL GlxContext)
# With GLVND (since CMake 3.10) we need to explicitly link to # With GLVND (since CMake 3.10) we need to explicitly link to
@ -928,40 +964,17 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
INTERFACE_LINK_LIBRARIES OpenGLES3::OpenGLES3) INTERFACE_LINK_LIBRARIES OpenGLES3::OpenGLES3)
endif() endif()
# MaterialTools library # No special setup for MaterialTools library
elseif(_component STREQUAL MaterialTools) # No special setup for MeshTools library
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES PhongToPbrMetallicRoughness.h) # No special setup for OpenGLTester library
# No special setup for VulkanTester library
# MeshTools library # No special setup for Primitives library
elseif(_component STREQUAL MeshTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h)
# OpenGLTester library
elseif(_component STREQUAL OpenGLTester)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/GL)
# VulkanTester library
elseif(_component STREQUAL VulkanTester)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Magnum/Vk)
# Primitives library
elseif(_component STREQUAL Primitives)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h)
# No special setup for SceneGraph library # No special setup for SceneGraph library
# No special setup for SceneTools library
# SceneTools library
elseif(_component STREQUAL SceneTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Hierarchy.h)
# No special setup for ShaderTools library # No special setup for ShaderTools library
# No special setup for Shaders library # No special setup for Shaders library
# No special setup for Text library # No special setup for Text library
# No special setup for TextureTools library
# TextureTools library
elseif(_component STREQUAL TextureTools)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Atlas.h)
# No special setup for Trade library # No special setup for Trade library
# Vk library # Vk library
@ -982,14 +995,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# No special setup for TgaImporter plugin # No special setup for TgaImporter plugin
# No special setup for WavAudioImporter plugin # No special setup for WavAudioImporter plugin
# Find library/plugin includes
if(_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS)
find_path(_MAGNUM_${_COMPONENT}_INCLUDE_DIR
NAMES ${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES}
HINTS ${MAGNUM_INCLUDE_DIR}/${_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX})
mark_as_advanced(_MAGNUM_${_COMPONENT}_INCLUDE_DIR)
endif()
# Automatic import of static plugins. Skip in case the include dir was # Automatic import of static plugins. Skip in case the include dir was
# not found -- that'll fail later with a proper message. Skip it also # not found -- that'll fail later with a proper message. Skip it also
# if the include dir doesn't contain the generated configure.h, which # if the include dir doesn't contain the generated configure.h, which
@ -1031,13 +1036,6 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
list(APPEND _MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD ${_component}) list(APPEND _MAGNUM_OPTIONAL_DEPENDENCIES_TO_ADD ${_component})
endif() endif()
endif() endif()
# Decide if the library was found
if(((_component IN_LIST _MAGNUM_LIBRARY_COMPONENTS OR _component IN_LIST _MAGNUM_PLUGIN_COMPONENTS) AND _MAGNUM_${_COMPONENT}_INCLUDE_DIR AND (MAGNUM_${_COMPONENT}_LIBRARY_DEBUG OR MAGNUM_${_COMPONENT}_LIBRARY_RELEASE)) OR (_component IN_LIST _MAGNUM_EXECUTABLE_COMPONENTS AND MAGNUM_${_COMPONENT}_EXECUTABLE))
set(Magnum_${_component}_FOUND TRUE)
else()
set(Magnum_${_component}_FOUND FALSE)
endif()
endif() endif()
# Global aliases for Windowless*Application, *Application and *Context # Global aliases for Windowless*Application, *Application and *Context

Loading…
Cancel
Save