From e9b5fb001969b73e78a77c4de5b2503f192c72b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 1 Jun 2019 19:20:34 +0200 Subject: [PATCH] modules: added FindMagnumBindings.cmake for finding the helper headers. --- CMakeLists.txt | 3 + modules/CMakeLists.txt | 30 ++++++++ modules/FindMagnumBindings.cmake | 116 +++++++++++++++++++++++++++++ modules/MagnumBindingsConfig.cmake | 26 +++++++ 4 files changed, 175 insertions(+) create mode 100644 modules/CMakeLists.txt create mode 100644 modules/FindMagnumBindings.cmake create mode 100644 modules/MagnumBindingsConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ab62473..1f15db5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,4 +43,7 @@ include(CMakeDependentOption) # Libraries to build option(WITH_PYTHON "Build Python bindings" OFF) +set(MAGNUMBINDINGS_CMAKE_MODULE_INSTALL_DIR share/cmake/MagnumBindings) + +add_subdirectory(modules) add_subdirectory(src) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 0000000..12f0cc1 --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +set(MagnumBindings_MODULES + FindMagnumBindings.cmake + MagnumBindingsConfig.cmake) + +install(FILES ${MagnumBindings_MODULES} DESTINATION ${MAGNUMBINDINGS_CMAKE_MODULE_INSTALL_DIR}) diff --git a/modules/FindMagnumBindings.cmake b/modules/FindMagnumBindings.cmake new file mode 100644 index 0000000..2a3e7df --- /dev/null +++ b/modules/FindMagnumBindings.cmake @@ -0,0 +1,116 @@ +#.rst: +# Find Magnum bindings +# -------------------- +# +# Finds helper headers for the Magnum bindings. Basic usage:: +# +# find_package(MagnumBindings REQUIRED) +# +# This command tries to find Magnum bindings and then defines the following: +# +# MagnumBindings_FOUND - Whether Magnum bindings were found +# +# This command will not try to find any actual bindings. The bindings are: +# +# Python - Python bindings +# +# Example usage with specifying the components is:: +# +# find_package(MagnumBindings REQUIRED Python) +# +# For each component is then defined: +# +# MagnumBindings_*_FOUND - Whether the bindings were found +# MagnumBindings::* - Imported target +# +# The package is found if the headers are found. None of the bindings expose +# any library at the moment. +# +# Additionally these variables are defined for internal usage: +# +# MAGNUMBINDINGS_*_INCLUDE_DIR - Component include dir (w/o dependencies) +# + +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +find_package(Magnum REQUIRED) + +# Component distinction (listing them explicitly to avoid mistakes with finding +# components from other repositories) +set(_MAGNUMBINDINGS_HEADER_ONLY_COMPONENT_LIST Python) + +# Convert components lists to regular expressions so I can use if(MATCHES). +# TODO: Drop this once CMake 3.3 and if(IN_LIST) can be used +foreach(_WHAT HEADER_ONLY) + string(REPLACE ";" "|" _MAGNUMBINDINGS_${_WHAT}_COMPONENTS "${_MAGNUMBINDINGS_${_WHAT}_COMPONENT_LIST}") + set(_MAGNUMBINDINGS_${_WHAT}_COMPONENTS "^(${_MAGNUMBINDINGS_${_WHAT}_COMPONENTS})$") +endforeach() + +# Find all components +foreach(_component ${MagnumBindings_FIND_COMPONENTS}) + string(TOUPPER ${_component} _COMPONENT) + + # Create imported target in case the library is found. If the project is + # added as subproject to CMake, the target already exists and all the + # required setup is already done from the build tree. + if(TARGET MagnumBindings::${_component}) + set(MagnumBindings_${_component}_FOUND TRUE) + else() + # Header-only components + if(_component MATCHES ${_MAGNUMBINDINGS_HEADER_ONLY_COMPONENTS}) + add_library(MagnumBindings::${_component} INTERFACE IMPORTED) + endif() + + # Python bindings + if(_component STREQUAL Python) + set(_MAGNUMBINDINGS_${_COMPONENT}_INCLUDE_PATH_NAMES Magnum/SceneGraph/Python.h) + endif() + + if(_component MATCHES ${_MAGNUMBINDINGS_HEADER_ONLY_COMPONENTS}) + # Find includes + find_path(_MAGNUMBINDINGS_${_COMPONENT}_INCLUDE_DIR + NAMES ${_MAGNUMBINDINGS_${_COMPONENT}_INCLUDE_PATH_NAMES} + HINTS ${MAGNUM_INCLUDE_DIR}) + mark_as_advanced(_MAGNUMBINDINGS_${_COMPONENT}_INCLUDE_DIR) + + # Link to core Magnum library + set_property(TARGET MagnumBindings::${_component} APPEND PROPERTY + INTERFACE_LINK_LIBRARIES Magnum::Magnum) + endif() + + # Decide if the component was found + if(_component MATCHES ${_MAGNUMBINDINGS_HEADER_ONLY_COMPONENTS} AND _MAGNUMBINDINGS_${_COMPONENT}_INCLUDE_DIR) + set(MagnumBindings_${_component}_FOUND TRUE) + else() + set(MagnumBindings_${_component}_FOUND FALSE) + endif() + endif() +endforeach() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MagnumBindings + REQUIRED_VARS MAGNUM_INCLUDE_DIR + HANDLE_COMPONENTS) diff --git a/modules/MagnumBindingsConfig.cmake b/modules/MagnumBindingsConfig.cmake new file mode 100644 index 0000000..827e093 --- /dev/null +++ b/modules/MagnumBindingsConfig.cmake @@ -0,0 +1,26 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 +# Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +include(${CMAKE_CURRENT_LIST_DIR}/FindMagnumBindings.cmake)