Files
lammps/unittest/fortran/CMakeLists.txt
2022-09-23 22:11:24 -05:00

67 lines
3.1 KiB
CMake

include(CheckGeneratorSupport)
if(NOT CMAKE_GENERATOR_SUPPORT_FORTRAN)
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no Fortran support in build tool")
return()
endif()
include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
enable_language(C)
enable_language(Fortran)
if(NOT CMAKE_Fortran_COMPILER_ID)
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: cannot identify Fortran compiler")
return()
endif()
get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE)
if(BUILD_MPI)
find_package(MPI REQUIRED)
if((NOT MPI_Fortran_FOUND) OR (NOT MPI_Fortran_HAVE_F77_HEADER))
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no MPI support for Fortran")
return()
endif()
else()
add_library(fmpi_stubs STATIC mpi_stubs.f90)
get_filename_component(_tmp_fc ${CMAKE_Fortran_COMPILER} NAME)
if (_tmp_fc STREQUAL "flang")
target_link_libraries(fmpi_stubs PUBLIC gfortran)
endif()
add_library(MPI::MPI_Fortran ALIAS fmpi_stubs)
endif()
add_library(flammps STATIC ${LAMMPS_FORTRAN_MODULE})
add_executable(test_fortran_create wrap_create.cpp test_fortran_create.f90)
target_link_libraries(test_fortran_create PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
target_include_directories(test_fortran_create PRIVATE "${LAMMPS_SOURCE_DIR}/../fortran")
add_test(NAME FortranOpen COMMAND test_fortran_create)
add_executable(test_fortran_commands wrap_commands.cpp test_fortran_commands.f90)
target_link_libraries(test_fortran_commands PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
add_test(NAME FortranCommands COMMAND test_fortran_commands)
add_executable(test_fortran_get_thermo wrap_get_thermo.cpp test_fortran_get_thermo.f90)
target_link_libraries(test_fortran_get_thermo PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
add_test(NAME FortranGetThermo COMMAND test_fortran_get_thermo)
add_executable(test_fortran_box wrap_box.cpp test_fortran_box.f90)
target_link_libraries(test_fortran_box PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
add_test(NAME FortranBox COMMAND test_fortran_box)
add_executable(test_fortran_properties wrap_properties.cpp test_fortran_properties.f90 test_fortran_commands.f90)
target_link_libraries(test_fortran_properties PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
add_test(NAME FortranProperties COMMAND test_fortran_properties)
add_executable(test_fortran_extract_global wrap_extract_global.cpp test_fortran_extract_global.f90)
target_link_libraries(test_fortran_extract_global PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
add_test(NAME FortranExtractGlobal COMMAND test_fortran_extract_global)
add_executable(test_fortran_extract_atom wrap_extract_atom.cpp test_fortran_extract_atom.f90)
target_link_libraries(test_fortran_extract_atom PRIVATE flammps lammps MPI::MPI_Fortran GTest::GTestMain)
add_test(NAME FortranExtractAtom COMMAND test_fortran_extract_atom)
else()
message(STATUS "Skipping Tests for the LAMMPS Fortran Module: no Fortran compiler")
endif()