Skip to content

Update CMakeLists.txt to enable build with C#3101

Merged
bendudson merged 4 commits into
boutproject:masterfrom
tbody-cfs:patch-1
Apr 18, 2025
Merged

Update CMakeLists.txt to enable build with C#3101
bendudson merged 4 commits into
boutproject:masterfrom
tbody-cfs:patch-1

Conversation

@tbody-cfs
Copy link
Copy Markdown
Contributor

See discussion in #2945

Comment thread CMakeLists.txt Outdated
DESCRIPTION "Fluid PDE solver framework"
VERSION ${BOUT_CMAKE_ACCEPTABLE_VERSION}
LANGUAGES CXX)
LANGUAGES C CXX)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding C as a top level language, could we move this line of code

enable_language(C)

between these two if statements?
if (BOUT_USE_SUNDIALS)
if (BOUT_DOWNLOAD_SUNDIALS)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this as a patch

diff --git a/cmake/SetupBOUTThirdParty.cmake b/cmake/SetupBOUTThirdParty.cmake
index 10942f8aa..2b2cefa22 100644
--- a/cmake/SetupBOUTThirdParty.cmake
+++ b/cmake/SetupBOUTThirdParty.cmake
@@ -271,7 +271,8 @@ option(BOUT_DOWNLOAD_SUNDIALS "Download and build SUNDIALS" OFF)
 # Force BOUT_USE_SUNDIALS if we're downloading it!
 cmake_dependent_option(BOUT_USE_SUNDIALS "Enable support for SUNDIALS time solvers" OFF
   "NOT BOUT_DOWNLOAD_SUNDIALS" ON)
-if (BOUT_USE_SUNDIALS)
+if (BOUT_USE_SUNDIALS)	
+  enable_language(C)
   if (BOUT_DOWNLOAD_SUNDIALS)
     message(STATUS "Downloading and configuring SUNDIALS")
     include(FetchContent)
@@ -293,7 +294,6 @@ if (BOUT_USE_SUNDIALS)
     FetchContent_MakeAvailable(sundials)
     message(STATUS "SUNDIALS done configuring")
   else()
-    enable_language(C)
     find_package(SUNDIALS REQUIRED)
     if (SUNDIALS_VERSION VERSION_LESS 4.0.0)
       message(FATAL_ERROR "SUNDIALS_VERSION 4.0.0 or newer is required. Found version ${SUNDIALS_VERSION}.")

and this as my cmake command

cmake -B ${BOUTPP_BUILD_DIR} -S ${BOUTPP_SRC_DIR} \
-Wno-dev \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_CXX_COMPILER=mpic++ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBOUT_UPDATE_GIT_SUBMODULE=OFF \
-DBOUT_ENABLE_PYTHON=ON \
-DBOUT_USE_SYSTEM_MPARK_VARIANT=OFF \
-DBOUT_USE_HYPRE=OFF \
-DBOUT_USE_PETSC=ON \
-DBOUT_USE_SLEPC=ON \
-DBOUT_USE_SUNDIALS=ON \
-DBOUT_USE_NLS=OFF \
-DBOUT_ENABLE_METRIC_3D=OFF \
-DBOUT_GENERATE_FIELDOPS=OFF

I still recieve the error Reason given by package: MPI component 'C' was requested, but language C is not enabled.. There must be another instance where C is being requested, but I'm not sure how to hunt this down.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Steven-Roberts that this is a nicer fix. Please could you add:

  find_package(MPI REQUIRED COMPONENTS C)

on the line immediately after enable_language(C)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't fix the error. Looking at the full error report, this actually seems to be coming from NetCDF

CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find MPI (missing: MPI_C_FOUND C)

      Reason given by package: MPI component 'C' was requested, but language C is not enabled.  

Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.22/Modules/FindMPI.cmake:1830 (find_package_handle_standard_args)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/spack-environment/.spack-env/view/lib/cmake/netCDF/netCDFConfig.cmake:32 (find_dependency)
  cmake/FindnetCDF.cmake:35 (find_package)
  cmake/FindnetCDFCxx.cmake:46 (find_package)
  cmake/SetupBOUTThirdParty.cmake:172 (find_package)
  CMakeLists.txt:474 (include)

I've now added enable_language(C) to the FindNetCDF.

Copy link
Copy Markdown
Contributor Author

@tbody-cfs tbody-cfs Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3c3aca6 compiles with

cmake -B ${BOUTPP_BUILD_DIR} -S ${BOUTPP_SRC_DIR} \
-Wno-dev \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_CXX_COMPILER=mpic++ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBOUT_UPDATE_GIT_SUBMODULE=OFF \
-DBOUT_ENABLE_PYTHON=ON \
-DBOUT_USE_SYSTEM_MPARK_VARIANT=OFF \
-DBOUT_USE_HYPRE=OFF \
-DBOUT_USE_PETSC=ON \
-DBOUT_USE_SLEPC=ON \
-DBOUT_USE_SUNDIALS=ON \
-DBOUT_USE_NLS=OFF \
-DBOUT_USE_NETCDF=OFF \
-DBOUT_ENABLE_METRIC_3D=OFF \
-DBOUT_GENERATE_FIELDOPS=OFF

With this build, I don't need enable(C) for SUNDIALS to configure, even though I've disabled NetCDF. However, this fails to build since NetCDF is required for a lot of functions.

@bendudson
Copy link
Copy Markdown
Contributor

Thanks @tbody-cfs ! I think we also should enable C when SUNDIALS is enabled, in case BOUT++ is configured without NetCDF (e.g using ADIOS2). The patch

   if (BOUT_USE_SUNDIALS)	
+  enable_language(C)

should be sufficient I think.

@tbody-cfs
Copy link
Copy Markdown
Contributor Author

Thanks @tbody-cfs ! I think we also should enable C when SUNDIALS is enabled, in case BOUT++ is configured without NetCDF (e.g using ADIOS2). The patch

   if (BOUT_USE_SUNDIALS)	
+  enable_language(C)

should be sufficient I think.

Hi Ben,
I've now put C back in for SUNDIALS.

@bendudson bendudson merged commit f264632 into boutproject:master Apr 18, 2025
8 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants