Fix unit tests when CMAKE_PREFIX_PATH env var is not set.
authorStephen Kelly <stephen.kelly@kdab.com>
Tue, 10 Jul 2012 15:56:54 +0000 (17:56 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 11 Jul 2012 10:46:15 +0000 (12:46 +0200)
Tests which are expected to not build need to get a way to find the
Qt 5 config packages. Because they use try_compile, there is no way
to pass the contents to it.

Work around that by generating a file containing the prefix which
the tests will include.

Change-Id: If43080c241539e4af5fe1c183e7da72066278b73
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
src/corelib/Qt5CTestMacros.cmake
tests/auto/cmake/test_add_resource_options/CMakeLists.txt
tests/auto/cmake/test_wrap_cpp_options/CMakeLists.txt

index a6d8adf..468c42e 100644 (file)
@@ -17,6 +17,9 @@ macro(expect_fail _dir)
   string(REPLACE ")" "_" testname "${testname}")
   file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
   file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
+
+  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/${_dir}/FindPackageHints.cmake" "set(Qt5Tests_PREFIX_PATH \"${CMAKE_PREFIX_PATH}\")")
+
   file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/CMakeLists.txt"
     "
       cmake_minimum_required(VERSION 2.8)
index e79b954..a358094 100644 (file)
@@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 2.8)
 
 project(test_add_resource_options)
 
-find_package(Qt5Core REQUIRED)
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
+    include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
+endif()
+
+find_package(Qt5Core REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
 
 include_directories(${Qt5Core_INCLUDE_DIRS})
 
index a7a2c0e..0704edb 100644 (file)
@@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 2.8)
 
 project(test_wrap_cpp_options)
 
-find_package(Qt5Core REQUIRED)
+if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
+    include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake")
+endif()
+
+find_package(Qt5Core REQUIRED HINTS ${Qt5Tests_PREFIX_PATH})
 
 include_directories(${Qt5Core_INCLUDE_DIRS})