From c64e031717c51336da31d8e70ddd34108170e151 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 25 Nov 2021 08:16:36 -0800 Subject: [PATCH] CMake: use more standard, portable mechanism for setting install paths Fixes #1973. Suggested-by: Satadru Pramanik --- CHANGELOG.md | 3 +++ CMakeLists.txt | 25 ++++++++++++++++++------- cmake/configure_plugins.cmake.in | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f85c5c005..3b65e7da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The tclpkg Makefile no longer suppresses `-fstack-clash-protection` nor other compiler options containing `-x` - Lefty is no longer enabled in the portable source tarball. +- on Linux, the CMake build system uses the standard `GNUInstallDirs` to locate + target installation paths ### Fixed @@ -93,6 +95,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - expr misinterprets `<<` and `>>` #2103 - stdout and stderr are not flushed at exit on MinGW #2178 - Gvedit on macOS now understands the `-?` help command line argument +- CMAKE_LIBRARY_PATH is not honored #1973 ## [2.50.0] – 2021-12-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 606391c33..8186859f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,12 +63,25 @@ endif() find_program(GZIP gzip) # ================== Convenient values for CMake configuration ================= -set(BINARY_INSTALL_DIR bin) -set(LIBRARY_INSTALL_DIR lib) +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + include(GNUInstallDirs) + set(BINARY_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") + set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") + set(HEADER_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/graphviz") + set(MAN_INSTALL_DIR "${CMAKE_INSTALL_MANDIR}") + set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") + set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +else() + set(BINARY_INSTALL_DIR bin) + set(LIBRARY_INSTALL_DIR lib) + set(HEADER_INSTALL_DIR include/graphviz) + set(MAN_INSTALL_DIR share/man) + set(libdir "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}") + set(includedir "${CMAKE_INSTALL_PREFIX}/include") +endif() + set(PLUGIN_INSTALL_DIR ${LIBRARY_INSTALL_DIR}/graphviz) -set(HEADER_INSTALL_DIR include/graphviz) -set(MAN_INSTALL_DIR share/man) -set(PKGCONFIG_DIR lib/pkgconfig) +set(PKGCONFIG_DIR ${LIBRARY_INSTALL_DIR}/pkgconfig) # TODO: Find a way to check for groff and ps2pdf for manpage pdf generation # set(MAN_PDF_INSTALL_DIR share/graphviz/doc/pdf) set(TOP_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") @@ -278,8 +291,6 @@ set(GVPLUGIN_VERSION "${GRAPHVIZ_PLUGIN_VERSION}") set(VERSION "${GRAPHVIZ_VERSION_STRING}") set(prefix "${CMAKE_INSTALL_PREFIX}") set(exec_prefix "${CMAKE_INSTALL_PREFIX}") -set(libdir "${CMAKE_INSTALL_PREFIX}/lib") -set(includedir "${CMAKE_INSTALL_PREFIX}/include") set(PACKAGE "graphviz") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/cdt/libcdt.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/libcdt.pc @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lib/cgraph/libcgraph.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/libcgraph.pc @ONLY) diff --git a/cmake/configure_plugins.cmake.in b/cmake/configure_plugins.cmake.in index d4d41a17b..d0c8f0f95 100644 --- a/cmake/configure_plugins.cmake.in +++ b/cmake/configure_plugins.cmake.in @@ -30,9 +30,9 @@ set(ROOT $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}) if(APPLE) - set(ENV{DYLD_LIBRARY_PATH} "${ROOT}/lib") + set(ENV{DYLD_LIBRARY_PATH} "${ROOT}/@LIBRARY_INSTALL_DIR@") elseif(UNIX) - set(ENV{LD_LIBRARY_PATH} "${ROOT}/lib") + set(ENV{LD_LIBRARY_PATH} "${ROOT}/@LIBRARY_INSTALL_DIR@") endif() execute_process( -- 2.40.0