Update CMakeLists.txt to enable build with C#3101
Conversation
| DESCRIPTION "Fluid PDE solver framework" | ||
| VERSION ${BOUT_CMAKE_ACCEPTABLE_VERSION} | ||
| LANGUAGES CXX) | ||
| LANGUAGES C CXX) |
There was a problem hiding this comment.
Instead of adding C as a top level language, could we move this line of code
BOUT-dev/cmake/SetupBOUTThirdParty.cmake
Line 296 in b70f79f
between these two if statements?
BOUT-dev/cmake/SetupBOUTThirdParty.cmake
Lines 274 to 275 in b70f79f
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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 should be sufficient I think. |
Hi Ben, |
See discussion in #2945