create alias target MPI::ANY_CXX to be used instead of MPI::MPI_CXX

With this alias it is possible to transparently refer to either the
real imported MPI library or to the MPI stub library. this further
reduced the need for if statements related to MPI. Some uses of
MPI::MPI_CXX remain but they are all in branches of the script code
where BUILD_MPI is enabled and thus the imported target will be present.
This commit is contained in:
Axel Kohlmeyer
2022-01-30 07:48:16 -05:00
parent 99cb494594
commit dc0e013297
2 changed files with 5 additions and 12 deletions

View File

@ -290,13 +290,14 @@ if(BUILD_MPI)
target_compile_definitions(lammps PRIVATE -DLAMMPS_LONGLONG_TO_LONG)
endif()
endif()
target_link_libraries(lammps PUBLIC MPI::MPI_CXX)
add_library(MPI::ANY_CXX ALIAS MPI::MPI_CXX)
else()
target_sources(lammps PRIVATE ${LAMMPS_SOURCE_DIR}/STUBS/mpi.cpp)
add_library(mpi_stubs INTERFACE)
target_include_directories(mpi_stubs INTERFACE $<BUILD_INTERFACE:${LAMMPS_SOURCE_DIR}/STUBS>)
target_link_libraries(lammps PUBLIC mpi_stubs)
add_library(MPI::ANY_CXX ALIAS mpi_stubs)
endif()
target_link_libraries(lammps PUBLIC MPI::ANY_CXX)
set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)")
set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall)
@ -577,11 +578,7 @@ if(PKG_ATC)
if(LAMMPS_SIZES STREQUAL "BIGBIG")
message(FATAL_ERROR "The ATC Package is not compatible with -DLAMMPS_BIGBIG")
endif()
if(BUILD_MPI)
target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::MPI_CXX)
else()
target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} mpi_stubs)
endif()
target_link_libraries(atc PRIVATE ${LAPACK_LIBRARIES} MPI::ANY_CXX)
target_include_directories(atc PRIVATE ${LAMMPS_SOURCE_DIR})
target_compile_definitions(atc PRIVATE -DLAMMPS_${LAMMPS_SIZES})
endif()

View File

@ -422,11 +422,7 @@ RegisterStylesExt(${GPU_SOURCES_DIR} gpu GPU_SOURCES)
RegisterFixStyle(${GPU_SOURCES_DIR}/fix_gpu.h)
get_property(GPU_SOURCES GLOBAL PROPERTY GPU_SOURCES)
if(BUILD_MPI)
target_link_libraries(gpu PRIVATE MPI::MPI_CXX)
else()
target_link_libraries(gpu PRIVATE mpi_stubs)
endif()
target_link_libraries(gpu PRIVATE MPI::ANY_CXX)
target_compile_definitions(gpu PRIVATE -DLAMMPS_${LAMMPS_SIZES})
set_target_properties(gpu PROPERTIES OUTPUT_NAME lammps_gpu${LAMMPS_MACHINE})