2 # This is an automatic test for the CMake configuration files.
4 # 1) mkdir build # Create a build directory
6 # 3) cmake .. # Run cmake on this directory.
9 # The expected output is something like:
12 # 1/7 Test #1: pass1 ............................ Passed 4.25 sec
14 # 2/7 Test #2: pass2 ............................ Passed 2.00 sec
16 # 3/7 Test #3: pass3 ............................ Passed 2.85 sec
18 # 4/7 Test #4: fail4 ............................ Passed 1.88 sec
20 # 5/7 Test #5: fail5 ............................ Passed 1.36 sec
21 # Start 6: pass_needsquoting_6
22 # 6/7 Test #6: pass_needsquoting_6 .............. Passed 2.88 sec
24 # 7/7 Test #7: pass7 ............................ Passed 0.93 sec
26 # Note that if Qt is not installed, or if it is installed to a
27 # non-standard prefix, the environment variable CMAKE_PREFIX_PATH
28 # needs to be set to the installation prefix or build prefix of Qt
29 # before running these tests.
31 cmake_minimum_required(VERSION 2.8)
33 project(qmake_cmake_files)
37 macro(expect_pass _dir)
38 string(REPLACE "(" "_" testname "${_dir}")
39 string(REPLACE ")" "_" testname "${testname}")
40 add_test(${testname} ${CMAKE_CTEST_COMMAND}
42 "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}"
43 "${CMAKE_CURRENT_BINARY_DIR}/${_dir}"
44 --build-generator ${CMAKE_GENERATOR}
45 --build-makeprogram ${CMAKE_MAKE_PROGRAM}
46 --build-options -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
50 macro(expect_fail _dir)
51 string(REPLACE "(" "_" testname "${_dir}")
52 string(REPLACE ")" "_" testname "${testname}")
53 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
54 file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}")
55 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/CMakeLists.txt"
57 cmake_minimum_required(VERSION 2.8)
58 project(${_dir}_build)
60 try_compile(Result \${CMAKE_CURRENT_BINARY_DIR}/${_dir}
61 \${CMAKE_CURRENT_SOURCE_DIR}/${_dir}
67 message(SEND_ERROR \"Succeeded build which should fail\")
71 add_test(${testname} ${CMAKE_CTEST_COMMAND}
73 "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}"
74 "${CMAKE_CURRENT_BINARY_DIR}/failbuild/${_dir}/build"
75 --build-generator ${CMAKE_GENERATOR}
76 --build-makeprogram ${CMAKE_MAKE_PROGRAM}
77 --build-options -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
81 if(NOT ${CMAKE_VERSION} VERSION_LESS 2.8.7)
82 # Requires CMAKE_AUTOMOC function in CMake 2.8.7
85 message("CMake version older than 2.8.7 (Found ${CMAKE_VERSION}). Not running test \"pass1\"")
88 # Modules do not currently find their own dependencies.
92 expect_pass("pass(needsquoting)6")
96 # If QtDBus has been installed then run the tests for its macros.
97 find_package(Qt5DBus QUIET)
98 if (Qt5DBus_FOUND AND NOT APPLE)