# # This file is part of Magnum. # # Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, # 2020, 2021, 2022 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. # cmake_minimum_required(VERSION 3.4) project(MagnumBindings CXX) # Don't restrict INTERPROCEDURAL_OPTIMIZATION only for icc on Linux if(POLICY CMP0069) cmake_policy(SET CMP0069 NEW) endif() # If CMAKE_AUTOMOC is set, all uses of corrade_add_resource() would otherwise # complain on 3.10 that AUTOMOC is not processing GENERATED files if(POLICY CMP0071) cmake_policy(SET CMP0071 NEW) endif() # Superprojects can use just set(MAGNUM_WITH_BLAH ON) without FORCE CACHE on # 3.13+ if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) endif() # Use folders for nice tree in Visual Studio and XCode set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules/" ${CMAKE_MODULE_PATH}) find_package(Magnum REQUIRED) include(CMakeDependentOption) # Options that used to be unprefixed. New options shouldn't be added to this # list. set(_MAGNUMBINDINGS_DEPRECATED_UNPREFIXED_OPTIONS WITH_PYTHON BUILD_TESTS) # If during the first run (i.e., when the variable isn't in cache yet), check # if any of the prefixed options are already set. If so, we assume the user is # already switched to the prefixed options and won't accept the deprecated # unprefixed options for backwards compatibility. This way it's possible for # projects to reuse these variables for other purposes without affecting # Corrade in any way. if(NOT DEFINED _MAGNUMBINDINGS_ACCEPT_DEPRECATED_UNPREFIXED_OPTIONS) set(_MAGNUMBINDINGS_ACCEPT_DEPRECATED_UNPREFIXED_OPTIONS ON CACHE INTERNAL "") foreach(option ${_MAGNUMBINDINGS_DEPRECATED_UNPREFIXED_OPTIONS}) if(DEFINED MAGNUM_${option}) set(_MAGNUMBINDINGS_ACCEPT_DEPRECATED_UNPREFIXED_OPTIONS OFF CACHE INTERNAL "") break() endif() endforeach() endif() # Libraries to build option(MAGNUM_WITH_PYTHON "Build Python bindings" OFF) option(MAGNUM_BUILD_TESTS "Build unit tests" OFF) # Backwards compatibility for unprefixed CMake options. If the user isn't # explicitly using prefixed options in the first run already, accept the # unprefixed options, and remember this decision for subsequent runs if(NOT DEFINED _MAGNUMBINDINGS_ACCEPT_DEPRECATED_UNPREFIXED_OPTIONS) set(_MAGNUMBINDINGS_ACCEPT_DEPRECATED_UNPREFIXED_OPTIONS ON CACHE INTERNAL "") endif() # If the user wasn't explicitly using prefixed options in the first run and the # MAGNUM_BUILD_DEPRECATED option is not currently disabled (which can get # changed subsequently), accept the unprefixed options and print a warning if # they're different from the prefixed ones. if(_MAGNUMBINDINGS_ACCEPT_DEPRECATED_UNPREFIXED_OPTIONS AND MAGNUM_BUILD_DEPRECATED) set(_MAGNUMBINDINGS_WARN_DEPRECATED_UNPREFIXED_OPTION ) foreach(option ${_MAGNUMBINDINGS_DEPRECATED_UNPREFIXED_OPTIONS}) if(DEFINED ${option}) # CMake has no comparison of boolean values (EQUAL returns false if # comparing ON and 1 or OFF and FALSE, STREQUAL also), so we have # to do it this way. Also warn only on the first encountered # variable so people can fix it, reconfigure and go to the next one # that warns. if((${option} AND NOT MAGNUM_${option}) OR (NOT ${option} AND MAGNUM_${option}) AND NOT _MAGNUMBINDINGS_WARN_DEPRECATED_UNPREFIXED_OPTION) set(_MAGNUMBINDINGS_WARN_DEPRECATED_UNPREFIXED_OPTION ${option}) endif() set(MAGNUM_${option} ${${option}}) # If variables specified on the command line don't match any # options, they're kept in cache but set as UNINITIALIZED, meaning # they don't appear in cmake-gui or ccmake, so there's no way to # fix the warning apart from hand-enditing the CMakeCache.txt or # recreating the build dir. Update their cached type to be BOOL to # make them appear. set(${option} ${${option}} CACHE BOOL "Deprecated, use MAGNUM_${option} instead" FORCE) endif() endforeach() if(_MAGNUMBINDINGS_WARN_DEPRECATED_UNPREFIXED_OPTION) # CMake 3.5+ has deprecation warnings enabled by default (which makes # sense), 3.4 not. Use a warning there instead. # TODO: drop when 3.4 is not supported anymore if(CMAKE_VERSION VERSION_LESS 3.5) set(DEPRECATION_OR_WARNING WARNING) else() set(DEPRECATION_OR_WARNING DEPRECATION) endif() message(${DEPRECATION_OR_WARNING} "Unprefixed options such as ${_MAGNUMBINDINGS_WARN_DEPRECATED_UNPREFIXED_OPTION} are deprecated, use MAGNUM_${_MAGNUMBINDINGS_WARN_DEPRECATED_UNPREFIXED_OPTION} instead. Delete the unprefixed variable from CMake cache or set both to the same value to silence this warning.") endif() endif() if(MAGNUM_BUILD_TESTS) find_package(Corrade REQUIRED TestSuite) if(CORRADE_TARGET_IOS) set(CORRADE_TESTSUITE_BUNDLE_IDENTIFIER_PREFIX "cz.mosra.magnum-bindings") endif() enable_testing() endif() set(MAGNUMBINDINGS_CMAKE_MODULE_INSTALL_DIR share/cmake/MagnumBindings) # Library version. MAGNUMBINDINGS_VERSION_YEAR/MONTH is used in # src/Magnum/CMakeLists.txt to generate the versionBindings.h header. set(MAGNUMBINDINGS_VERSION_YEAR 2020) set(MAGNUMBINDINGS_VERSION_MONTH 6) # A single output location. After a decade of saying NO THIS IS A NON-SOLUTION # TO A NON-PROBLEM I reconsidered my views and enabled this, because: # # - On Windows (which don't have RPATH), this makes test execution finally # possible without having to install all the stuff first (including the # test-only libs, which is ugh). # - With CMake subprojects, this makes it finally possible to use dynamic # plugins directly from the build dir (again without installing anything) --- # all plugins are put into the same place, so PluginManager has a single # place to look into; and thanks to the dynamic libraries being there as # well, this location can be automagically detected as relative to # Utility::Path::libraryLocation(). # - Thanks to the $ being part of the output path, you are always sure # you never accidentally mix up debug/release libraries when switching # CMAKE_BUILD_TYPE in an existing build dir. # # The runtime location is set to CMAKE_BINARY_DIR and not PROJECT_BINARY_DIR # because have one runtime location per CMake subproject would not solve much # either. If the user already provides CMAKE_RUNTIME_OUTPUT_DIRECTORY (even # empty), it's respected and nothing is being done. # # Explicitly using a generator expression to ensure plugins are added to e.g. # /lib/magnum/importers/ instead of lib/magnum/importers/. Also # adding this to cache, making superprojects pick that up implicitly as well, # without forcing them to explicitly mirror this setting. if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY AND NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY AND NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/bin CACHE PATH "" FORCE) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/lib CACHE PATH "" FORCE) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$/lib CACHE PATH "" FORCE) endif() add_subdirectory(modules) add_subdirectory(src)