diff --git a/CMakeLists.txt b/CMakeLists.txt index e1f7d43f21..c0c766beeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,27 @@ project(BOUT++ VERSION ${BOUT_CMAKE_ACCEPTABLE_VERSION} LANGUAGES CXX) +# Optionally ignore anything that is installed by conda +set (BOUT_IGNORE_CONDA_ENV OFF CACHE BOOL "Ignore anything installed by conda. May introduce a slow step to the configuration, due to scanning a large number of files under $CONDA_PREFIX.") +if (BOUT_IGNORE_CONDA_ENV) + if (EXISTS $ENV{CONDA_PREFIX}) + # CMake does not allow ignoring everything under a prefix, so we have to + # get a list with *every* directory under CONDA_PREFIX. + # GLOB_RECURSE also doesn't seem to directly allow matching directories, + # but 'LIST_DIRECTORIES true' makes all directories traversed appear in the + # result, and setting the glob-pattern to [] (which does not match anything + # because square brackets match to any of the characters inside the + # brackets) means we do not actually match any files. + # [This may become less awful in CMake-3.23.0, where it may be possible to + # filter by prefix, not just directory, see + # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6880] + file(GLOB_RECURSE BOUT_IGNORE_CONDA_ENV_DIRECTORY_LIST + LIST_DIRECTORIES true + $ENV{CONDA_PREFIX}/[]) + list (APPEND CMAKE_IGNORE_PATH ${BOUT_IGNORE_CONDA_ENV_DIRECTORY_LIST}) + endif() +endif() + # This might not be entirely sensible, but helps CMake to find the # correct MPI, workaround for https://gitlab.kitware.com/cmake/cmake/issues/18895 find_program(MPIEXEC_EXECUTABLE NAMES mpiexec mpirun) diff --git a/bout++Config.cmake.in b/bout++Config.cmake.in index b62e8057d0..3909f71a7f 100644 --- a/bout++Config.cmake.in +++ b/bout++Config.cmake.in @@ -75,6 +75,13 @@ if(EXISTS "@HDF5F_ROOT@") endif() if(EXISTS "@PVODE_ROOT@") set(PVODE_ROOT "@PVODE_ROOT@") +elseif(EXISTS "@PVODE_DIR@") + set(PVODE_DIR "@PVODE_DIR@") +elseif(EXISTS "@PVODE_BINARY_DIR@") + set(PVODE_DIR "@PVODE_BINARY_DIR@") +endif() +if(EXISTS "@Libuuid_ROOT@") + set(Libuuid_ROOT "@Libuuid_ROOT@") endif() if(@BOUT_USE_SYSTEM_MPARK_VARIANT@) @@ -91,6 +98,7 @@ if (BOUT_USE_OPENMP) find_dependency(OpenMP) endif() if (BOUT_HAS_NETCDF) + find_dependency(netCDF @netCDF_VERSION@) find_dependency(netCDFCxx @netCDFCxx_VERSION@) endif() if (BOUT_HAS_HDF5) diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake index bf83ffd564..e1940c687d 100644 --- a/cmake/FindFFTW.cmake +++ b/cmake/FindFFTW.cmake @@ -29,6 +29,11 @@ if (FFTW_INCLUDE_DIRS) set (FFTW_FIND_QUIETLY TRUE) endif (FFTW_INCLUDE_DIRS) +if (EXISTS ${FFTW_ROOT}) + # Make sure FFTW_ROOT is an absolute path by setting it as a 'FILEPATH' + set (FFTW_ROOT "" CACHE FILEPATH "Location of the FFTW library") +endif() + find_program(FFTW_WISDOM "fftw-wisdom" PATHS "${FFTW_ROOT}" PATH_SUFFIXES bin diff --git a/cmake/FindnetCDF.cmake b/cmake/FindnetCDF.cmake index 198fbb920b..7cc0645a29 100644 --- a/cmake/FindnetCDF.cmake +++ b/cmake/FindnetCDF.cmake @@ -27,13 +27,16 @@ include(BOUT++functions) -find_package(netCDF QUIET CONFIG) -if (netCDF_FOUND) - set(netCDF_FOUND TRUE) - if (NOT TARGET netCDF::netcdf) - bout_add_library_alias(netCDF::netcdf netcdf) +if (NOT EXISTS ${NC_CONFIG}) + # Only search if NC_CONFIG was not set explicitly + find_package(netCDF QUIET CONFIG) + if (netCDF_FOUND) + set(netCDF_FOUND TRUE) + if (NOT TARGET netCDF::netcdf) + bout_add_library_alias(netCDF::netcdf netcdf) + endif() + return() endif() - return() endif() find_program(NC_CONFIG "nc-config" diff --git a/cmake/FindnetCDFCxx.cmake b/cmake/FindnetCDFCxx.cmake index 0d7b427da5..14e086623a 100644 --- a/cmake/FindnetCDFCxx.cmake +++ b/cmake/FindnetCDFCxx.cmake @@ -27,13 +27,16 @@ include(BOUT++functions) -find_package(netCDFCxx QUIET CONFIG) -if (netCDFCxx_FOUND) - set(netCDFCxx_FOUND TRUE) - if (NOT TARGET netCDF::netcdf-cxx4) - bout_add_library_alias(netCDF::netcdf-cxx4 netcdf-cxx4) +if (NOT EXISTS ${NCXX4_CONFIG}) + # Only search if NCXX4_CONFIG was not set explicitly + find_package(netCDFCxx QUIET CONFIG) + if (netCDFCxx_FOUND) + set(netCDFCxx_FOUND TRUE) + if (NOT TARGET netCDF::netcdf-cxx4) + bout_add_library_alias(netCDF::netcdf-cxx4 netcdf-cxx4) + endif() + return() endif() - return() endif() find_package(netCDF REQUIRED) diff --git a/manual/sphinx/user_docs/advanced_install.rst b/manual/sphinx/user_docs/advanced_install.rst index 2bcf39a6d0..6fc0c89462 100644 --- a/manual/sphinx/user_docs/advanced_install.rst +++ b/manual/sphinx/user_docs/advanced_install.rst @@ -64,7 +64,10 @@ Machine-specific installation ----------------------------- These are some configurations which have been found to work on -particular machines. +particular machines. There is also the repo +https://github.com/boutproject/BOUT-configs which provides scripts for one or +two line compilation, with dependencies, of known-good versions on several +machines (different machines are in different branches). Archer ~~~~~~ diff --git a/manual/sphinx/user_docs/installing.rst b/manual/sphinx/user_docs/installing.rst index 816bd9d7ea..2e6f231058 100644 --- a/manual/sphinx/user_docs/installing.rst +++ b/manual/sphinx/user_docs/installing.rst @@ -373,7 +373,7 @@ time as your project, therefore there is no option to use an external installation for that. Using CMake with your physics model -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can write a CMake configuration file (``CMakeLists.txt``) for your physics model in only four lines: @@ -406,6 +406,28 @@ source. Doing this has the advantage that any changes you make to BOUT++ source files will trigger a rebuild of both the BOUT++ library and your model when you next build your code. +Working with an active `conda` environment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When `conda` is used, it installs separate versions of several libraries. These +can cause warnings or even failures when linking BOUT++ executables. There are +several alternatives to deal with this problem: +* The simplest but least convenient option is to use `conda deactivate` before + configuring, compiling, or running any BOUT++ program. +* You might sometimes want to link to the conda-installed libraries. This is + probably not ideal for production runs on an HPC system (as conda downloads + binary packages that will not be optimized for specific hardware), but can be + a simple way to get packages for testing or on a personal computer. In this + case just keep your `conda` environment active, and with luck the libraries + should be picked up by the standard search mechanisms. +* In case you do want a fully optimized and as-stable-as-possible build for + production runs, it is probably best not to depend on any conda packages for + compiling or running BOUT++ executables (restrict `conda` to providing Python + packages for post-processing, and their dependencies). Passing + `-DBOUT_IGNORE_CONDA_ENV=ON` (default `OFF`) excludes anything in the conda + environment from CMake search paths. This should totally separate BOUT++ from + the `conda` environment. + .. _sec-config-nls: Natural Language Support