1 if(DOWNLOAD_GOOGLETEST)
2 # Download and unpack googletest at configure time
3 configure_file(CMakeLists.gtest.in googletest-download/CMakeLists.txt)
4 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
6 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
8 message(WARNING "CMake step for googletest failed: ${result}")
9 # message(FATAL_ERROR "CMake step for googletest failed: ${result}")
11 execute_process(COMMAND ${CMAKE_COMMAND} --build .
12 RESULT_VARIABLE result
13 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
15 message(WARNING "Build step for googletest failed: ${result}")
16 # message(FATAL_ERROR "Build step for googletest failed: ${result}")
19 # Add googletest directly to our build. This defines
20 # the gtest and gtest_main targets.
21 add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
22 ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
24 add_library(GTest::GTest ALIAS gtest)
25 add_library(GTest::Main ALIAS gtest_main)
27 if(GMXAPI_EXTENSION_MASTER_PROJECT)
28 find_package(GTest REQUIRED)
29 else() # building as part of a GROMACS build...
31 add_library(GTest::GTest ALIAS gtest)
32 add_library(GTest::Main ALIAS gtest_main)
36 if(NOT TARGET GTest::GTest)
37 message(FATAL_ERROR "GTest::GTest target should have been supplied by the parent project.")
39 if(NOT TARGET GTest::Main)
40 message(FATAL_ERROR "GTest::Main target should have been supplied by the parent project.")
43 endif() # DOWNLOAD_GOOGLETEST
51 if (GMXAPI_EXTENSION_MASTER_PROJECT)
52 # TODO: Deduplicate and leverage CMake dependencies.
53 # We also build a test file in the spc_water_box pytest test fixture, but we can
54 # presumably extract both of those from the GROMACS installation, or at least
55 # through the gmxapi Python package resources.
56 # Ref: https://gitlab.com/gromacs/gromacs/-/issues/2961
58 https://github.com/kassonlab/sample_restraint/raw/master/tests/data/topol.tpr
59 ${CMAKE_CURRENT_BINARY_DIR}/topol.tpr
60 STATUS _download_status
62 list(GET _download_status 0 _status)
63 if(${_status} GREATER 0)
64 message(WARNING "Could not download test data: ${_download_log}")
67 add_custom_target(gmxapi_extension_spc2_water_box
69 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/topol.tpr
72 # We are in the GROMACS build tree.
73 # We just need a simple TPR input file. The 6 atom spc water box will suffice.
75 message(FATAL_ERROR "Trying to use gmx wrapper binary, but gmx target not defined.")
77 set(_mdp ${CMAKE_CURRENT_BINARY_DIR}/grompp.mdp)
78 file(WRITE ${_mdp} "integrator = md\n")
79 file(APPEND ${_mdp} "nsteps = 6")
80 set(_gro ${CMAKE_SOURCE_DIR}/src/testutils/simulationdatabase/spc2.gro)
81 set(_top ${CMAKE_SOURCE_DIR}/src/testutils/simulationdatabase/spc2.top)
82 add_custom_target(gmxapi_extension_spc2_water_box
84 COMMAND gmx -quiet grompp -f ${_mdp} -c ${_gro} -p ${_top}
86 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
87 COMMENT "Generating input file for sample_restraint tests.")
93 # Note: Expects topol.tpr to be in CURRENT_BINARY_DUR
94 configure_file(testingconfiguration.in.h testingconfiguration.h)
96 # Test that the library can access its dependencies and build.
97 add_executable(gmxapi_extension_library-test test_binding.cpp)
98 add_dependencies(gmxapi_extension_library-test gmxapi_extension_spc2_water_box)
99 target_include_directories(gmxapi_extension_library-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
100 target_link_libraries(gmxapi_extension_library-test Gromacs::libgromacs Gromacs::gmxapi GTest::Main)
101 gtest_add_tests(TARGET gmxapi_extension_library-test
102 TEST_LIST BasicPlugin)
104 # Test the C++ force evaluation for the restrained-ensemble biasing potential.
105 add_executable(gmxapi_extension_histogram-test test_histogram.cpp)
106 add_dependencies(gmxapi_extension_histogram-test gmxapi_extension_spc2_water_box)
107 target_include_directories(gmxapi_extension_histogram-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
108 set_target_properties(gmxapi_extension_histogram-test PROPERTIES SKIP_BUILD_RPATH FALSE)
109 target_link_libraries(gmxapi_extension_histogram-test gmxapi_extension_ensemblepotential Gromacs::gmxapi
111 gtest_add_tests(TARGET gmxapi_extension_histogram-test
112 TEST_LIST EnsembleHistogramPotentialPlugin)
114 # Test the flat-bottom bounding potential built in to the ensemble restraint.
115 add_executable(gmxapi_extension_bounding-test test_bounding_restraint.cpp)
116 add_dependencies(gmxapi_extension_bounding-test gmxapi_extension_spc2_water_box)
117 target_include_directories(gmxapi_extension_bounding-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
118 set_target_properties(gmxapi_extension_bounding-test PROPERTIES SKIP_BUILD_RPATH FALSE)
119 target_link_libraries(gmxapi_extension_bounding-test gmxapi_extension_ensemblepotential Gromacs::gmxapi
121 gtest_add_tests(TARGET gmxapi_extension_bounding-test
122 TEST_LIST EnsembleBoundingPotentialPlugin)
124 if (NOT GMXAPI_EXTENSION_MASTER_PROJECT)
125 include(CMakeGROMACS.txt)