diff --git a/CMakeLists.txt b/CMakeLists.txt index b8d9d90e7..d8eabb8d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -682,14 +682,23 @@ if(CORRADE_TARGET_EMSCRIPTEN AND NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DI endif() # Installation paths -include(${CORRADE_LIB_SUFFIX_MODULE}) -set(MAGNUM_BINARY_INSTALL_DIR bin) -set(MAGNUM_LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}) -set(MAGNUM_DATA_INSTALL_DIR share/magnum) -set(MAGNUM_CMAKE_MODULE_INSTALL_DIR share/cmake/Magnum) -set(MAGNUM_INCLUDE_INSTALL_DIR include/Magnum) -set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR include/MagnumExternal) -set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR include/MagnumPlugins) +include(GNUInstallDirs) +# On Android, if we're using CMake's builtin support and not the NDK toolchain +# (i.e., with CMAKE_ANDROID_ARCH_TRIPLE defined), point CMAKE_INSTALL_LIBDIR to +# a subdirectory based on the target. If the subdirectory doesn't exist, don't +# adjust anything -- in that case the assumption is that it's being installed +# in some other place that doesn't match the NDK layout. +# 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_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 ".") 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}) diff --git a/doc/building.dox b/doc/building.dox index 6c6995de2..a7943c4c7 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -815,15 +815,15 @@ semi-automatically when using Magnum in depending projects, see @ref cmake for more information. Particular platforms have additional requirements when it comes to location of -installed files. The following variables are supported: - -- `LIB_SUFFIX` --- Setting this variable to `64` can be used to tell CMake to - install to `lib64/` instead of `lib/`. In most cases this variable is - autodetected, so you don't need to set it yourself. On - @ref CORRADE_TARGET_ANDROID "Android", if `CMAKE_INSTALL_PREFIX` points to - the NDK sysroot, it gets automatically set to - `/${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}` to put the binaries - to correct location for given architecture and API level version. +installed files. The following special cases are recognized: + +- On @ref CORRADE_TARGET_ANDROID "Android", if `CMAKE_INSTALL_PREFIX` points + to the NDK sysroot, `CMAKE_INSTALL_LIBDIR` gets adjusted to point to a + `${CMAKE_ANDROID_ARCH_TRIPLE}/${CMAKE_SYSTEM_VERSION}` subdir to put the + binaries to correct location for given architecture and API level version. + +The following variables are supported: + - `MAGNUM_DEPLOY_PREFIX` --- Used on @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" 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 @@ -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 by disabling `MAGNUM_TARGET_GLES2`. -If you set `CMAKE_INSTALL_PREFIX` to `/usr` subdirectory of the particular -Android platform sysroot (as shown below), Magnum's buildsystem will also pick -a `LIB_SUFFIX` corresponding to a particular ABI and version, which in turn -makes the package automatically discoverable when compiling depending projects, -both with vanilla CMake and with Gradle. Another option is to explicitly set -`CMAKE_PREFIX_PATH` to the install location in depending projects. +If you set `CMAKE_INSTALL_PREFIX` to the `/usr` subdirectory of the particular +Android platform sysroot (as shown below), Magnum's buildsystem will also +adjust `CMAKE_INSTALL_LIBDIR` to a subdirectory corresponding to a particular +ABI and version, which in turn makes the package automatically discoverable +when compiling depending projects, both with vanilla CMake and with Gradle. +Another option is to explicitly set `CMAKE_PREFIX_PATH` to the install location +in depending projects. diff --git a/doc/changelog.dox b/doc/changelog.dox index fdd36674a..f70c8efeb 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1167,11 +1167,12 @@ See also: 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). - 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` - gets autodetected to a correct triplet + API level version subdirectory, - making the installed project discoverable by both vanilla CMake and Gradle. - On 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 + without explicitly supplying various system paths. Additionally, when + `CMAKE_INSTALL_PREFIX` points to Android NDK sysroot, `CMAKE_INSTALL_LIBDIR` + gets adjusted to a correct triplet + API level version subdirectory, making + the installed project discoverable by both vanilla CMake and Gradle. On + 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 information. - 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 (see [mosra/magnum#689](https://github.com/mosra/magnum/issues/689) and [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 diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index b820eab35..9185b6bad 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -1340,13 +1340,22 @@ endif() set(MAGNUM_DEPLOY_PREFIX "." CACHE STRING "Prefix where to put final application executables") -include(${CORRADE_LIB_SUFFIX_MODULE}) -set(MAGNUM_BINARY_INSTALL_DIR bin) -set(MAGNUM_LIBRARY_INSTALL_DIR lib${LIB_SUFFIX}) -set(MAGNUM_DATA_INSTALL_DIR share/magnum) -set(MAGNUM_INCLUDE_INSTALL_DIR include/Magnum) -set(MAGNUM_EXTERNAL_INCLUDE_INSTALL_DIR include/MagnumExternal) -set(MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR include/MagnumPlugins) +include(GNUInstallDirs) +# On Android, if we're using CMake's builtin support and not the NDK toolchain +# (i.e., with CMAKE_ANDROID_ARCH_TRIPLE defined), point CMAKE_INSTALL_LIBDIR to +# a subdirectory based on the target. If the subdirectory doesn't exist, don't +# adjust anything -- in that case the assumption is that it's being installed +# in some other place that doesn't match the NDK layout. +# 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 ".") 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})