diff options
| author | Thomas Bracht Laumann Jespersen <t@laumann.xyz> | 2022-08-07 16:42:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-07 16:42:01 +0200 |
| commit | c7bccf0515892617af984328e96cff5b4a6cd6d3 (patch) | |
| tree | 67fe67826f15c36e97cc6b8edf150e0b4e68fee5 /CMakeLists.txt | |
| parent | e3f07dcc07c651321ec3b5f540ef698bbe6f1906 (diff) | |
CMake: switch to GNUInstallDirs (#1424)
* Add GNUInstallDirs for standard installation directories
Distributions are given standard variables for already existing hooks.
Multiarch libdirs is taken care of automagically.
Raises minimum cmake version by a little.
* Handle CMAKE_INSTALL_xxx being absolute paths for .pc file generation
In some cases the CMAKE_INSTAL_{BIN,MAN,DOC,LIB,INCLUDE}DIR variables
may turn out to be absolute paths in which case prepending ${prefix} in
the pkg-config .pc files will result in incorrect values.
For .pc file generation, figure out if these variables are absolute and
omit the prefix in the configured file when so.
See: https://github.com/OSGeo/PROJ/commit/ab25e4b7ed9544e668282dcd293cfaaa2e56dbdf
Diffstat (limited to 'CMakeLists.txt')
| -rw-r--r-- | CMakeLists.txt | 77 |
1 files changed, 25 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f89df72..fcf4709d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ # For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like # e.g.: # set(OPENJPEG_NAMESPACE "GDCMOPENJPEG") -cmake_minimum_required(VERSION 2.8.2) +cmake_minimum_required(VERSION 2.8.5) if(COMMAND CMAKE_POLICY) cmake_policy(SET CMP0003 NEW) @@ -105,55 +105,24 @@ endif() # -------------------------------------------------------------------------- # Install directories +string(TOLOWER ${PROJECT_NAME} PROJECT_NAME) +include(GNUInstallDirs) + # Build DOCUMENTATION (not in ALL target and only if Doxygen is found) option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF) -string(TOLOWER ${PROJECT_NAME} projectname) -set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}") - -if(NOT OPENJPEG_INSTALL_BIN_DIR) - set(OPENJPEG_INSTALL_BIN_DIR "bin") -endif() - -if(NOT OPENJPEG_INSTALL_LIB_DIR) - set(OPENJPEG_INSTALL_LIB_DIR "lib") -endif() - -if(NOT OPENJPEG_INSTALL_SHARE_DIR) - set(OPENJPEG_INSTALL_SHARE_DIR "share") -endif() - -if(NOT OPENJPEG_INSTALL_DATA_DIR) - set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}") -endif() - -if(NOT OPENJPEG_INSTALL_INCLUDE_DIR) - set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}") -endif() - -if(BUILD_DOC) -if(NOT OPENJPEG_INSTALL_MAN_DIR) - set(OPENJPEG_INSTALL_MAN_DIR "share/man/") -endif() - -if(NOT OPENJPEG_INSTALL_DOC_DIR) - set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}") -endif() -endif() +set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}") if(NOT OPENJPEG_INSTALL_JNI_DIR) if(WIN32) - set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR}) + set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_BINDIR}) else() - set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR}) + set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_LIBDIR}) endif() endif() if(NOT OPENJPEG_INSTALL_PACKAGE_DIR) - # We could install *.cmake files in share/ however those files contains - # hardcoded path to libraries on a multi-arch system (fedora/debian) those - # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu) - set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}") + set(OPENJPEG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${OPENJPEG_INSTALL_SUBDIR}") endif() if (APPLE) @@ -161,7 +130,7 @@ if (APPLE) # For cmake >= 3.0, we turn on CMP0042 and # https://cmake.org/cmake/help/v3.0/policy/CMP0042.html mentions # "Projects wanting @rpath in a target’s install name may remove any setting of the INSTALL_NAME_DIR and CMAKE_INSTALL_NAME_DIR variables" - list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}") + list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}") endif() option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF) endif() @@ -346,14 +315,6 @@ install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake ) #----------------------------------------------------------------------------- -# install CHANGES and LICENSE -if(BUILD_DOC) -if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES) - install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR}) -endif() - -install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR}) -endif() include (cmake/OpenJPEGCPack.cmake) @@ -366,18 +327,30 @@ else() option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF) endif() if(BUILD_PKGCONFIG_FILES) - # install in lib and not share (see multi-arch note above) + macro(set_variable_from_rel_or_absolute_path var root rel_or_abs_path) + if(IS_ABSOLUTE "${rel_or_abs_path}") + set(${var} "${rel_or_abs_path}") + else() + set(${var} "${root}/${rel_or_abs_path}") + endif() + endmacro() + set_variable_from_rel_or_absolute_path("bindir" "\\\${prefix}" "${CMAKE_INSTALL_BINDIR}") + set_variable_from_rel_or_absolute_path("mandir" "\\\${prefix}" "${CMAKE_INSTALL_MANDIR}") + set_variable_from_rel_or_absolute_path("docdir" "\\\${prefix}" "${CMAKE_INSTALL_DOCDIR}") + set_variable_from_rel_or_absolute_path("libdir" "\\\${prefix}" "${CMAKE_INSTALL_LIBDIR}") + set_variable_from_rel_or_absolute_path("includedir" "\\\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}") + + # install in lib and not share (CMAKE_INSTALL_LIBDIR takes care of it for multi-arch) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION - ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) # if(BUILD_JPIP) - # install in lib and not share (see multi-arch note above) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION - ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) endif() endif() |
