Browse Source

Prefix all CMake options with MAGNUM_*.

pull/16/head
Vladimír Vondruš 4 years ago
parent
commit
737ec6c415
  1. 77
      CMakeLists.txt
  2. 2
      doc/python/pages/building.rst
  3. 4
      doc/python/pages/changelog.rst
  4. 2
      modules/FindMagnumBindings.cmake
  5. 2
      src/CMakeLists.txt
  6. 2
      src/Corrade/CMakeLists.txt
  7. 2
      src/Corrade/Containers/CMakeLists.txt
  8. 4
      src/Magnum/CMakeLists.txt
  9. 2
      src/Magnum/GL/CMakeLists.txt
  10. 2
      src/Magnum/SceneGraph/CMakeLists.txt
  11. 2
      src/python/corrade/CMakeLists.txt

77
CMakeLists.txt

@ -36,7 +36,8 @@ endif()
if(POLICY CMP0071) if(POLICY CMP0071)
cmake_policy(SET CMP0071 NEW) cmake_policy(SET CMP0071 NEW)
endif() endif()
# Superprojects can use just set(WITH_BLAH ON) without FORCE CACHE on 3.13+ # Superprojects can use just set(MAGNUM_WITH_BLAH ON) without FORCE CACHE on
# 3.13+
if(POLICY CMP0077) if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW) cmake_policy(SET CMP0077 NEW)
endif() endif()
@ -49,11 +50,79 @@ find_package(Magnum REQUIRED)
include(CMakeDependentOption) 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 # Libraries to build
option(WITH_PYTHON "Build Python bindings" OFF) option(MAGNUM_WITH_PYTHON "Build Python bindings" OFF)
option(BUILD_TESTS "Build unit tests" 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(BUILD_TESTS) if(MAGNUM_BUILD_TESTS)
find_package(Corrade REQUIRED TestSuite) find_package(Corrade REQUIRED TestSuite)
if(CORRADE_TARGET_IOS) if(CORRADE_TARGET_IOS)
set(CORRADE_TESTSUITE_BUNDLE_IDENTIFIER_PREFIX "cz.mosra.magnum-bindings") set(CORRADE_TESTSUITE_BUNDLE_IDENTIFIER_PREFIX "cz.mosra.magnum-bindings")

2
doc/python/pages/building.rst

@ -119,7 +119,7 @@ default location known to CMake, add their path to ``CMAKE_PREFIX_PATH``.
mkdir build && cd build mkdir build && cd build
cmake .. \ cmake .. \
-DWITH_PYTHON=ON -DMAGNUM_WITH_PYTHON=ON
make make
Note that pybind11 compilation is quite time- and memory-hungry, so you might Note that pybind11 compilation is quite time- and memory-hungry, so you might

4
doc/python/pages/changelog.rst

@ -96,6 +96,10 @@ Changelog
- Exposed :ref:`Color3.red()` and other convenience constructors (see - Exposed :ref:`Color3.red()` and other convenience constructors (see
:gh:`mosra/magnum-bindings#12`) :gh:`mosra/magnum-bindings#12`)
- Fixed issues with an in-source build (see :gh:`mosra/magnum-bindings#13`) - Fixed issues with an in-source build (see :gh:`mosra/magnum-bindings#13`)
- All CMake build options are now prefixed with ``MAGNUM_``. For backwards
compatibility, unless ``MAGNUM_BUILD_DEPRECATED`` is disabled and unless a
prefixed option is already set during the initial run, the unprefixed
options are still recognized with a warning. See also :gh:`mosra/corrade#139`.
`2020.06`_ `2020.06`_
========== ==========

2
modules/FindMagnumBindings.cmake

@ -160,7 +160,7 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.16)
# misleading messages. # misleading messages.
elseif(NOT _component IN_LIST _MAGNUMBINDINGS_IMPLICITLY_ENABLED_COMPONENTS) elseif(NOT _component IN_LIST _MAGNUMBINDINGS_IMPLICITLY_ENABLED_COMPONENTS)
string(TOUPPER ${_component} _COMPONENT) string(TOUPPER ${_component} _COMPONENT)
list(APPEND _MAGNUMBINDINGS_REASON_FAILURE_MESSAGE "${_component} is not built by default. Make sure you enabled WITH_${_COMPONENT} when building Magnum Bindings") list(APPEND _MAGNUMBINDINGS_REASON_FAILURE_MESSAGE "${_component} is not built by default. Make sure you enabled MAGNUM_WITH_${_COMPONENT} when building Magnum Bindings")
# Otherwise we have no idea. Better be silent than to print something # Otherwise we have no idea. Better be silent than to print something
# misleading. # misleading.
else() else()

2
src/CMakeLists.txt

@ -42,7 +42,7 @@ set_directory_properties(PROPERTIES
add_subdirectory(Corrade) add_subdirectory(Corrade)
add_subdirectory(Magnum) add_subdirectory(Magnum)
if(WITH_PYTHON) if(MAGNUM_WITH_PYTHON)
add_subdirectory(python) add_subdirectory(python)
endif() endif()

2
src/Corrade/CMakeLists.txt

@ -27,7 +27,7 @@
# property that would have to be set on each target separately. # property that would have to be set on each target separately.
set(CMAKE_FOLDER "Corrade/Python") set(CMAKE_FOLDER "Corrade/Python")
if(WITH_PYTHON) if(MAGNUM_WITH_PYTHON)
add_custom_target(CorradePython SOURCES PythonBindings.h) add_custom_target(CorradePython SOURCES PythonBindings.h)
install(FILES PythonBindings.h DESTINATION ${CORRADE_INCLUDE_INSTALL_DIR}) install(FILES PythonBindings.h DESTINATION ${CORRADE_INCLUDE_INSTALL_DIR})

2
src/Corrade/Containers/CMakeLists.txt

@ -23,7 +23,7 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
if(WITH_PYTHON) if(MAGNUM_WITH_PYTHON)
set(CorradeContainersPython_HEADERS set(CorradeContainersPython_HEADERS
OptionalPythonBindings.h OptionalPythonBindings.h
PythonBindings.h PythonBindings.h

4
src/Magnum/CMakeLists.txt

@ -69,7 +69,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/versionBindings.h.cmake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/versionBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/versionBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR})
if(WITH_PYTHON) if(MAGNUM_WITH_PYTHON)
add_custom_target(MagnumPython SOURCES PythonBindings.h) add_custom_target(MagnumPython SOURCES PythonBindings.h)
install(FILES PythonBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}) install(FILES PythonBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR})
endif() endif()
@ -84,6 +84,6 @@ if(Magnum_SceneGraph_FOUND)
add_subdirectory(SceneGraph) add_subdirectory(SceneGraph)
endif() endif()
if(BUILD_TESTS) if(MAGNUM_BUILD_TESTS)
add_subdirectory(Test) add_subdirectory(Test)
endif() endif()

2
src/Magnum/GL/CMakeLists.txt

@ -23,7 +23,7 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
if(WITH_PYTHON) if(MAGNUM_WITH_PYTHON)
add_custom_target(MagnumGLPython SOURCES PythonBindings.h) add_custom_target(MagnumGLPython SOURCES PythonBindings.h)
install(FILES PythonBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/GL) install(FILES PythonBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/GL)
endif() endif()

2
src/Magnum/SceneGraph/CMakeLists.txt

@ -23,7 +23,7 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
if(WITH_PYTHON) if(MAGNUM_WITH_PYTHON)
add_custom_target(MagnumSceneGraphPython SOURCES PythonBindings.h) add_custom_target(MagnumSceneGraphPython SOURCES PythonBindings.h)
install(FILES PythonBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/SceneGraph) install(FILES PythonBindings.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/SceneGraph)
endif() endif()

2
src/python/corrade/CMakeLists.txt

@ -98,6 +98,6 @@ set_target_properties(corrade PROPERTIES
file(GENERATE OUTPUT ${output_dir}/corrade/__init__.py file(GENERATE OUTPUT ${output_dir}/corrade/__init__.py
INPUT ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py) INPUT ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py)
if(BUILD_TESTS) if(MAGNUM_BUILD_TESTS)
add_subdirectory(test) add_subdirectory(test)
endif() endif()

Loading…
Cancel
Save