Add initial support for python bindings
[alexxy/gromacs.git] / tests / CMakeLists.txt
index 078807afa1fbc9e1e9b3348e77d7e4c89c21a489..3bd404724f3ba8cd9b703fe6ef00fd71afbff6b1 100644 (file)
@@ -1,10 +1,10 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013, by the GROMACS development team, led by
-# David van der Spoel, Berk Hess, Erik Lindahl, and including many
-# others, as listed in the AUTHORS file in the top-level source
-# directory and at http://www.gromacs.org.
+# Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
 #
 # GROMACS is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public License
 #
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
-#
+
 set(REGRESSIONTEST_PATH "" CACHE PATH "Directory containing regressiontests")
 mark_as_advanced(REGRESSIONTEST_PATH)
 option(REGRESSIONTEST_DOWNLOAD
-    "Automatically download regressiontests. Tests can be run with ctest." no)
-if(REGRESSIONTEST_DOWNLOAD AND CMAKE_VERSION VERSION_LESS "2.8.2")
-    message(WARNING "REGRESSIONTEST_DOWNLOAD requires cmake >=2.8.2. Please update cmake or manually download the regressiontests.")
-    set(REGRESSIONTEST_DOWNLOAD FALSE CACHE BOOL 
-        "REGRESSIONTEST_DOWNLOAD not supported with cmake ${CMAKE_VERSION}" FORCE)
-endif()
+    "Automatically download regressiontests. Tests can be run with ctest." OFF)
+
 if(REGRESSIONTEST_DOWNLOAD)
-    if("${PROJECT_VERSION}" MATCHES "-dev")
-       if("${PROJECT_VERSION}" MATCHES "^5[.]")
-          set(REGRESSIONTEST_URL http://gerrit.gromacs.org/snapshot/refs/heads/master)
-       else()
-          set(REGRESSIONTEST_URL http://gerrit.gromacs.org/snapshot/refs/heads/release-4-6)
-      endif()
-      set(REGRESSIONTEST_PATH "${CMAKE_CURRENT_BINARY_DIR}/regressiontests"
-           CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
+    if (NOT SOURCE_IS_SOURCE_DISTRIBUTION)
+        set(REGRESSIONTEST_URL http://gerrit.gromacs.org/snapshot/${REGRESSIONTEST_BRANCH})
+        set(REGRESSIONTEST_PATH "${CMAKE_CURRENT_BINARY_DIR}/regressiontests"
+            CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
     else()
-        if(NOT REGRESSIONTEST_VERSION)
-          message(FATAL_ERROR "The configuration files do not specify what regressiontests tarball is suitable for automated download and testing. Please obtain and use a suitable set of tests yourself.")
-        endif()
         set(REGRESSIONTEST_URL http://gerrit.gromacs.org/download/regressiontests-${REGRESSIONTEST_VERSION}.tar.gz)
         set(REGRESSIONTEST_PATH
-           "${CMAKE_CURRENT_BINARY_DIR}/regressiontests-${REGRESSIONTEST_VERSION}"
-           CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
+            "${CMAKE_CURRENT_BINARY_DIR}/regressiontests-${REGRESSIONTEST_VERSION}"
+            CACHE PATH "Path to auto-downloaded regressiontests" FORCE)
     endif()
     set(REGRESSIONTEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/regressiontests.tgz")
     message("Downloading: ${REGRESSIONTEST_URL}")
@@ -71,6 +60,12 @@ status_code: ${status_code}
 status_string: ${status_string}
 log: ${log}")
     endif()
+    if (SOURCE_IS_SOURCE_DISTRIBUTION)
+        file(MD5 ${REGRESSIONTEST_FILE} COMPUTED_MD5SUM)
+        if(NOT ${REGRESSIONTEST_MD5SUM} STREQUAL ${COMPUTED_MD5SUM})
+            message(FATAL_ERROR "Download of regressiontests failed. Expected MD5 of ${REGRESSIONTEST_MD5SUM} but download has ${COMPUTED_MD5SUM}")
+        endif()
+    endif()
 
     file(REMOVE_RECURSE "${REGRESSIONTEST_PATH}") #delete potential prior folder
     execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${REGRESSIONTEST_FILE}"
@@ -81,11 +76,14 @@ log: ${log}")
     set(REGRESSIONTEST_DOWNLOAD OFF CACHE BOOL "Tests already downloaded. Set to yes to download again" FORCE)
 endif()
 
-if(REGRESSIONTEST_PATH AND (GMX_BLUEGENE OR CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES))
-    #Bluegene requires us to compile both front-end and back-end binaries (single build is insufficient)
-    message(WARNING 
-        "With cross-compiling or multi-configuration generators (e.g. Visual Studio), running regressiontests from build system is not supported. Please run gmxtest.pl directly.")
-    set(REGRESSIONTEST_PATH OFF CACHE BOOL 
+if(REGRESSIONTEST_PATH AND (GMX_BLUEGENE OR CMAKE_CROSSCOMPILING OR CMAKE_CONFIGURATION_TYPES OR GMX_BUILD_MDRUN_ONLY))
+    # TODO: It would be nicer to do these before potentially downloading the tests.
+    # Bluegene requires us to compile both front-end and back-end binaries
+    # (single build is insufficient)
+    # Testing an mdrun-only builds require supporting binaries from a full build
+    message(WARNING
+        "With cross-compiling, multi-configuration generators (e.g. Visual Studio), or with mdrun-only builds, running regressiontests from build system is not supported. Please run gmxtest.pl directly.")
+    set(REGRESSIONTEST_PATH OFF CACHE BOOL
         "With cross-compiling or multi-configuration generators, running regressiontests from build system is not supported." FORCE)
 endif()
 
@@ -94,6 +92,11 @@ if(REGRESSIONTEST_PATH)
         message(FATAL_ERROR
             "REGRESSIONTEST_PATH invalid. The path needs to contain gmxtest.pl.")
     endif()
+
+    # gmxtests target builds all binaries required for running gmxtest
+    add_custom_target(gmxtests DEPENDS gmx)
+    add_dependencies(check gmxtests)
+
     if(GMX_DOUBLE)
         list(APPEND ARGS -double)
     endif()
@@ -138,9 +141,9 @@ if(REGRESSIONTEST_PATH)
         set(PATH "$ENV{PATH}")
     endif()
 
-    foreach(FOLDER kernel tools gmxlib mdlib) #lib folders might be needed for
+    foreach(FOLDER bin lib) #lib folders might be needed for
         #e.g. DLLs. For GMX paths native ("\") is needed for GMXLIB detection
-        file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/src/${FOLDER}" DIR)
+        file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${FOLDER}" DIR)
         set(PATH "${DIR}${PATH_SEPARATOR}${PATH}")
     endforeach()
 
@@ -157,6 +160,14 @@ if(REGRESSIONTEST_PATH)
             #windows requires the command to be perl and not the script
             COMMAND perl "${REGRESSIONTEST_PATH}/gmxtest.pl" ${subtest} ${ARGS})
         set_tests_properties(regressiontests/${subtest} PROPERTIES
-            ENVIRONMENT "PATH=${PATH};GMXLIB=${CMAKE_SOURCE_DIR}/share/top")
+            ENVIRONMENT "PATH=${PATH}")
     endforeach()
+else()
+    add_custom_target(regressiontests-notice
+        ${CMAKE_COMMAND} -E echo "NOTE: Regression tests have not been run. If you want to run them from the build system, get the correct version of the regression tests package and set REGRESSIONTEST_PATH in CMake to point to it, or set REGRESSIONTEST_DOWNLOAD=ON."
+        DEPENDS run-ctest
+        COMMENT "Regression tests not available" VERBATIM)
+    add_dependencies(check regressiontests-notice)
 endif()
+
+include(CppCheck.cmake)