|
| 1 | +# This file defines macros which can be used to setup |
| 2 | +# new cmake project tests without introducing excessive boilerplate. |
| 3 | + |
| 4 | +# declare_add_subdirectory_test(<name of test>): |
| 5 | +# Use when the test depends on launchdarkly via add_subdirectory. |
| 6 | + |
| 7 | +# declare_find_package_test(<test name>): |
| 8 | +# Use when the test depends on launchdarkly via find_package. |
| 9 | + |
| 10 | +# add_build_step(<test name>): |
| 11 | +# By default, the declare_* macros result in a test where "cmake -DSOMEVARIABLE=WHATEVER .." |
| 12 | +# (the cmake configure step) is invoked. This may be sufficient for a particular test, |
| 13 | +# for example testing that the configure step fails. |
| 14 | +# If the test should also invoke "cmake --build .", use this macro. |
| 15 | + |
| 16 | +# require_configure_failure(<test name>): |
| 17 | +# Asserts that the cmake configure step should fail. For example, this would |
| 18 | +# happen if a required version of a dependency couldn't be satisfied with find_package. |
| 19 | + |
| 20 | +# require_build_failure(<test name>): |
| 21 | +# Asserts that the cmake build step should fail. |
| 22 | + |
| 23 | +macro(declare_add_subdirectory_test name) |
| 24 | + set(test_prefix ${name}) |
| 25 | + |
| 26 | + add_test( |
| 27 | + NAME ${test_prefix}_configure |
| 28 | + COMMAND |
| 29 | + ${CMAKE_COMMAND} |
| 30 | + # Since project/CMakeLists.txt is going to call add_subdirectory(), it needs to know where |
| 31 | + # the SDK's project is (which is actually a couple directories above this particular file; not normally the case.) |
| 32 | + # The variable name is arbitrary. |
| 33 | + -DLAUNCHDARKLY_SOURCE_DIR=${PROJECT_SOURCE_DIR} |
| 34 | + # Do not setup all of the SDK's testing machinery, which would normally happen when calling add_subdirectory. |
| 35 | + -DBUILD_TESTING=OFF |
| 36 | + -DBOOST_ROOT=${BOOST_ROOT} |
| 37 | + -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} |
| 38 | + ${CMAKE_CURRENT_SOURCE_DIR}/project |
| 39 | + ) |
| 40 | + |
| 41 | + set_tests_properties(${test_prefix}_configure |
| 42 | + PROPERTIES |
| 43 | + FIXTURES_SETUP ${test_prefix} |
| 44 | + # Forward along the CC and CXX environment variables, because clang11 CI build uses them. |
| 45 | + ENVIRONMENT "CC=${CMAKE_C_COMPILER};CXX=${CMAKE_CXX_COMPILER}" |
| 46 | + ) |
| 47 | +endmacro() |
| 48 | + |
| 49 | +macro(require_configure_failure name) |
| 50 | + set_tests_properties(${name}_configure PROPERTIES WILL_FAIL TRUE) |
| 51 | +endmacro() |
| 52 | + |
| 53 | +macro(require_build_failure name) |
| 54 | + set_tests_properties(${name}_build PROPERTIES WILL_FAIL TRUE) |
| 55 | +endmacro() |
| 56 | + |
| 57 | +macro(add_build_step name) |
| 58 | + # Setup a 'test' to perform the cmake build step. |
| 59 | + add_test( |
| 60 | + NAME ${name}_build |
| 61 | + COMMAND ${CMAKE_COMMAND} --build . |
| 62 | + ) |
| 63 | + |
| 64 | + set_tests_properties(${name}_build |
| 65 | + PROPERTIES |
| 66 | + FIXTURES_REQUIRED ${name} |
| 67 | + ) |
| 68 | +endmacro() |
| 69 | + |
| 70 | +macro(declare_find_package_test name) |
| 71 | + # This test assumes that the SDK has been installed at CMAKE_INSTALL_PREFIX. |
| 72 | + set(test_prefix ${name}) |
| 73 | + |
| 74 | + add_test( |
| 75 | + NAME ${test_prefix}_configure |
| 76 | + COMMAND |
| 77 | + ${CMAKE_COMMAND} |
| 78 | + # Since project/CMakeLists.txt uses find_package(), it needs to know where to find |
| 79 | + # ldserverapiConfig.cmake. That can be found where the SDK is installed, which is CMAKE_INSTALL_PREFIX. |
| 80 | + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX} |
| 81 | + ${CMAKE_CURRENT_SOURCE_DIR}/project |
| 82 | + ) |
| 83 | + |
| 84 | + set_tests_properties(${test_prefix}_configure |
| 85 | + PROPERTIES |
| 86 | + FIXTURES_SETUP ${test_prefix} |
| 87 | + # Forward along the CC and CXX environment variables, because clang11 CI build uses them. |
| 88 | + ENVIRONMENT "CC=${CMAKE_C_COMPILER};CXX=${CMAKE_CXX_COMPILER}" |
| 89 | + ) |
| 90 | +endmacro() |
0 commit comments