Skip to content

Commit

Permalink
Merge pull request #2628 from boutproject/cmake-install-paths
Browse files Browse the repository at this point in the history
Remove references to build dir from install
  • Loading branch information
ZedThree authored Jun 14, 2023
2 parents f695441 + efe5e3d commit ebc0051
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 33 deletions.
51 changes: 36 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -672,9 +688,6 @@ endif()
##################################################
# L10N: localisation - include translations


include(GNUInstallDirs)

find_package(Gettext)

if (GETTEXT_FOUND)
Expand Down Expand Up @@ -746,15 +759,20 @@ 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
# directory library path with the installation path
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}")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
35 changes: 21 additions & 14 deletions bout++Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions tools/pylib/boutconfig/__init__.py.cin
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = {}
Expand Down

0 comments on commit ebc0051

Please sign in to comment.