]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMakes: Preprocess testsuite parameter files
authorMatthias Maier <tamiko@43-1.org>
Wed, 21 Mar 2018 15:20:03 +0000 (10:20 -0500)
committerMatthias Maier <tamiko@43-1.org>
Wed, 21 Mar 2018 15:20:03 +0000 (10:20 -0500)
Add a third test variant consisting of a .prm.in file:
  test.output
  test.prm.in

The test.prm.in file is preprocessed by CONFIGURE_FEATURE to a test.prm
file substituting all @VARIABLE@ string with the corresponding CMake
variable.

cmake/macros/macro_deal_ii_add_test.cmake

index 5dbb375df69d85c04993aa6d5f7721627a430843..bcfd45b7410c33305805e41b3340bc0df4eedc13 100644 (file)
 #     TEST_TARGET or
 #     TEST_TARGET_DEBUG and TEST_TARGET_RELEASE
 #
+# - If the parameter file in the second test variant is named
+#   "${test_name}.prm.in" it will be configured/preprocessed to a
+#   "${test_name}.prm" file. This preprocessing is done with the CMake
+#   macro CONFIGURE_FILE that replaces all strings @VARIABLE@ with the
+#   contents of the corresponding CMake variable. This is useful in
+#   particular to conveniently substitute @SOURCE_DIR@ with the full source
+#   directory path of the test.
+#
 # For every deal.II build type (given by the variable DEAL_II_BUILD_TYPES)
 # that is a (case insensitive) substring of CMAKE_BUILD_TYPE a test is
 # defined.
@@ -180,7 +188,20 @@ MACRO(DEAL_II_ADD_TEST _category _test_name _comparison_file)
         SET(_target ${_test_name}.${_build_lowercase}) # target name
         SET(_run_args "$<TARGET_FILE:${_target}>") # the command to issue
 
-      ELSEIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm")
+      ELSEIF( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm" OR
+              EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm.in" )
+
+        IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm.in")
+          SET(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+          CONFIGURE_FILE(
+            "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm.in"
+            "${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.prm"
+            @ONLY
+            )
+          SET(_prm_file "${CMAKE_CURRENT_BINARY_DIR}/${_test_name}.prm")
+        ELSE()
+          SET(_prm_file "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm")
+        ENDIF()
 
         IF(NOT "${TEST_TARGET_${_build}}" STREQUAL "")
           SET(_target ${TEST_TARGET_${_build}})
@@ -188,14 +209,14 @@ MACRO(DEAL_II_ADD_TEST _category _test_name _comparison_file)
           SET(_target ${TEST_TARGET})
         ELSE()
           MESSAGE(FATAL_ERROR
-            "\nFor ${_comparison_file}: \"${_test_name}.prm\" provided, but "
-            "neither \"\${TEST_TARGET}\", nor \"\${TEST_TARGET_${_build}}"
+            "\nFor ${_comparison_file}: \"${_test_name}.prm(.in)\" provided, "
+            "but neither \"\${TEST_TARGET}\", nor \"\${TEST_TARGET_${_build}}"
             "\" is defined.\n\n"
             )
         ENDIF()
         SET(_run_args
           "$<TARGET_FILE:${_target}>"
-          "${CMAKE_CURRENT_SOURCE_DIR}/${_test_name}.prm"
+          "${_prm_file}"
           )
 
       ELSE()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.