Browse Source

Add infrastructure for CMake-only tests

Some tests only need to run CMake to configure and generate a build
tree, but not actually perform the build.  Add a new "Tests/CMakeOnly"
directory dedicated for this purpose.  Add a helper script to drive each
test by creating a fresh build tree and running CMake on it.  Add macro
"add_CMakeOnly_test" to help create tests using the script.
Brad King 14 years ago
parent
commit
9a20abf04a
3 changed files with 22 additions and 0 deletions
  1. 1 0
      Tests/CMakeLists.txt
  2. 9 0
      Tests/CMakeOnly/CMakeLists.txt
  3. 12 0
      Tests/CMakeOnly/Test.cmake.in

+ 1 - 0
Tests/CMakeLists.txt

@@ -47,6 +47,7 @@ IF(BUILD_TESTING)
   ENDIF()
 
   ADD_SUBDIRECTORY(CMakeLib)
+  ADD_SUBDIRECTORY(CMakeOnly)
 
   ADD_SUBDIRECTORY(FindPackageModeMakefileTest)
 

+ 9 - 0
Tests/CMakeOnly/CMakeLists.txt

@@ -0,0 +1,9 @@
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Test.cmake.in
+               ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake @ONLY)
+
+macro(add_CMakeOnly_test test)
+  add_test(CMakeOnly.${test} ${CMAKE_CMAKE_COMMAND}
+    -DTEST=${test}
+    -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
+    )
+endmacro()

+ 12 - 0
Tests/CMakeOnly/Test.cmake.in

@@ -0,0 +1,12 @@
+set(source_dir "@CMAKE_CURRENT_SOURCE_DIR@/${TEST}")
+set(binary_dir "@CMAKE_CURRENT_BINARY_DIR@/${TEST}-build")
+file(REMOVE_RECURSE "${binary_dir}")
+file(MAKE_DIRECTORY "${binary_dir}")
+execute_process(
+  COMMAND ${CMAKE_COMMAND} "${source_dir}" -G "@CMAKE_TEST_GENERATOR@"
+  WORKING_DIRECTORY "${binary_dir}"
+  RESULT_VARIABLE result
+  )
+if(result)
+  message(FATAL_ERROR "CMake failed to configure ${TEST}")
+endif()