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: ab25e4b7ed
This commit is contained in:
Thomas Bracht Laumann Jespersen 2022-08-07 16:42:01 +02:00 committed by GitHub
parent e3f07dcc07
commit c7bccf0515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 87 deletions

View File

@ -7,7 +7,7 @@
# For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like # For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
# e.g.: # e.g.:
# set(OPENJPEG_NAMESPACE "GDCMOPENJPEG") # set(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
cmake_minimum_required(VERSION 2.8.2) cmake_minimum_required(VERSION 2.8.5)
if(COMMAND CMAKE_POLICY) if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW) cmake_policy(SET CMP0003 NEW)
@ -105,55 +105,24 @@ endif()
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Install directories # Install directories
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
include(GNUInstallDirs)
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found) # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF) option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
string(TOLOWER ${PROJECT_NAME} projectname) set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
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()
if(NOT OPENJPEG_INSTALL_JNI_DIR) if(NOT OPENJPEG_INSTALL_JNI_DIR)
if(WIN32) if(WIN32)
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR}) set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_BINDIR})
else() else()
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR}) set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_LIBDIR})
endif() endif()
endif() endif()
if(NOT OPENJPEG_INSTALL_PACKAGE_DIR) if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
# We could install *.cmake files in share/ however those files contains set(OPENJPEG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${OPENJPEG_INSTALL_SUBDIR}")
# 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}")
endif() endif()
if (APPLE) if (APPLE)
@ -161,7 +130,7 @@ if (APPLE)
# For cmake >= 3.0, we turn on CMP0042 and # For cmake >= 3.0, we turn on CMP0042 and
# https://cmake.org/cmake/help/v3.0/policy/CMP0042.html mentions # https://cmake.org/cmake/help/v3.0/policy/CMP0042.html mentions
# "Projects wanting @rpath in a targets install name may remove any setting of the INSTALL_NAME_DIR and CMAKE_INSTALL_NAME_DIR variables" # "Projects wanting @rpath in a targets 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() endif()
option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF) option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
endif() 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) include (cmake/OpenJPEGCPack.cmake)
@ -366,18 +327,30 @@ else()
option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF) option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
endif() endif()
if(BUILD_PKGCONFIG_FILES) 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 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY) ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
# #
if(BUILD_JPIP) 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 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY) ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
endif() endif()
endif() endif()

View File

@ -27,12 +27,8 @@ if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
# This is an install tree # This is an install tree
include(${SELF_DIR}/OpenJPEGTargets.cmake) include(${SELF_DIR}/OpenJPEGTargets.cmake)
# We find a relative path from the PKG directory to header files. set(INC_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@/@OPENJPEG_INSTALL_SUBDIR@")
set(PKG_DIR "@CMAKE_INSTALL_PREFIX@/@OPENJPEG_INSTALL_PACKAGE_DIR@") get_filename_component(OPENJPEG_INCLUDE_DIRS "${INC_DIR}" ABSOLUTE)
set(INC_DIR "@CMAKE_INSTALL_PREFIX@/@OPENJPEG_INSTALL_INCLUDE_DIR@")
file(RELATIVE_PATH PKG_TO_INC_RPATH "${PKG_DIR}" "${INC_DIR}")
get_filename_component(OPENJPEG_INCLUDE_DIRS "${SELF_DIR}/${PKG_TO_INC_RPATH}" REALPATH)
else() else()
if(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake) if(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake)

View File

@ -44,7 +44,7 @@ if(DOXYGEN_FOUND)
# install HTML documentation (install png files too): # install HTML documentation (install png files too):
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html
DESTINATION ${OPENJPEG_INSTALL_DOC_DIR} DESTINATION ${CMAKE_INSTALL_DOCDIR}
PATTERN ".svn" EXCLUDE PATTERN ".svn" EXCLUDE
) )
else() else()

View File

@ -67,7 +67,7 @@ foreach(exe opj_decompress opj_compress opj_dump)
# Install exe # Install exe
install(TARGETS ${exe} install(TARGETS ${exe}
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
) )
if(OPJ_USE_DSYMUTIL) if(OPJ_USE_DSYMUTIL)
add_custom_command(TARGET ${exe} POST_BUILD add_custom_command(TARGET ${exe} POST_BUILD
@ -83,6 +83,6 @@ install(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_compress.1 FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_compress.1
${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_decompress.1 ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_decompress.1
${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_dump.1 ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_dump.1
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man1) DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
# #
endif() endif()

View File

@ -13,7 +13,7 @@ add_executable(opj_jpip_addxml opj_jpip_addxml.c)
# Install exe # Install exe
install(TARGETS opj_jpip_addxml install(TARGETS opj_jpip_addxml
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
) )
if(BUILD_JPIP_SERVER) if(BUILD_JPIP_SERVER)
@ -38,7 +38,7 @@ if(BUILD_JPIP_SERVER)
# Install exe # Install exe
install(TARGETS opj_server install(TARGETS opj_server
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
) )
endif() endif()
@ -52,7 +52,7 @@ add_executable(${exe} ${exe}.c)
target_link_libraries(${exe} openjpip) target_link_libraries(${exe} openjpip)
install(TARGETS ${exe} install(TARGETS ${exe}
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
) )
endforeach() endforeach()
@ -123,7 +123,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
) )
install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} COMPONENT JavaModule
) )
else() else()
# opj_viewer (simple, no xerces) # opj_viewer (simple, no xerces)
@ -153,7 +153,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
) )
install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar install(FILES ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} COMPONENT JavaModule
) )
endif() endif()
else() else()

View File

@ -2,7 +2,7 @@ include_regular_expression("^.*$")
# #
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers)
include_directories( include_directories(
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h
@ -117,21 +117,21 @@ endif()
# Install library # Install library
install(TARGETS ${INSTALL_LIBS} install(TARGETS ${INSTALL_LIBS}
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
RUNTIME DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
LIBRARY DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
ARCHIVE DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
) )
# Install includes files # Install includes files
install(FILES openjpeg.h opj_stdint.h install(FILES openjpeg.h opj_stdint.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers
) )
if(BUILD_DOC) if(BUILD_DOC)
# install man page of the library # install man page of the library
install( install(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjp2.3 FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjp2.3
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3) DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
endif() endif()
if(BUILD_LUTS_GENERATOR) if(BUILD_LUTS_GENERATOR)

View File

@ -1,9 +1,9 @@
prefix=@CMAKE_INSTALL_PREFIX@ prefix=@CMAKE_INSTALL_PREFIX@
bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ bindir=@bindir@
mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ mandir=@mandir@
docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ docdir=@docdir@
libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ libdir=@libdir@
includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ includedir=@includedir@
Name: openjp2 Name: openjp2
Description: JPEG2000 library (Part 1 and 2) Description: JPEG2000 library (Part 1 and 2)

View File

@ -74,9 +74,9 @@ endif()
# Install library # Install library
install(TARGETS openjpip install(TARGETS openjpip
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
RUNTIME DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
LIBRARY DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
ARCHIVE DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
) )
if(BUILD_JPIP_SERVER) if(BUILD_JPIP_SERVER)
@ -86,6 +86,6 @@ if(BUILD_JPIP_SERVER)
PROPERTIES COMPILE_FLAGS "-DSERVER") PROPERTIES COMPILE_FLAGS "-DSERVER")
install(TARGETS openjpip_server install(TARGETS openjpip_server
EXPORT OpenJPEGTargets EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
) )
endif() endif()

View File

@ -1,9 +1,9 @@
prefix=@CMAKE_INSTALL_PREFIX@ prefix=@CMAKE_INSTALL_PREFIX@
bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ bindir=@bindir@
mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ mandir=@mandir@
docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ docdir=@docdir@
libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ libdir=@libdir@
includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ includedir=@includedir@
Name: openjpip Name: openjpip
Description: JPEG2000 Interactivity tools, APIs and protocols (Part 9) Description: JPEG2000 Interactivity tools, APIs and protocols (Part 9)

View File

@ -66,5 +66,5 @@ add_custom_target(OpenJPEGJavaJar ALL
) )
install(FILES ${LIBRARY_OUTPUT_PATH}/openjpeg.jar install(FILES ${LIBRARY_OUTPUT_PATH}/openjpeg.jar
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule DESTINATION ${CMAKE_INSTALL_DATAROOTDIR} COMPONENT JavaModule
) )