Squash SYCL DeviceContext and DeviceStream
[alexxy/gromacs.git] / src / testutils / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2011,2012,2013,2014,2015 by the GROMACS development team.
5 # Copyright (c) 2016,2017,2018,2019,2020, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
9 #
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
14 #
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 #
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
32 #
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
35
36 if (NOT GMX_BUILD_UNITTESTS)
37     gmx_add_missing_tests_notice("Unit tests have not been run. You need to set GMX_BUILD_UNITTESTS=ON if you want to build and run them.")
38     return()
39 endif()
40
41 set(TESTUTILS_SOURCES
42     cmdlinetest.cpp
43     conftest.cpp
44     filematchers.cpp
45     interactivetest.cpp
46     loggertest.cpp
47     mpi_printer.cpp
48     mpitest.cpp
49     refdata.cpp
50     refdata_xml.cpp
51     simulationdatabase.cpp
52     stdiohelper.cpp
53     stringtest.cpp
54     testasserts.cpp
55     testfilemanager.cpp
56     testfileredirector.cpp
57     test_device.cpp
58     test_hardware_environment.cpp
59     testinit.cpp
60     testmatchers.cpp
61     testoptions.cpp
62     textblockmatchers.cpp
63     tprfilegenerator.cpp
64     xvgtest.cpp
65     )
66
67 if(NOT HAVE_TINYXML2)
68     list(APPEND TESTUTILS_SOURCES ../external/tinyxml2/tinyxml2.cpp)
69 endif()
70
71 if (GMX_GPU_CUDA)
72     # Work around FindCUDA that prevents using target_link_libraries()
73     # with keywords otherwise...
74     set(CUDA_LIBRARIES PRIVATE ${CUDA_LIBRARIES})
75     if (NOT GMX_CLANG_CUDA)
76         gmx_cuda_add_library(testutils ${TESTUTILS_SOURCES})
77     else()
78         add_library(testutils STATIC ${TESTUTILS_SOURCES})
79     endif()
80     target_link_libraries(testutils PRIVATE ${CUDA_CUFFT_LIBRARIES})
81 else()
82     add_library(testutils STATIC ${UNITTEST_TARGET_OPTIONS} ${TESTUTILS_SOURCES})
83 endif()
84
85 if (GMX_GPU_SYCL)
86     set_source_files_properties(test_device.cpp
87       PROPERTIES COMPILE_FLAGS "${SYCL_CXX_FLAGS}")
88 endif()
89
90 gmx_target_compile_options(testutils)
91 target_compile_definitions(testutils PRIVATE HAVE_CONFIG_H)
92 target_include_directories(testutils SYSTEM BEFORE PRIVATE ${PROJECT_SOURCE_DIR}/src/external/thread_mpi/include)
93 target_link_libraries(testutils PRIVATE libgromacs ${GMX_COMMON_LIBRARIES} gmock)
94
95 if(HAVE_TINYXML2)
96     include_directories(SYSTEM ${TinyXML2_INCLUDE_DIR})
97     target_link_libraries(testutils PRIVATE ${TinyXML2_LIBRARIES})
98 else()
99     include_directories(BEFORE SYSTEM "../external/tinyxml2")
100 endif()
101
102 # TODO Use gmx_add_missing_tests_notice() instead of the messages below.
103 set(GMX_CAN_RUN_MPI_TESTS 1)
104 if (GMX_MPI)
105     set(_an_mpi_variable_had_content 0)
106     foreach(VARNAME MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS)
107         # These variables need a valid value for the test to run
108         # and pass, but conceivably any of them might be valid
109         # with arbitrary (including empty) content. They can't be
110         # valid if they've been populated with the CMake
111         # find_package magic suffix/value "NOTFOUND", though.
112         if (${VARNAME} MATCHES ".*NOTFOUND")
113             message(STATUS "CMake variable ${VARNAME} was not detected to be a valid value. To test GROMACS correctly, check the advice in the install guide.")
114             set(GMX_CAN_RUN_MPI_TESTS 0)
115         endif()
116         if (NOT VARNAME STREQUAL MPIEXEC AND ${VARNAME})
117             set(_an_mpi_variable_had_content 1)
118         endif()
119     endforeach()
120     if(_an_mpi_variable_had_content AND NOT MPIEXEC)
121         message(STATUS "CMake variable MPIEXEC must have a valid value if one of the other related MPIEXEC variables does. To test GROMACS correctly, check the advice in the install guide.")
122         set(GMX_CAN_RUN_MPI_TESTS 0)
123     endif()
124 elseif (NOT GMX_THREAD_MPI)
125     set(GMX_CAN_RUN_MPI_TESTS 0)
126 endif()
127
128 set(TESTUTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
129 set(TESTUTILS_DIR ${TESTUTILS_DIR} PARENT_SCOPE)
130 set(GMX_CAN_RUN_MPI_TESTS ${GMX_CAN_RUN_MPI_TESTS} PARENT_SCOPE)
131
132 add_subdirectory(tests)