From 6427a41d8e902c7e25bd5b515a4a324e9aa4151b Mon Sep 17 00:00:00 2001 From: David Bold Date: Mon, 9 Jan 2023 08:25:42 +0100 Subject: [PATCH 1/2] Remove references to build dir from install --- CMakeLists.txt | 32 ++++++++++++++++---------- bout++Config.cmake.in | 30 +++++++++++++----------- tools/pylib/boutconfig/__init__.py.cin | 20 ++++++++++++---- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec3073e5ab..c30f4654f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -730,8 +730,12 @@ else() set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS}") endif() +set(ISINSTALLED "FALSE") + # This version of the file allows the build directory to be used directly configure_file(bin/bout-config.in bin/bout-config @ONLY) +configure_file(tools/pylib/boutconfig/__init__.py.cin tools/pylib/boutconfig/__init__.py @ONLY) +configure_file(bout++Config.cmake.in bout++Config.cmake @ONLY) # We need to generate a separate version for installation, with the # correct install paths. So first we need to replace the build @@ -739,6 +743,7 @@ configure_file(bin/bout-config.in bin/bout-config @ONLY) string(REPLACE "${CMAKE_BINARY_DIR}/lib" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" CONFIG_LDFLAGS "${CONFIG_LDFLAGS}") +set(BOUT_LIB_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") # Update mpark.variant and fmt include paths if we're building them if (NOT BOUT_USE_SYSTEM_MPARK_VARIANT) set(MPARK_VARIANT_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") @@ -750,8 +755,13 @@ set(BOUT_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") # We don't need the build include path any more string(REPLACE "-I${CMAKE_CURRENT_BINARY_DIR}/include" "" CONFIG_CFLAGS "${CONFIG_CFLAGS}") +set(PYTHONCONFIGPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_PYTHON_SITEARCH}") +set(ISINSTALLED "TRUE") + # This version now has the correct paths to use the final installation configure_file(bin/bout-config.in bin/bout-config-install @ONLY) +configure_file(tools/pylib/boutconfig/__init__.py.cin tools/pylib/boutconfig/__init__.py-install @ONLY) +configure_file(bout++Config.cmake.in bout++Config.cmake-install @ONLY) ################################################## # Installation @@ -788,6 +798,12 @@ install(PROGRAMS "${CMAKE_CURRENT_BINARY_DIR}/bin/bout-config-install" RENAME "bout-config" ) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pylib/boutconfig/__init__.py-install" + DESTINATION "${CMAKE_INSTALL_PYTHON_SITEARCH}/boutconfig" + RENAME "__init__.py" + ) + include(CMakePackageConfigHelpers) write_basic_package_version_file( bout++ConfigVersion.cmake @@ -801,14 +817,9 @@ install(EXPORT bout++Targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/bout++" ) -configure_package_config_file(bout++Config.cmake.in bout++Config.cmake - INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/bout++Config.cmake" - ) - # CMake configuration files install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/bout++Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/bout++ConfigVersion.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/BOUT++functions.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CorrectWindowsPaths.cmake" @@ -827,14 +838,11 @@ install( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/ResolveCompilerPaths.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/bout++" ) - -configure_package_config_file(tools/pylib/boutconfig/__init__.py.cin tools/pylib/boutconfig/__init__.py - INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/tools/pylib/boutconfig/__init__.py" - ) - install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pylib/boutconfig/__init__.py" - DESTINATION "${CMAKE_INSTALL_PYTHON_SITEARCH}/boutconfig" + FILES + "${CMAKE_CURRENT_BINARY_DIR}/bout++Config.cmake-install" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/bout++" + RENAME "bout++Config.cmake" ) export(EXPORT bout++Targets diff --git a/bout++Config.cmake.in b/bout++Config.cmake.in index e2da45af99..3f8ab809ae 100644 --- a/bout++Config.cmake.in +++ b/bout++Config.cmake.in @@ -30,21 +30,23 @@ set(BOUT_HAS_RAJA @BOUT_HAS_RAJA@) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") -# Enables the use of the build directory directly, without having to -# specify the paths for the external packages as well -if(EXISTS "@CMAKE_BINARY_DIR@/externalpackages/fmt") - list(APPEND CMAKE_PREFIX_PATH "@CMAKE_BINARY_DIR@/externalpackages/fmt") -endif() -if(EXISTS "@CMAKE_BINARY_DIR@/externalpackages/mpark.variant") - list(APPEND CMAKE_PREFIX_PATH "@CMAKE_BINARY_DIR@/externalpackages/mpark.variant") -endif() -if(EXISTS "@CMAKE_BINARY_DIR@/externalpackages/PVODE") - list(APPEND CMAKE_PREFIX_PATH "@CMAKE_BINARY_DIR@/externalpackages/PVODE") -endif() +if(NOT "@ISINSTALLED@") + # Enables the use of the build directory directly, without having to + # specify the paths for the external packages as well + if(EXISTS "@CMAKE_BINARY_DIR@/externalpackages/fmt") + list(APPEND CMAKE_PREFIX_PATH "@CMAKE_BINARY_DIR@/externalpackages/fmt") + endif() + if(EXISTS "@CMAKE_BINARY_DIR@/externalpackages/mpark.variant") + list(APPEND CMAKE_PREFIX_PATH "@CMAKE_BINARY_DIR@/externalpackages/mpark.variant") + endif() + if(EXISTS "@CMAKE_BINARY_DIR@/externalpackages/PVODE") + list(APPEND CMAKE_PREFIX_PATH "@CMAKE_BINARY_DIR@/externalpackages/PVODE") + endif() -# If using the build directory directly, we need the CMake modules too -if(EXISTS "@PROJECT_SOURCE_DIR@/cmake") - list(APPEND CMAKE_MODULE_PATH "@PROJECT_SOURCE_DIR@/cmake") + # If using the build directory directly, we need the CMake modules too + if(EXISTS "@PROJECT_SOURCE_DIR@/cmake") + list(APPEND CMAKE_MODULE_PATH "@PROJECT_SOURCE_DIR@/cmake") + endif() endif() include(BOUT++functions) diff --git a/tools/pylib/boutconfig/__init__.py.cin b/tools/pylib/boutconfig/__init__.py.cin index 2205f2d7bd..6ab17eb974 100644 --- a/tools/pylib/boutconfig/__init__.py.cin +++ b/tools/pylib/boutconfig/__init__.py.cin @@ -3,19 +3,18 @@ """ # Created by cmake _yesno = {"TRUE": True, "ON": True, "FALSE": False, "OFF": False} -_iyesno = {True: "yes", False: "no"} config = { "cc": "@CMAKE_C_COMPILER@", "cxx": "@CMAKE_CXX_COMPILER@", "ld": "@CMAKE_CXX_COMPILER@", "checks": "@BOUT_CHECK_LEVEL@", - "cflags": "@BOUT_CFLAGS@", - "libs": "@BOUT_LIBS@", + "cflags": "@CONFIG_CFLAGS@", + "libs": "@CONFIG_LIBS@", "version": "@BOUT_VERSION@", "git": "@BOUT_REVISION@", "idlpath": "@IDLCONFIGPATH@", - "pythonpath": "@BOUT_PYTHONPATH@", + "pythonpath": "@PYTHONCONFIGPATH@", "has_netcdf": "@BOUT_HAS_NETCDF@", "has_legacy_netcdf": "@BOUT_HAS_LEGACY_NETCDF@", "has_pnetcdf": "OFF", @@ -34,6 +33,19 @@ config = { "metric_type": "@BOUT_METRIC_TYPE@", } +for k, v in config.items(): + config[k] = ( + v.replace( + "${BOUT_INCLUDE_PATH}", "@BOUT_INCLUDE_PATH@" + ) + .replace( + "${MPARK_VARIANT_INCLUDE_PATH}", "@MPARK_VARIANT_INCLUDE_PATH@" + ) + .replace( + "${FMT_INCLUDE_PATH}", "@FMT_INCLUDE_PATH@" + ) + ) + @property def has(): From efe5e3d5cce5bd2db43e87d33d7ae853f9ad0072 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 3 Feb 2023 14:40:10 +0100 Subject: [PATCH 2/2] set CMAKE_INSTALL_RPATH to installed lib dir Ensures the bundled libraries are found --- CMakeLists.txt | 19 ++++++++++++++++--- bout++Config.cmake.in | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c30f4654f2..1e5685a298 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -372,6 +372,21 @@ This warning is only important for BOUT++ developers and can otherwise be \ safely ignored.") endif() +include(GNUInstallDirs) + +# use, i.e. don't skip the full RPATH for the build tree +set(CMAKE_SKIP_BUILD_RPATH FALSE) + +# when building, don't use the install RPATH already +# (but later on when installing) +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + +# add the automatically determined parts of the RPATH +# which point to directories outside the build tree to the install RPATH +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + + execute_process(COMMAND ${Python3_EXECUTABLE} -c "import site ; print('/'.join(site.getusersitepackages().split('/')[-2:]))" RESULT_VARIABLE PYTHON_WORKING OUTPUT_VARIABLE PYTHON_SITEPATH_SUFFIX @@ -395,6 +410,7 @@ add_custom_command( MAIN_DEPENDENCY "${CMAKE_CURRENT_LIST_DIR}/cmake/GenerateDateTimeFile.cmake" ) + add_library(bout++ ${BOUT_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/bout++-time.cxx @@ -656,9 +672,6 @@ endif() ################################################## # L10N: localisation - include translations - -include(GNUInstallDirs) - find_package(Gettext) if (GETTEXT_FOUND) diff --git a/bout++Config.cmake.in b/bout++Config.cmake.in index 3f8ab809ae..3f4b7e5061 100644 --- a/bout++Config.cmake.in +++ b/bout++Config.cmake.in @@ -47,6 +47,11 @@ if(NOT "@ISINSTALLED@") if(EXISTS "@PROJECT_SOURCE_DIR@/cmake") list(APPEND CMAKE_MODULE_PATH "@PROJECT_SOURCE_DIR@/cmake") endif() +else() + if(EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/ ") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + endif() endif() include(BOUT++functions)