Browse Source

CMake: use GNUInstallDirs to define installation locations.

Same change as in Corrade, additionally reflected also inside
FindMagnum.cmake for reuse by depending projects. Besides moving closer
to the "standard" way of doing things, using this module allows me to
drop the custom logic around LIB_SUFFIX, as the /usr/lib vs /usr/lib64
etc. distinction is now handled by GNUInstallDirs along with any other
variants.
next
Vladimír Vondruš 3 weeks ago
parent
commit
145fc82c75
  1. 25
      CMakeLists.txt
  2. 31
      doc/building.dox
  3. 14
      doc/changelog.dox
  4. 23
      modules/FindMagnum.cmake

25
CMakeLists.txt

@ -682,14 +682,23 @@ if(CORRADE_TARGET_EMSCRIPTEN AND NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DI
endif() endif()
# Installation paths # Installation paths
include(${CORRADE_LIB_SUFFIX_MODULE}) include(GNUInstallDirs)
set(MAGNUM_BINARY_INSTALL_DIR bin) # On Android, if we're using CMake's builtin support and not the NDK toolchain
set(MAGNUM_LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}) # (i.e., with CMAKE_ANDROID_ARCH_TRIPLE defined), point CMAKE_INSTALL_LIBDIR to
set(MAGNUM_DATA_INSTALL_DIR share/magnum) # a subdirectory based on the target. If the subdirectory doesn't exist, don't
set(MAGNUM_CMAKE_MODULE_INSTALL_DIR share/cmake/Magnum) # adjust anything -- in that case the assumption is that it's being installed
set(MAGNUM_INCLUDE_INSTALL_DIR include/Magnum) # in some other place that doesn't match the NDK layout.
set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR include/MagnumExternal) # TODO could GNUInstallDirs do this on their own? Ugh...
set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR include/MagnumPlugins) if(CORRADE_TARGET_ANDROID AND CMAKE_ANDROID_ARCH_TRIPLE AND EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}")
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}")
endif()
set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_BINDIR})
set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
set(MAGNUM_DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/magnum)
set(MAGNUM_CMAKE_MODULE_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/cmake/Magnum)
set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/Magnum)
set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/MagnumExternal)
set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/MagnumPlugins)
if(MAGNUM_BUILD_DEPRECATED AND MAGNUM_INCLUDE_INSTALL_PREFIX AND NOT MAGNUM_INCLUDE_INSTALL_PREFIX STREQUAL ".") if(MAGNUM_BUILD_DEPRECATED AND MAGNUM_INCLUDE_INSTALL_PREFIX AND NOT MAGNUM_INCLUDE_INSTALL_PREFIX STREQUAL ".")
message(DEPRECATION "MAGNUM_INCLUDE_INSTALL_PREFIX is obsolete as its primary use was for old Android NDK versions. Please switch to the NDK r19+ layout instead of using this variable and recreate your build directory to get rid of this warning.") message(DEPRECATION "MAGNUM_INCLUDE_INSTALL_PREFIX is obsolete as its primary use was for old Android NDK versions. Please switch to the NDK r19+ layout instead of using this variable and recreate your build directory to get rid of this warning.")
set(MAGNUM_DATA_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/${MAGNUM_DATA_INSTALL_DIR}) set(MAGNUM_DATA_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/${MAGNUM_DATA_INSTALL_DIR})

31
doc/building.dox

@ -815,15 +815,15 @@ semi-automatically when using Magnum in depending projects, see @ref cmake for
more information. more information.
Particular platforms have additional requirements when it comes to location of Particular platforms have additional requirements when it comes to location of
installed files. The following variables are supported: installed files. The following special cases are recognized:
- `LIB_SUFFIX` --- Setting this variable to `64` can be used to tell CMake to - On @ref CORRADE_TARGET_ANDROID "Android", if `CMAKE_INSTALL_PREFIX` points
install to `lib64/` instead of `lib/`. In most cases this variable is to the NDK sysroot, `CMAKE_INSTALL_LIBDIR` gets adjusted to point to a
autodetected, so you don't need to set it yourself. On `${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}` subdir to put the
@ref CORRADE_TARGET_ANDROID "Android", if `CMAKE_INSTALL_PREFIX` points to binaries to correct location for given architecture and API level version.
the NDK sysroot, it gets automatically set to
`/${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}` to put the binaries The following variables are supported:
to correct location for given architecture and API level version.
- `MAGNUM_DEPLOY_PREFIX` --- Used on @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" - `MAGNUM_DEPLOY_PREFIX` --- Used on @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten"
to override location where web demos and utilities (such as @ref magnum-gl-info) to override location where web demos and utilities (such as @ref magnum-gl-info)
are installed, so you can have libraries installed to a system location and are installed, so you can have libraries installed to a system location and
@ -1202,12 +1202,13 @@ manually loading all depending shared libraries using JNI would be too
inconvenient. The engine is built for OpenGL ES 2.0 by default, switch to 3.0 inconvenient. The engine is built for OpenGL ES 2.0 by default, switch to 3.0
by disabling `MAGNUM_TARGET_GLES2`. by disabling `MAGNUM_TARGET_GLES2`.
If you set `CMAKE_INSTALL_PREFIX` to `/usr` subdirectory of the particular If you set `CMAKE_INSTALL_PREFIX` to the `/usr` subdirectory of the particular
Android platform sysroot (as shown below), Magnum's buildsystem will also pick Android platform sysroot (as shown below), Magnum's buildsystem will also
a `LIB_SUFFIX` corresponding to a particular ABI and version, which in turn adjust `CMAKE_INSTALL_LIBDIR` to a subdirectory corresponding to a particular
makes the package automatically discoverable when compiling depending projects, ABI and version, which in turn makes the package automatically discoverable
both with vanilla CMake and with Gradle. Another option is to explicitly set when compiling depending projects, both with vanilla CMake and with Gradle.
`CMAKE_PREFIX_PATH` to the install location in depending projects. Another option is to explicitly set `CMAKE_PREFIX_PATH` to the install location
in depending projects.
<b></b> <b></b>

14
doc/changelog.dox

@ -1167,11 +1167,12 @@ See also:
subproject. See the @ref Platform-Sdl2Application-usage "Platform::Sdl2Application docs" subproject. See the @ref Platform-Sdl2Application-usage "Platform::Sdl2Application docs"
for more information. See also [mosra/magnum#496](https://github.com/mosra/magnum/issues/496). for more information. See also [mosra/magnum#496](https://github.com/mosra/magnum/issues/496).
- With CMake 3.20 and newer it's possible to compile for Android NDK r19+ - With CMake 3.20 and newer it's possible to compile for Android NDK r19+
without explicitly supplying various system paths. Additionally, when `CMAKE_INSTALL_PREFIX` points to Android NDK sysroot, the `LIB_SUFFIX` without explicitly supplying various system paths. Additionally, when
gets autodetected to a correct triplet + API level version subdirectory, `CMAKE_INSTALL_PREFIX` points to Android NDK sysroot, `CMAKE_INSTALL_LIBDIR`
making the installed project discoverable by both vanilla CMake and Gradle. gets adjusted to a correct triplet + API level version subdirectory, making
On CMake 3.16 to 3.19 it's required to set two extra variables for the the installed project discoverable by both vanilla CMake and Gradle. On
same effect. See @ref building-cross-android, @ref platforms-android and CMake 3.16 to 3.19 it's required to set two extra variables for the same
effect. See @ref building-cross-android, @ref platforms-android and
[mosra/magnum#310](https://github.com/mosra/magnum/issues/310) for more [mosra/magnum#310](https://github.com/mosra/magnum/issues/310) for more
information. information.
- Suppressing a CMake policy-related warning if the global `CMAKE_AUTOMOC` is - Suppressing a CMake policy-related warning if the global `CMAKE_AUTOMOC` is
@ -1270,6 +1271,9 @@ See also:
- Undefining the `near` and `far` macros on Windows in a more robust way - Undefining the `near` and `far` macros on Windows in a more robust way
(see [mosra/magnum#689](https://github.com/mosra/magnum/issues/689) and (see [mosra/magnum#689](https://github.com/mosra/magnum/issues/689) and
[mosra/magnum#690](https://github.com/mosra/magnum/pull/690)) [mosra/magnum#690](https://github.com/mosra/magnum/pull/690))
- The buildsystem now uses CMake's `GNUInstallDirs` module for a standardized
way to specify installation location of binaries, libraries, include files
and other data (see [mosra/magnum#696](https://github.com/mosra/magnum/issues/696))
@subsection changelog-latest-bugfixes Bug fixes @subsection changelog-latest-bugfixes Bug fixes

23
modules/FindMagnum.cmake

@ -1340,13 +1340,22 @@ endif()
set(MAGNUM_DEPLOY_PREFIX "." set(MAGNUM_DEPLOY_PREFIX "."
CACHE STRING "Prefix where to put final application executables") CACHE STRING "Prefix where to put final application executables")
include(${CORRADE_LIB_SUFFIX_MODULE}) include(GNUInstallDirs)
set(MAGNUM_BINARY_INSTALL_DIR bin) # On Android, if we're using CMake's builtin support and not the NDK toolchain
set(MAGNUM_LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}) # (i.e., with CMAKE_ANDROID_ARCH_TRIPLE defined), point CMAKE_INSTALL_LIBDIR to
set(MAGNUM_DATA_INSTALL_DIR share/magnum) # a subdirectory based on the target. If the subdirectory doesn't exist, don't
set(MAGNUM_INCLUDE_INSTALL_DIR include/Magnum) # adjust anything -- in that case the assumption is that it's being installed
set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR include/MagnumExternal) # in some other place that doesn't match the NDK layout.
set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR include/MagnumPlugins) # TODO could GNUInstallDirs do this on their own? Ugh...
if(CORRADE_TARGET_ANDROID AND CMAKE_ANDROID_ARCH_TRIPLE AND EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}")
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}")
endif()
set(MAGNUM_BINARY_INSTALL_DIR ${CMAKE_INSTALL_BINDIR})
set(MAGNUM_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
set(MAGNUM_DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/magnum)
set(MAGNUM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/Magnum)
set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/MagnumExternal)
set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/MagnumPlugins)
if(MAGNUM_BUILD_DEPRECATED AND MAGNUM_INCLUDE_INSTALL_PREFIX AND NOT MAGNUM_INCLUDE_INSTALL_PREFIX STREQUAL ".") if(MAGNUM_BUILD_DEPRECATED AND MAGNUM_INCLUDE_INSTALL_PREFIX AND NOT MAGNUM_INCLUDE_INSTALL_PREFIX STREQUAL ".")
message(DEPRECATION "MAGNUM_INCLUDE_INSTALL_PREFIX is obsolete as its primary use was for old Android NDK versions. Please switch to the NDK r19+ layout instead of using this variable and recreate your build directory to get rid of this warning.") message(DEPRECATION "MAGNUM_INCLUDE_INSTALL_PREFIX is obsolete as its primary use was for old Android NDK versions. Please switch to the NDK r19+ layout instead of using this variable and recreate your build directory to get rid of this warning.")
set(MAGNUM_DATA_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/${MAGNUM_DATA_INSTALL_DIR}) set(MAGNUM_DATA_INSTALL_DIR ${MAGNUM_INCLUDE_INSTALL_PREFIX}/${MAGNUM_DATA_INSTALL_DIR})

Loading…
Cancel
Save