Skip to content

Commit

Permalink
Merge pull request #2494 from boutproject/cmake-more-fixes
Browse files Browse the repository at this point in the history
CMake: option to ignore a conda environment; fix for PVODE
  • Loading branch information
johnomotani authored Feb 4, 2022
2 parents 1c44d41 + ba9de49 commit 5772080
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions bout++Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@)
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmake/FindFFTW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions cmake/FindnetCDF.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 9 additions & 6 deletions cmake/FindnetCDFCxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion manual/sphinx/user_docs/advanced_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~
Expand Down
24 changes: 23 additions & 1 deletion manual/sphinx/user_docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5772080

Please sign in to comment.