Skip to content

Commit

Permalink
Improve handling of MPI CMake option
Browse files Browse the repository at this point in the history
  • Loading branch information
taylor-a-barnes committed Jan 7, 2025
1 parent fb00591 commit 731103f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 3.7)
option(MDI_CXX "Build with CXX suport - ON (DEFAULT) or OFF)" ON)
option(MDI_Fortran "Build with Fortran support - ON (DEFAULT) or OFF)" ON)
option(MDI_Python "Build with Python support - ON (DEFAULT) or OFF)" ON)
set(MDI_USE_MPI "" CACHE STRING "Flag to use MPI - ON (DEFAULT) or OFF")

option(mpi "on or off" ON)
option(python_package "on or off" OFF)
option(plugins "on or off" ON)
option(python_plugins "on or off" ${plugins})
Expand All @@ -18,6 +18,7 @@ option(debug "on or off" OFF)
# Deprecated Options
option(language "Deprecated; use MDI_CXX, MDI_Fortran, and/or MDI_Python instead.")
option(libtype "Deprecated; use BUILD_SHARED_LIBS instead.")
set(mpi ${MDI_USE_MPI} CACHE STRING "Deprecated; use MDI_USE_MPI instead.")

set(use_C "")
set(use_CXX "")
Expand Down Expand Up @@ -55,7 +56,19 @@ project(mdi
VERSION 1.4.31
LANGUAGES ${use_C} ${use_CXX} ${use_Fortran})

# set a definition to enable MDI debug mode
# Check for MPI
if ( mpi STREQUAL "ON" )
find_package(MPI REQUIRED)
elseif( NOT ( mpi STREQUAL "OFF") )
find_package(MPI)
if ( MPI_FOUND )
set( mpi "ON" )
else()
set( mpi "OFF" )
endif()
endif()

# Set a definition to enable MDI debug mode
if( ${debug} )
add_definitions(-D_MDI_DEBUG=1)
else()
Expand Down
13 changes: 1 addition & 12 deletions MDI_Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ endmacro(string_to_list _VAR _STR)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

# Check for MPI
if ( NOT ( mpi STREQUAL "OFF") )
find_package(MPI)
endif()
if( NOT MPI_FOUND )
if( mpi STREQUAL "ON" )
message( WARNING "Could not find MPI. Compiling without MPI support." )
endif()
set(mpi "OFF")
endif()

# Confirm that "language" is a valid value
if( language AND (NOT language STREQUAL "C") AND (NOT language STREQUAL "CXX") AND (NOT language STREQUAL "Fortran") AND (NOT language STREQUAL "Python") )
message( FATAL_ERROR "Value of language not recognized. Accepted values are: C; CXX; Fortran; Python." )
Expand Down Expand Up @@ -122,7 +111,7 @@ elseif( mpi STREQUAL "OFF" )

else()

message( FATAL_ERROR "Value of mpi not recognized. Accepted values are: ON; OFF." )
message( FATAL_ERROR "Value of mpi (${mpi}) not recognized. Accepted values are: ON; OFF." )

endif()

Expand Down
15 changes: 2 additions & 13 deletions tests/MDI_Test_Codes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
# Check for MPI

if ( NOT ( mpi STREQUAL "OFF") )
find_package(MPI)
endif()
if( NOT MPI_FOUND )
if( mpi STREQUAL "ON" )
message( WARNING "Could not find MPI. Compiling without MPI support." )
endif()
# Include MPI stubs, if needed
if( mpi STREQUAL "OFF" )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/STUBS_MPI/mpi.h ${CMAKE_CURRENT_BINARY_DIR}/STUBS_MPI/mpi.h COPYONLY)
set(mpi "OFF")
endif()



# Macro to link target to MPI

macro(link_against_mpi _TAR)
if( mpi STREQUAL "ON" )

Expand Down

0 comments on commit 731103f

Please sign in to comment.