diff --git a/CMakeLists.txt b/CMakeLists.txt index 99c2b56a47..8864c9d113 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -388,6 +388,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 @@ -411,6 +426,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 @@ -672,9 +688,6 @@ endif() ################################################## # L10N: localisation - include translations - -include(GNUInstallDirs) - find_package(Gettext) if (GETTEXT_FOUND) @@ -746,8 +759,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 @@ -755,6 +772,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}") @@ -766,8 +784,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 @@ -804,6 +827,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 @@ -817,14 +846,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" @@ -843,14 +867,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 cb4a993326..e33e950e6f 100644 --- a/bout++Config.cmake.in +++ b/bout++Config.cmake.in @@ -30,21 +30,28 @@ 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() +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) diff --git a/tools/pylib/boutconfig/__init__.py.cin b/tools/pylib/boutconfig/__init__.py.cin index fea7ec95ef..bb1bad6fd8 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@" + ) + ) + """Get a dict of the enabled features""" has = {}