Merge topic 'update-kwsys'

f510aafbfc Merge branch 'upstream-KWSys' into update-kwsys
a930de85d8 KWSys 2019-02-14 (e270ce9f)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2967
diff --git a/Modules/Compiler/Cray-C.cmake b/Modules/Compiler/Cray-C.cmake
index b3c96ee..d34154c 100644
--- a/Modules/Compiler/Cray-C.cmake
+++ b/Modules/Compiler/Cray-C.cmake
@@ -8,13 +8,13 @@
 string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
 
 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1)
-  set(CMAKE_C90_STANDARD_COMPILE_OPTION  "-h noc99,conform")
-  set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-h noc99,gnu")
-  set(CMAKE_C99_STANDARD_COMPILE_OPTION  "-h c99,conform")
-  set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-h c99,gnu")
+  set(CMAKE_C90_STANDARD_COMPILE_OPTION  -h noc99,conform)
+  set(CMAKE_C90_EXTENSION_COMPILE_OPTION -h noc99,gnu)
+  set(CMAKE_C99_STANDARD_COMPILE_OPTION  -h c99,conform)
+  set(CMAKE_C99_EXTENSION_COMPILE_OPTION -h c99,gnu)
   if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.5)
-    set(CMAKE_C11_STANDARD_COMPILE_OPTION  "-h std=c11,conform")
-    set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-h std=c11,gnu")
+    set(CMAKE_C11_STANDARD_COMPILE_OPTION  -h std=c11,conform)
+    set(CMAKE_C11_EXTENSION_COMPILE_OPTION -h std=c11,gnu)
   endif ()
 endif ()
 
diff --git a/Modules/Compiler/Cray-CXX.cmake b/Modules/Compiler/Cray-CXX.cmake
index bbb5718..85a3167 100644
--- a/Modules/Compiler/Cray-CXX.cmake
+++ b/Modules/Compiler/Cray-CXX.cmake
@@ -8,15 +8,15 @@
 string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG")
 
 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1)
-  set(CMAKE_CXX98_STANDARD_COMPILE_OPTION  "-h conform")
-  set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-h gnu")
+  set(CMAKE_CXX98_STANDARD_COMPILE_OPTION  -h conform)
+  set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -h gnu)
   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.4)
-    set(CMAKE_CXX11_STANDARD_COMPILE_OPTION  "-h std=c++11")
-    set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-h std=c++11,gnu")
+    set(CMAKE_CXX11_STANDARD_COMPILE_OPTION  -h std=c++11)
+    set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -h std=c++11,gnu)
   endif()
   if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.6)
-    set(CMAKE_CXX14_STANDARD_COMPILE_OPTION  "-h std=c++14")
-    set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-h std=c++14,gnu")
+    set(CMAKE_CXX14_STANDARD_COMPILE_OPTION  -h std=c++14)
+    set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -h std=c++14,gnu)
   endif ()
 endif ()
 
diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake
index 1a2af16..47c0e79 100644
--- a/Modules/FindLibXml2.cmake
+++ b/Modules/FindLibXml2.cmake
@@ -18,7 +18,7 @@
 
 This module will set the following variables in your project:
 
-``LIBXML2_FOUND``
+``LibXml2_FOUND``
   true if libxml2 headers and libraries were found
 ``LIBXML2_INCLUDE_DIR``
   the directory containing LibXml2 headers
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 8330dc8..e69ceb9 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,5 +1,5 @@
 # CMake version number components.
 set(CMake_VERSION_MAJOR 3)
 set(CMake_VERSION_MINOR 14)
-set(CMake_VERSION_PATCH 20190214)
+set(CMake_VERSION_PATCH 20190215)
 #set(CMake_VERSION_RC 1)
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index bd110ec..eb52895 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -226,7 +226,7 @@
     } else if (doing == DoingCMakeFlags) {
       cmakeFlags.push_back(argv[i]);
     } else if (doing == DoingCompileDefinitions) {
-      compileDefs.push_back(argv[i]);
+      cmSystemTools::ExpandListArgument(argv[i], compileDefs);
     } else if (doing == DoingLinkOptions) {
       linkOptions.push_back(argv[i]);
     } else if (doing == DoingLinkLibraries) {
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index 12d9304..913fc4a 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -453,7 +453,8 @@
         "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\"
         "Windows Kits\\Installed Roots;KitsRoot81",
         win81Root, cmSystemTools::KeyWOW64_32)) {
-    return cmSystemTools::FileExists(win81Root + "/um/windows.h", true);
+    return cmSystemTools::FileExists(win81Root + "/include/um/windows.h",
+                                     true);
   }
   return false;
 }
diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
index 616092d..b584e16 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
+++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
@@ -128,7 +128,8 @@
 endif()
 
 # for msvc the compiler version determines which c++11 features are available.
-if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
+    OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))
   if(";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
     list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
     list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
diff --git a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt
index f4b726f..9b32e59 100644
--- a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt
+++ b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt
@@ -5,10 +5,48 @@
 # Dummy executable to generate a clean target
 add_executable(dummy dummy.cpp)
 
-set(timeformat "%Y%j%H%M%S")
+# Utility variables
+set(timeformat "%Y.%j.%H.%M%S")
 set(mocBasicSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocBasic")
 set(mocBasicBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocBasic")
 
+# Utility macros
+macro(sleep)
+  message(STATUS "Sleeping for a few seconds.")
+  execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+endmacro()
+
+macro(acquire_timestamp When)
+  file(TIMESTAMP "${mocBasicBin}" time${When} "${timeformat}")
+endmacro()
+
+macro(rebuild buildName)
+  message(STATUS "Starting build ${buildName}.")
+  execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result)
+  if (result)
+    message(FATAL_ERROR "Build ${buildName} failed.")
+  else()
+    message(STATUS "Build ${buildName} finished.")
+  endif()
+endmacro()
+
+macro(require_change)
+  if (timeAfter VERSION_GREATER timeBefore)
+    message(STATUS "As expected the file ${mocBasicBin} changed.")
+  else()
+    message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} did not change!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
+  endif()
+endmacro()
+
+macro(require_change_not)
+  if (timeAfter VERSION_GREATER timeBefore)
+    message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} changed!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
+  else()
+    message(STATUS "As expected the file ${mocBasicBin} did not change.")
+  endif()
+endmacro()
+
+
 # Initial build
 configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
 try_compile(MOC_RERUN
@@ -21,46 +59,44 @@
   OUTPUT_VARIABLE output
 )
 if (NOT MOC_RERUN)
-  message(SEND_ERROR "Initial build of mocBasic failed. Output: ${output}")
+  message(FATAL_ERROR "Initial build of mocBasic failed. Output: ${output}")
 endif()
+
 # Get name of the output binary
 file(STRINGS "${mocBasicBinDir}/mocBasic.txt" mocBasicList ENCODING UTF-8)
 list(GET mocBasicList 0 mocBasicBin)
 
-message("Changing the header content for a MOC rerun")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}")
+# To avoid a race condition where the binary has the same timestamp
+# as a source file and therefore gets rebuild
+# - sleep to ensure a timestamp change
+# - touch binary to ensure it has a new timestamp
+acquire_timestamp(Before)
+sleep()
+message(STATUS "Touching binary file to ensure a new timestamps")
+file(TOUCH_NOCREATE "${mocBasicBin}")
+acquire_timestamp(After)
+require_change()
+
+
 # - Ensure that the timestamp will change
-# - Change header file content and rebuild
+# - Change header file content
 # - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamp(Before)
+sleep()
+message(STATUS "Changing the header content for a MOC re-run")
 configure_file("${mocBasicSrcDir}/test1b.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result )
-if (result)
-  message(SEND_ERROR "Second build of mocBasic failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}")
-# - Test if timestamps changed
-if (NOT timeAfter GREATER timeBefore)
-  message(SEND_ERROR "File (${mocBasicBin}) should have changed!")
-endif()
+sleep()
+rebuild(2)
+acquire_timestamp(After)
+require_change()
 
 
-message("Changing nothing for a MOC rerun")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}")
 # - Ensure that the timestamp would change
 # - Change nothing
 # - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result )
-if (result)
-  message(SEND_ERROR "Third build of mocBasic failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}")
-# - Test if timestamps changed
-if (timeAfter GREATER timeBefore)
-  message(SEND_ERROR "File (${mocBasicBin}) should not have changed!")
-endif()
+acquire_timestamp(Before)
+sleep()
+message(STATUS "Changing nothing for no MOC re-run")
+rebuild(3)
+acquire_timestamp(After)
+require_change_not()
diff --git a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt
index b83e994..6ab9538 100644
--- a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt
+++ b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt
@@ -9,10 +9,53 @@
 add_executable(dummy dummy.cpp)
 
 # Utility variables
-set(timeformat "%Y%j%H%M%S")
+set(timeformat "%Y.%j.%H.%M%S")
 set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocPlugin")
 set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocPlugin")
 
+# Utility macros
+macro(sleep)
+  message(STATUS "Sleeping for a few seconds.")
+  execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+endmacro()
+
+macro(rebuild buildName)
+  message(STATUS "Starting build ${buildName}.")
+  execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}" RESULT_VARIABLE result)
+  if (result)
+    message(FATAL_ERROR "Build ${buildName} failed.")
+  else()
+    message(STATUS "Build ${buildName} finished.")
+  endif()
+endmacro()
+
+macro(require_change PLG)
+  if (pl${PLG}After VERSION_GREATER pl${PLG}Before)
+    message(STATUS "As expected the file ${pl${PLG}File} changed.")
+  else()
+    message(SEND_ERROR
+      "Unexpectedly the file ${pl${PLG}File} did not change!\nTimestamp pre: ${pl${PLG}Before}\nTimestamp aft: ${pl${PLG}After}\n")
+  endif()
+endmacro()
+
+macro(require_change_not PLG)
+  if (pl${PLG}After VERSION_GREATER pl${PLG}Before)
+    message(SEND_ERROR
+      "Unexpectedly the file ${pl${PLG}File} changed!\nTimestamp pre: ${pl${PLG}Before}\nTimestamp aft: ${pl${PLG}After}\n")
+  else()
+    message(STATUS "As expected the file ${pl${PLG}File} did not change.")
+  endif()
+endmacro()
+
+macro(acquire_timestamps When)
+  file(TIMESTAMP "${plAFile}" plA${When} "${timeformat}")
+  file(TIMESTAMP "${plBFile}" plB${When} "${timeformat}")
+  file(TIMESTAMP "${plCFile}" plC${When} "${timeformat}")
+  file(TIMESTAMP "${plDFile}" plD${When} "${timeformat}")
+  file(TIMESTAMP "${plEFile}" plE${When} "${timeformat}")
+endmacro()
+
+
 # Initial build
 try_compile(MOC_PLUGIN
   "${mocPlugBinDir}"
@@ -24,83 +67,75 @@
   OUTPUT_VARIABLE output
 )
 if (NOT MOC_PLUGIN)
-  message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}")
+  message(FATAL_ERROR "Initial build of mocPlugin failed. Output: ${output}")
 endif()
 
+# Get names of the output binaries
 find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
 find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
 find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
 find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
 find_library(plEFile "PlugE" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH)
 
+# To avoid a race condition where the library has the same timestamp
+# as a source file and therefore gets rebuild
+# - sleep to ensure a timestamp change
+# - touch library to ensure it has a new timestamp
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Touching library files to ensure new timestamps")
+file(TOUCH_NOCREATE "${plAFile}" "${plBFile}" "${plCFile}" "${plDFile}" "${plEFile}")
+acquire_timestamps(After)
+require_change(A)
+require_change(B)
+require_change(C)
+require_change(D)
+require_change(E)
+
+
 # - Ensure that the timestamp will change.
 # - Change the json files referenced by Q_PLUGIN_METADATA
 # - Rebuild
-file(TIMESTAMP "${plAFile}" plABefore "${timeformat}")
-file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}")
-file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}")
-file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}")
-file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}")
-
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing json files")
 configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json")
 configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json")
 configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/StyleE.json")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}")
+sleep()
+rebuild(2)
+acquire_timestamps(After)
+# Test changes
+require_change_not(A)
+require_change_not(B)
+require_change(C)
+require_change(D)
+# There's a bug in Ninja on Windows:
+# https://gitlab.kitware.com/cmake/cmake/issues/16776
+if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja"))
+  require_change(E)
+endif()
 
-file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}")
-file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}")
-file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}")
-file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}")
-file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}")
-
-if (plAAfter GREATER plABefore)
-  message(SEND_ERROR "file (${plAFile}) should not have changed!")
-endif()
-if (plBAfter GREATER plBBefore)
-  message(SEND_ERROR "file (${plBFile}) should not have changed!")
-endif()
-if (NOT plCAfter GREATER plCBefore)
-  message(SEND_ERROR "file (${plCFile}) should have changed!")
-endif()
-if (NOT plDAfter GREATER plDBefore)
-  message(SEND_ERROR "file (${plDFile}) should have changed!")
-endif()
-if (NOT plEAfter GREATER plEBefore)
-  # There's a bug in Ninja on Windows
-  # https://gitlab.kitware.com/cmake/cmake/issues/16776
-  if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja"))
-    message(SEND_ERROR "file (${plEFile}) should have changed!")
-  endif()
-endif()
 
 # - Ensure that the timestamp will change.
 # - Change the json files referenced by A_CUSTOM_MACRO
 # - Rebuild
-file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}")
-file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}")
-file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}")
-
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing json files")
 configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json")
 configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json")
 configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleE_Custom.json")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}")
-
-file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}")
-file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}")
-file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}")
-
-if (NOT plCAfter GREATER plCBefore)
-  message(SEND_ERROR "file (${plCFile}) should have changed!")
-endif()
-if (NOT plDAfter GREATER plDBefore)
-  message(SEND_ERROR "file (${plDFile}) should have changed!")
-endif()
-if (NOT plEAfter GREATER plEBefore)
-  # There's a bug in Ninja on Windows
-  # https://gitlab.kitware.com/cmake/cmake/issues/16776
-  if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja"))
-    message(SEND_ERROR "file (${plEFile}) should have changed!")
-  endif()
+sleep()
+rebuild(3)
+acquire_timestamps(After)
+# Test changes
+require_change_not(A)
+require_change_not(B)
+require_change(C)
+require_change(D)
+# There's a bug in Ninja on Windows
+# https://gitlab.kitware.com/cmake/cmake/issues/16776
+if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja"))
+  require_change(E)
 endif()
diff --git a/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt b/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt
index dcb7a79..33c01ac 100644
--- a/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt
+++ b/Tests/QtAutogen/RerunRccConfigChange/CMakeLists.txt
@@ -9,10 +9,23 @@
 
 # When a .qrc or a file listed in a .qrc file changes,
 # the target must be rebuilt
-set(timeformat "%Y%j%H%M%S")
 set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/RccConfigChange")
 set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/RccConfigChange")
 
+# Rebuild macro
+macro(rebuild CFG)
+  message(STATUS "Rebuilding rccConfigChange in ${CFG} configuration.")
+  execute_process(
+    COMMAND "${CMAKE_COMMAND}" --build . --config "${CFG}"
+    WORKING_DIRECTORY "${rccDepBD}"
+    RESULT_VARIABLE result)
+  if (result)
+    message(FATAL_ERROR "${CFG} build of rccConfigChange failed.")
+  else()
+    message(STATUS "${CFG} build of rccConfigChange finished.")
+  endif()
+endmacro()
+
 # Initial build
 try_compile(RCC_DEPENDS
   "${rccDepBD}"
@@ -24,19 +37,11 @@
   OUTPUT_VARIABLE output
 )
 if (NOT RCC_DEPENDS)
-  message(SEND_ERROR "Initial build of rccConfigChange failed. Output: ${output}")
+  message(FATAL_ERROR "Initial build of rccConfigChange failed. Output: ${output}")
 endif()
 
-# - Rebuild Release
-message("Rebuilding rccConfigChange in Release configuration")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Release WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Release build of rccConfigChange failed.")
-endif()
+# Rebuild: Release
+rebuild(Release)
 
-# - Rebuild Debug
-message("Rebuilding rccConfigChange in Debug configuration")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Debug WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Debug build of rccConfigChange failed.")
-endif()
+# Rebuild: Debug
+rebuild(Debug)
diff --git a/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt b/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt
index 80c5cf0..1301550 100644
--- a/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt
+++ b/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt
@@ -3,19 +3,63 @@
 include("../AutogenCoreTest.cmake")
 
 # Tests rcc rebuilding when a resource file changes
+# When a .qrc or a file listed in a .qrc file changes,
+# the target must be rebuilt
 
 # Dummy executable to generate a clean target
 add_executable(dummy dummy.cpp)
 
-# When a .qrc or a file listed in a .qrc file changes,
-# the target must be rebuilt
-set(timeformat "%Y%j%H%M%S")
+# Utility variables
+set(timeformat "%Y.%j.%H.%M%S")
 set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/RccDepends")
 set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/RccDepends")
 
-# Initial build
+# Utility macros
+macro(sleep)
+  message(STATUS "Sleeping for a few seconds.")
+  execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+endmacro()
+
+macro(acquire_timestamps When)
+  file(TIMESTAMP "${rccDepBinPlain}" rdPlain${When} "${timeformat}")
+  file(TIMESTAMP "${rccDepBinGenerated}" rdGenerated${When} "${timeformat}")
+endmacro()
+
+macro(rebuild buildName)
+  message(STATUS "Starting build ${buildName} of rccDepends.")
+  execute_process(
+    COMMAND "${CMAKE_COMMAND}" --build .
+    WORKING_DIRECTORY "${rccDepBD}"
+    RESULT_VARIABLE result)
+  if (result)
+    message(FATAL_ERROR "Build ${buildName} of rccDepends failed.")
+  else()
+    message(STATUS "Build ${buildName} of rccDepends finished.")
+  endif()
+endmacro()
+
+macro(require_change type)
+  if (rd${type}After VERSION_GREATER rd${type}Before)
+    message(STATUS "As expected the ${type} .qrc file ${rccDepBin${type}} changed.")
+  else()
+    message(SEND_ERROR "Unexpectedly the ${type} .qrc file ${rccDepBin${type}} did not change!\nTimestamp pre: ${rd${type}Before}\nTimestamp aft: ${rd${type}After}\n")
+  endif()
+endmacro()
+
+macro(require_change_not type)
+  if (rd${type}After VERSION_GREATER rd${type}Before)
+    message(SEND_ERROR "Unexpectedly the ${type} .qrc file ${rccDepBin${type}} changed!\nTimestamp pre: ${rd${type}Before}\nTimestamp aft: ${rd${type}After}\n")
+  else()
+    message(STATUS "As expected the ${type} .qrc file ${rccDepBin${type}} did not change.")
+  endif()
+endmacro()
+
+
+# Initial configuration
 configure_file(${rccDepSD}/resPlainA.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
 configure_file(${rccDepSD}/resGenA.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
+
+# Initial build
 try_compile(RCC_DEPENDS
   "${rccDepBD}"
   "${rccDepSD}"
@@ -26,113 +70,84 @@
   OUTPUT_VARIABLE output
 )
 if (NOT RCC_DEPENDS)
-  message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}")
+  message(FATAL_ERROR "Initial build of rccDepends failed. Output: ${output}")
 endif()
 
 # Get name of the output binaries
 file(STRINGS "${rccDepBD}/targetPlain.txt" targetListPlain ENCODING UTF-8)
 file(STRINGS "${rccDepBD}/targetGen.txt" targetListGen ENCODING UTF-8)
 list(GET targetListPlain 0 rccDepBinPlain)
-list(GET targetListGen 0 rccDepBinGen)
-message("Target that uses a plain .qrc file is:\n  ${rccDepBinPlain}")
-message("Target that uses a GENERATED .qrc file is:\n  ${rccDepBinGen}")
+list(GET targetListGen 0 rccDepBinGenerated)
+message(STATUS "Target that uses a plain .qrc file is:\n  ${rccDepBinPlain}")
+message(STATUS "Target that uses a GENERATED .qrc file is:\n  ${rccDepBinGenerated}")
+
+# To avoid a race condition where the binary has the same timestamp
+# as a source file and therefore gets rebuild
+# - sleep to ensure a timestamp change
+# - touch binary to ensure it has a new timestamp
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Touching binary files to ensure new timestamps")
+file(TOUCH_NOCREATE "${rccDepBinPlain}" "${rccDepBinGenerated}")
+acquire_timestamps(After)
+require_change(Plain)
+require_change(Generated)
 
 
-message("Changing a resource files listed in the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
 # - Ensure that the timestamp will change
 # - Change a resource files listed in the .qrc file
 # - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing a resource file listed in the .qrc file")
 file(TOUCH "${rccDepBD}/resPlain/input.txt" "${rccDepBD}/resGen/input.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Second build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+sleep()
+rebuild(2)
+acquire_timestamps(After)
 # - Test if timestamps changed
-if (NOT rdPlainAfter GREATER rdPlainBefore)
-  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
-endif()
-if (NOT rdGenAfter GREATER rdGenBefore)
-  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
-endif()
+require_change(Plain)
+require_change(Generated)
 
 
-message("Changing the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
 # - Ensure that the timestamp will change
 # - Change the .qrc file
 # - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing the .qrc file")
 configure_file(${rccDepSD}/resPlainB.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
 configure_file(${rccDepSD}/resGenB.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Third build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+sleep()
+rebuild(3)
+acquire_timestamps(After)
 # - Test if timestamps changed
-if (NOT rdPlainAfter GREATER rdPlainBefore)
-  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
-endif()
-if (NOT rdGenAfter GREATER rdGenBefore)
-  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
-endif()
+require_change(Plain)
+require_change(Generated)
 
 
-message("Changing a newly added resource files listed in the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
 # - Ensure that the timestamp will change
 # - Change a newly added resource files listed in the .qrc file
 # - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing a newly added resource file listed in the .qrc file")
 file(TOUCH "${rccDepBD}/resPlain/inputAdded.txt" "${rccDepBD}/resGen/inputAdded.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Fourth build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+sleep()
+rebuild(4)
+acquire_timestamps(After)
 # - Test if timestamps changed
-if (NOT rdPlainAfter GREATER rdPlainBefore)
-  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
-endif()
-if (NOT rdGenAfter GREATER rdGenBefore)
-  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
-endif()
+require_change(Plain)
+require_change(Generated)
 
 
-message("Changing nothing in the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
 # - Ensure that the timestamp will change
 # - Change nothing
 # - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Fifth build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing nothing in the .qrc file")
+rebuild(5)
+acquire_timestamps(After)
 # - Test if timestamps changed
-if (rdPlainAfter GREATER rdPlainBefore)
-  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should NOT have changed!")
-endif()
-if (rdGenAfter GREATER rdGenBefore)
-  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should NOT have changed!")
-endif()
+require_change_not(Plain)
+require_change_not(Generated)
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
index 184a7be..54e96a2 100644
--- a/Tests/TryCompile/CMakeLists.txt
+++ b/Tests/TryCompile/CMakeLists.txt
@@ -165,6 +165,35 @@
   OUTPUT_VARIABLE output)
 TEST_ASSERT(TEST_INNER "try_compile project mode failed:\n${output}")
 
+try_compile(COMPILE_DEFINITIONS_LIST_EXPANDED
+    ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+    ${TryCompile_SOURCE_DIR}/check_a_b.c
+    OUTPUT_VARIABLE output
+    COMPILE_DEFINITIONS "-DDEF_A;-DDEF_B"
+    )
+if(COMPILE_DEFINITIONS_LIST_EXPANDED)
+  message(STATUS "COMPILE_DEFINITIONS list expanded correctly")
+else()
+  string(REPLACE "\n" "\n  " output "  ${output}")
+  message(SEND_ERROR "COMPILE_DEFINITIONS list did not expand correctly\n${output}")
+endif()
+
+try_compile(SHOULD_FAIL_DUE_TO_BAD_SOURCE
+    ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+    ${TryCompile_SOURCE_DIR}/pass.c
+    OUTPUT_VARIABLE output
+    COMPILE_DEFINITIONS "bad#source.c"
+    )
+if(SHOULD_FAIL_DUE_TO_BAD_SOURCE AND NOT CMAKE_GENERATOR MATCHES "Watcom WMake|NMake Makefiles")
+  string(REPLACE "\n" "\n  " output "  ${output}")
+  message(SEND_ERROR "try_compile with bad#source.c did not fail:\n${output}")
+elseif(NOT output MATCHES [[(bad#source\.c|bad\\)]])
+  string(REPLACE "\n" "\n  " output "  ${output}")
+  message(SEND_ERROR "try_compile with bad#source.c failed without mentioning bad source:\n${output}")
+else()
+  message(STATUS "try_compile with bad#source.c correctly failed")
+endif()
+
 add_executable(TryCompile pass.c)
 
 ######################################
diff --git a/Tests/TryCompile/check_a_b.c b/Tests/TryCompile/check_a_b.c
new file mode 100644
index 0000000..05fba0f
--- /dev/null
+++ b/Tests/TryCompile/check_a_b.c
@@ -0,0 +1,10 @@
+#ifndef DEF_A
+#  error DEF_A not defined
+#endif
+#ifndef DEF_B
+#  error DEF_B not defined
+#endif
+int main()
+{
+  return 0;
+}