Restore CMake convenience targets for sample_restraint.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Wed, 23 Oct 2019 16:00:51 +0000 (19:00 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 31 Oct 2019 15:51:34 +0000 (16:51 +0100)
When building GROMACS with GMX_PYTHON_PACKAGE=ON, the Python and C++
tests in python_packaging/sample_restraint are configured for use in
the GROMACS build tree. Let the tests in
python_packaging/sample_restraint use input data from
src/testutils/simulationdatabase.

Refs #2961

Change-Id: Ida104dc224e7a6af3874bd0604439033fe4f72a1

python_packaging/sample_restraint/tests/CMakeLists.txt

index de31ecc843c8d849338525c99c43504f6ce5f825..7d915f3d0072fbc5bd3376a0801ac8d7202b6222 100644 (file)
@@ -64,34 +64,63 @@ if (GMXAPI_EXTENSION_MASTER_PROJECT)
         message(WARNING "Could not download test data: ${_download_log}")
     endif()
     unset(_status)
+    add_custom_target(spc2_water_box
+                      COMMAND cmake -E echo
+                      SOURCES ${CMAKE_CURRENT_BINARY_DIR}/topol.tpr
+                      )
+else()
+    # We are in the GROMACS build tree.
+    # We just need a simple TPR input file. The 6 atom spc water box will suffice.
+    if (NOT TARGET gmx)
+        message(FATAL_ERROR "Trying to use gmx wrapper binary, but gmx target not defined.")
+    endif()
+    set(_mdp ${CMAKE_CURRENT_BINARY_DIR}/grompp.mdp)
+    file(WRITE ${_mdp} "integrator = md\n")
+    file(APPEND ${_mdp} "nsteps = 6")
+    set(_gro ${CMAKE_SOURCE_DIR}/src/testutils/simulationdatabase/spc2.gro)
+    set(_top ${CMAKE_SOURCE_DIR}/src/testutils/simulationdatabase/spc2.top)
+    add_custom_target(spc2_water_box
+                      BYPRODUCTS topol.tpr
+                      COMMAND gmx -quiet grompp -f ${_mdp} -c ${_gro} -p ${_top}
+                      DEPENDS gmx ${_mdp}
+                      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+                      COMMENT "Generating input file for sample_restraint tests.")
+    unset(_mdp)
+    unset(_gro)
+    unset(_top)
+endif ()
 
-    # Note: Expects topol.tpr to be in CURRENT_BINARY_DUR
-    configure_file(testingconfiguration.in.h testingconfiguration.h)
+# Note: Expects topol.tpr to be in CURRENT_BINARY_DUR
+configure_file(testingconfiguration.in.h testingconfiguration.h)
 
-    # Test that the library can access its dependencies and build.
-    add_executable(library-test test_binding.cpp)
-    target_include_directories(library-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-    target_link_libraries(library-test Gromacs::gmxapi GTest::Main)
-    gtest_add_tests(TARGET library-test
-                    TEST_LIST BasicPlugin)
+# Test that the library can access its dependencies and build.
+add_executable(library-test test_binding.cpp)
+add_dependencies(library-test spc2_water_box)
+target_include_directories(library-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(library-test Gromacs::gmxapi GTest::Main)
+gtest_add_tests(TARGET library-test
+                TEST_LIST BasicPlugin)
 
-    # Test the C++ force evaluation for the restrained-ensemble biasing potential.
-    add_executable(histogram-test test_histogram.cpp)
-    target_include_directories(histogram-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-    set_target_properties(histogram-test PROPERTIES SKIP_BUILD_RPATH FALSE)
-    target_link_libraries(histogram-test ensemblepotential Gromacs::gmxapi
-                          GTest::Main)
-    gtest_add_tests(TARGET histogram-test
-                    TEST_LIST EnsembleHistogramPotentialPlugin)
+# Test the C++ force evaluation for the restrained-ensemble biasing potential.
+add_executable(histogram-test test_histogram.cpp)
+add_dependencies(histogram-test spc2_water_box)
+target_include_directories(histogram-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+set_target_properties(histogram-test PROPERTIES SKIP_BUILD_RPATH FALSE)
+target_link_libraries(histogram-test ensemblepotential Gromacs::gmxapi
+                      GTest::Main)
+gtest_add_tests(TARGET histogram-test
+                TEST_LIST EnsembleHistogramPotentialPlugin)
 
-    # Test the flat-bottom bounding potential built in to the ensemble restraint.
-    add_executable(bounding-test test_bounding_restraint.cpp)
-    target_include_directories(bounding-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-    set_target_properties(bounding-test PROPERTIES SKIP_BUILD_RPATH FALSE)
-    target_link_libraries(bounding-test ensemblepotential Gromacs::gmxapi
-                          GTest::Main)
-    gtest_add_tests(TARGET bounding-test
-                    TEST_LIST EnsembleBoundingPotentialPlugin)
+# Test the flat-bottom bounding potential built in to the ensemble restraint.
+add_executable(bounding-test test_bounding_restraint.cpp)
+add_dependencies(bounding-test spc2_water_box)
+target_include_directories(bounding-test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+set_target_properties(bounding-test PROPERTIES SKIP_BUILD_RPATH FALSE)
+target_link_libraries(bounding-test ensemblepotential Gromacs::gmxapi
+                      GTest::Main)
+gtest_add_tests(TARGET bounding-test
+                TEST_LIST EnsembleBoundingPotentialPlugin)
 
+if (NOT GMXAPI_EXTENSION_MASTER_PROJECT)
     include(CMakeGROMACS.txt)
 endif ()