Never attempt to run the dbus tests on APPLE.
[profile/ivi/qtbase.git] / tests / auto / cmake / CMakeLists.txt
1
2 # This is an automatic test for the CMake configuration files.
3 # To run it,
4 # 1) mkdir build   # Create a build directory
5 # 2) cd build
6 # 3) cmake ..      # Run cmake on this directory.
7 # 4) ctest         # Run ctest
8 #
9 # The expected output is something like:
10 #
11 #     Start 1: pass1
12 # 1/7 Test #1: pass1 ............................   Passed    4.25 sec
13 #     Start 2: pass2
14 # 2/7 Test #2: pass2 ............................   Passed    2.00 sec
15 #     Start 3: pass3
16 # 3/7 Test #3: pass3 ............................   Passed    2.85 sec
17 #     Start 4: fail4
18 # 4/7 Test #4: fail4 ............................   Passed    1.88 sec
19 #     Start 5: fail5
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
23 #     Start 7: pass7
24 # 7/7 Test #7: pass7 ............................   Passed    0.93 sec
25 #
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.
30
31 cmake_minimum_required(VERSION 2.8)
32
33 project(qmake_cmake_files)
34
35 enable_testing()
36
37 macro(expect_pass _dir)
38   string(REPLACE "(" "_" testname "${_dir}")
39   string(REPLACE ")" "_" testname "${testname}")
40   add_test(${testname} ${CMAKE_CTEST_COMMAND}
41     --build-and-test
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}
47   )
48 endmacro()
49
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"
56     "
57       cmake_minimum_required(VERSION 2.8)
58       project(${_dir}_build)
59
60       try_compile(Result \${CMAKE_CURRENT_BINARY_DIR}/${_dir}
61           \${CMAKE_CURRENT_SOURCE_DIR}/${_dir}
62           ${_dir}
63           OUTPUT_VARIABLE Out
64       )
65       message(\"\${Out}\")
66       if (Result)
67         message(SEND_ERROR \"Succeeded build which should fail\")
68       endif()
69       "
70   )
71   add_test(${testname} ${CMAKE_CTEST_COMMAND}
72     --build-and-test
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}
78   )
79 endmacro()
80
81 if(NOT ${CMAKE_VERSION} VERSION_LESS 2.8.7)
82     # Requires CMAKE_AUTOMOC function in CMake 2.8.7
83     expect_pass(pass1)
84 else()
85     message("CMake version older than 2.8.7 (Found ${CMAKE_VERSION}). Not running test \"pass1\"")
86 endif()
87 expect_pass(pass2)
88 # Modules do not currently find their own dependencies.
89 # expect_pass(pass3)
90 expect_fail(fail4)
91 expect_fail(fail5)
92 expect_pass("pass(needsquoting)6")
93 expect_pass(pass7)
94 expect_pass(pass8)
95
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)
99     expect_pass(pass9)
100 endif()