Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/KexiAddTests.cmake
1 | # Additional CMake macros | 1 | # Additional CMake macros | ||
---|---|---|---|---|---|
2 | # | 2 | # | ||
3 | # Copyright (C) 2015-2017 Jarosław Staniek <staniek@kde.org> | 3 | # Copyright (C) 2015-2017 Jarosław Staniek <staniek@kde.org> | ||
4 | # | 4 | # | ||
5 | # Redistribution and use is allowed according to the terms of the BSD license. | 5 | # Redistribution and use is allowed according to the terms of the BSD license. | ||
6 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. | 6 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
7 | # | 7 | # | ||
8 | # Note: the file must be included before KDEInstallDirs or add_tests() won't fully work | 8 | # Note: the file must be included before KDEInstallDirs or add_tests() won't fully work | ||
9 | 9 | | |||
10 | if(__kexi_add_tests) | 10 | if(__kexi_add_tests) | ||
11 | return() | 11 | return() | ||
12 | endif() | 12 | endif() | ||
13 | set(__kexi_add_tests YES) | 13 | set(__kexi_add_tests YES) | ||
14 | 14 | | |||
15 | include(KexiAddSimpleOption) | 15 | include(KexiAddSimpleOption) | ||
16 | include(MacroBoolTo01) | ||||
16 | 17 | | |||
17 | # Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/ | 18 | # Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/ | ||
18 | # and tests/ subdirectory is enabled. If optional argument ARG1 is ON, building tests will | 19 | # and tests/ subdirectory is enabled. If optional argument ARG1 is ON, building tests will | ||
19 | # be ON by default. Otherwise building tests will be OFF. ARG1 is OFF by default. | 20 | # be ON by default. Otherwise building tests will be OFF. ARG1 is OFF by default. | ||
20 | # If tests are OFF, BUILD_COVERAGE is set to OFF. | 21 | # If tests are OFF, BUILD_COVERAGE is set to OFF. | ||
21 | # If tests are on BUILD_TESTING macro is defined. | 22 | # If tests are on BUILD_TESTING macro is defined. | ||
22 | macro(kexi_add_tests) | 23 | macro(kexi_add_tests) | ||
23 | if(KDE_INSTALL_TARGETS_DEFAULT_ARGS) | 24 | if(KDE_INSTALL_TARGETS_DEFAULT_ARGS) | ||
24 | message(FATAL_ERROR "Include before KDEInstallDirs!") | 25 | message(FATAL_ERROR "Include before KDEInstallDirs!") | ||
25 | endif() | 26 | endif() | ||
26 | if (NOT "${ARG1}" STREQUAL "ON") | 27 | if (NOT "${ARG1}" STREQUAL "ON") | ||
27 | set(_SET OFF) | 28 | set(_SET OFF) | ||
28 | endif() | 29 | endif() | ||
29 | simple_option(BUILD_TESTING "Build tests" ${_SET}) # override default from CTest.cmake | 30 | simple_option(BUILD_TESTING "Build tests" ${_SET}) # override default from CTest.cmake | ||
30 | if(BUILD_TESTING) | 31 | if(BUILD_TESTING) | ||
31 | add_definitions(-DBUILD_TESTING) | 32 | add_definitions(-DBUILD_TESTING) | ||
32 | include(CTest) | 33 | include(CTest) | ||
33 | else() | 34 | else() | ||
34 | set(BUILD_COVERAGE OFF) | 35 | set(BUILD_COVERAGE OFF) | ||
35 | simple_option(BUILD_COVERAGE "Build test coverage (disabled because BUILD_TESTING is OFF)" OFF) | 36 | simple_option(BUILD_COVERAGE "Build test coverage (disabled because BUILD_TESTING is OFF)" OFF) | ||
36 | endif() | 37 | endif() | ||
38 | | ||||
39 | # only with COMPILING_TESTS definition will all the FOO_TEST_EXPORT macros do something | ||||
40 | # TODO: check if this can be moved to only those places which make use of it, | ||||
41 | # to reduce global compiler definitions that would trigger a recompile of | ||||
42 | # everything on a change (like adding/removing tests to/from the build) | ||||
43 | macro_bool_to_01(BUILD_TESTING COMPILING_TESTS) | ||||
37 | endmacro() | 44 | endmacro() |