فهرست منبع

Add tests for EXCLUDE_FROM_DEFAULT_BUILD

Add tests for EXCLUDE_FROM_DEFAULT_BUILD and its per-configuration
variants.
Petr Kmoch 13 سال پیش
والد
کامیت
b777272b0b

+ 22 - 0
Tests/CMakeLists.txt

@@ -1412,6 +1412,28 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
       --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
       --test-command VSMidl)
     list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSMidl")
+
+    if(NOT MSVC60 AND NOT CMAKE_TEST_MAKEPROGRAM MATCHES "[mM][sS][bB][uU][iI][lL][dD]\\.[eE][xX][eE]")
+      # The test (and tested property) works with .sln files, so it's skipped when:
+      # * Using VS6, which doesn't use .sln files
+      # * cmake --build is set up to use MSBuild, since the MSBuild invocation does not use the .sln file
+      foreach(config ${CMAKE_CONFIGURATION_TYPES})
+        add_test(NAME VSExcludeFromDefaultBuild-${config} COMMAND ${CMAKE_CTEST_COMMAND}
+          --build-and-test
+          "${CMake_SOURCE_DIR}/Tests/VSExcludeFromDefaultBuild"
+          "${CMake_BINARY_DIR}/Tests/VSExcludeFromDefaultBuild"
+          --build-config ${config}
+          --build-two-config
+          --build-generator ${CMAKE_TEST_GENERATOR}
+          --build-project VSExcludeFromDefaultBuild
+          --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
+          --test-command ${CMAKE_COMMAND}
+             -D "activeConfig=${config}"
+             -D "allConfigs=${CMAKE_CONFIGURATION_TYPES}"
+             -D "dir=${CMake_BINARY_DIR}/Tests/VSExcludeFromDefaultBuild"
+             -P "${CMake_SOURCE_DIR}/Tests/VSExcludeFromDefaultBuild/ResultTest.cmake")
+      endforeach()
+    endif()
   endif()
 
   if (APPLE)

+ 32 - 0
Tests/VSExcludeFromDefaultBuild/CMakeLists.txt

@@ -0,0 +1,32 @@
+cmake_minimum_required(VERSION 2.8.9)
+project(VSExcludeFromDefaultBuild)
+
+# First step is to clear all .exe files in output so that possible past
+# failures of this test do not prevent it from succeeding.
+add_custom_target(ClearExes ALL
+  COMMAND "${CMAKE_COMMAND}"
+    -Ddir=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
+    -P ${CMAKE_CURRENT_SOURCE_DIR}/ClearExes.cmake
+  VERBATIM)
+
+# Make sure ClearExes is executed before other targets are built
+function(add_test_executable target)
+  add_executable("${target}" ${ARGN})
+  add_dependencies("${target}" ClearExes)
+endfunction()
+
+add_test_executable(DefaultBuilt main.c)
+
+add_test_executable(AlwaysBuilt main.c)
+set_target_properties(AlwaysBuilt PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD FALSE)
+
+add_test_executable(NeverBuilt main.c)
+set_target_properties(NeverBuilt PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
+
+foreach(config ${CMAKE_CONFIGURATION_TYPES})
+  string(TOUPPER ${config} Config)
+  add_test_executable(BuiltIn${config} main.c)
+  set_target_properties(BuiltIn${config} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE EXCLUDE_FROM_DEFAULT_BUILD_${Config} FALSE)
+  add_test_executable(ExcludedIn${config} main.c)
+  set_target_properties(ExcludedIn${config} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD_${Config} TRUE)
+endforeach()

+ 4 - 0
Tests/VSExcludeFromDefaultBuild/ClearExes.cmake

@@ -0,0 +1,4 @@
+file(GLOB exeFiles "${dir}/*.exe")
+foreach(exeFile IN LISTS exeFiles)
+  file(REMOVE "${exeFile}")
+endforeach()

+ 23 - 0
Tests/VSExcludeFromDefaultBuild/ResultTest.cmake

@@ -0,0 +1,23 @@
+message(STATUS "Testing configuration ${activeConfig}.")
+
+macro(TestExists exeName)
+  set(exeFile "${dir}/${activeConfig}/${exeName}.exe")
+  if(${ARGN} EXISTS "${exeFile}")
+    message(STATUS "File ${exeFile} was correctly found ${ARGN} to exist.")
+  else()
+    message(FATAL_ERROR "File ${exeFile} was expected ${ARGN} to exist!")
+  endif()
+endmacro()
+
+TestExists(DefaultBuilt)
+TestExists(AlwaysBuilt)
+TestExists(NeverBuilt NOT)
+foreach(config ${allConfigs})
+  if(config STREQUAL activeConfig)
+    TestExists(BuiltIn${config})
+    TestExists(ExcludedIn${config} NOT)
+  else()
+    TestExists(BuiltIn${config} NOT)
+    TestExists(ExcludedIn${config})
+  endif()
+endforeach()

+ 4 - 0
Tests/VSExcludeFromDefaultBuild/main.c

@@ -0,0 +1,4 @@
+int main(void)
+{
+  return 0;
+}