diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 0d4bab29f12ea265f7271ffc15eddb5098c87419..47a4075bccaa8f4ea35e4b73e0b33d9f447296f9 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -136,6 +136,7 @@ if(BUILD_EXE) if(LAMMPS_MACHINE) set(LAMMPS_MACHINE "_${LAMMPS_MACHINE}") endif() + set(LAMMPS_BINARY lmp${LAMMPS_MACHINE}) endif() option(BUILD_LIB "Build LAMMPS library" OFF) @@ -208,6 +209,38 @@ option(CMAKE_VERBOSE_MAKEFILE "Verbose makefile" OFF) option(ENABLE_TESTING "Enable testing" OFF) if(ENABLE_TESTING) enable_testing() + + if (CMAKE_VERSION VERSION_GREATER "3.10.3") # due to FetchContent + include(FetchContent) + + + FetchContent_Declare(lammps-testing + GIT_REPOSITORY https://github.com/lammps/lammps-testing.git + GIT_TAG master + ) + + FetchContent_GetProperties(lammps-testing) + if(NOT lammps-testing_POPULATED) + message(STATUS "Downloading tests...") + FetchContent_Populate(lammps-testing) + endif() + message(STATUS "Running test discovery...") + + file(GLOB_RECURSE TEST_SCRIPTS ${lammps-testing_SOURCE_DIR}/tests/core/*/in.*) + foreach(script_path ${TEST_SCRIPTS}) + get_filename_component(TEST_NAME ${script_path} EXT) + get_filename_component(SCRIPT_NAME ${script_path} NAME) + get_filename_component(PARENT_DIR ${script_path} DIRECTORY) + string(SUBSTRING ${TEST_NAME} 1 -1 TEST_NAME) + string(REPLACE "-" "_" TEST_NAME ${TEST_NAME}) + string(REPLACE "+" "_" TEST_NAME ${TEST_NAME}) + set(TEST_NAME "test_core_${TEST_NAME}_serial") + add_test(${TEST_NAME} ${CMAKE_BINARY_DIR}/${LAMMPS_BINARY} -in ${SCRIPT_NAME}) + set_tests_properties(${TEST_NAME} PROPERTIES WORKING_DIRECTORY ${PARENT_DIR}) + endforeach() + else() + message(WARNING "Full test-suite requires CMake >= 3.11") + endif() endif(ENABLE_TESTING) set(DEFAULT_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS DIPOLE GRANULAR @@ -1119,11 +1152,11 @@ if(BUILD_EXE) endif() endif() - set_target_properties(lmp PROPERTIES OUTPUT_NAME lmp${LAMMPS_MACHINE}) + set_target_properties(lmp PROPERTIES OUTPUT_NAME ${LAMMPS_BINARY}) install(TARGETS lmp DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(FILES ${LAMMPS_DOC_DIR}/lammps.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 RENAME lmp${LAMMPS_MACHINE}.1) + install(FILES ${LAMMPS_DOC_DIR}/lammps.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 RENAME ${LAMMPS_BINARY}.1) if(ENABLE_TESTING) - add_test(ShowHelp lmp${LAMMPS_MACHINE} -help) + add_test(ShowHelp ${LAMMPS_BINARY} -help) endif() endif()