Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.5) |
Kosta | ce441a9 | 2013-08-05 12:40:33 +0200 | [diff] [blame] | 2 | |
David Seifert | a035998 | 2018-01-18 00:01:27 +0100 | [diff] [blame] | 3 | # detect if Catch is being bundled, |
| 4 | # disable testsuite in that case |
| 5 | if(NOT DEFINED PROJECT_NAME) |
| 6 | set(NOT_SUBPROJECT ON) |
| 7 | endif() |
| 8 | |
Martin Hořeňovský | 15cf3ca | 2018-07-23 10:12:15 +0200 | [diff] [blame] | 9 | project(Catch2 LANGUAGES CXX VERSION 2.3.0) |
Kosta | ce441a9 | 2013-08-05 12:40:33 +0200 | [diff] [blame] | 10 | |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 11 | # Provide path for scripts |
| 12 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") |
| 13 | |
David Seifert | 8d4074a | 2018-01-18 00:01:27 +0100 | [diff] [blame] | 14 | include(GNUInstallDirs) |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 15 | include(CMakePackageConfigHelpers) |
| 16 | include(CTest) |
David Seifert | 8d4074a | 2018-01-18 00:01:27 +0100 | [diff] [blame] | 17 | |
David Seifert | b0f4f16 | 2018-01-18 19:20:08 +0100 | [diff] [blame] | 18 | option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF) |
Martin Hořeňovský | 797d3b0 | 2018-07-22 18:01:42 +0200 | [diff] [blame] | 19 | option(CATCH_BUILD_TESTING "Build SelfTest project" ON) |
David Seifert | b0f4f16 | 2018-01-18 19:20:08 +0100 | [diff] [blame] | 20 | option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF) |
Martin Hořeňovský | f061dab | 2018-08-28 09:44:47 +0200 | [diff] [blame] | 21 | option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF) |
David Seifert | b0f4f16 | 2018-01-18 19:20:08 +0100 | [diff] [blame] | 22 | option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF) |
| 23 | option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON) |
Paul le Roux | 0eb99fb | 2018-06-19 07:14:09 +0200 | [diff] [blame] | 24 | option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON) |
Martin Hořeňovský | ed582bd | 2018-06-23 19:04:22 +0200 | [diff] [blame] | 25 | option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON) |
| 26 | |
Martin Hořeňovský | a20b286 | 2017-11-05 12:46:04 +0100 | [diff] [blame] | 27 | |
Phil Nash | 8abe17a | 2017-01-09 16:27:06 +0000 | [diff] [blame] | 28 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 29 | |
Kosta | ce441a9 | 2013-08-05 12:40:33 +0200 | [diff] [blame] | 30 | # define some folders |
Phil Nash | c8fefc4 | 2017-01-06 16:19:20 +0000 | [diff] [blame] | 31 | set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Kosta | ce441a9 | 2013-08-05 12:40:33 +0200 | [diff] [blame] | 32 | set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest) |
Martin Hořeňovský | 3b7511e | 2017-01-14 21:55:37 +0100 | [diff] [blame] | 33 | set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark) |
Phil Nash | e1fbbe1 | 2017-01-06 16:59:18 +0000 | [diff] [blame] | 34 | set(HEADER_DIR ${CATCH_DIR}/include) |
| 35 | |
Antonio Di Monaco | b8443e6 | 2017-05-11 13:00:03 +0200 | [diff] [blame] | 36 | if(USE_WMAIN) |
| 37 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") |
| 38 | endif() |
| 39 | |
Martin Hořeňovský | 797d3b0 | 2018-07-22 18:01:42 +0200 | [diff] [blame] | 40 | if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT) |
Martin Hořeňovský | fcd91c7 | 2018-09-02 18:54:41 +0200 | [diff] [blame^] | 41 | find_package(PythonInterp) |
David Seifert | 7f18282 | 2018-08-18 22:06:25 +0200 | [diff] [blame] | 42 | if (NOT PYTHONINTERP_FOUND) |
| 43 | message(FATAL_ERROR "Python not found, but required for tests") |
| 44 | endif() |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 45 | add_subdirectory(projects) |
| 46 | endif() |
Saad K | 7dd4f29 | 2017-01-31 14:22:45 -0500 | [diff] [blame] | 47 | |
David Seifert | b0f4f16 | 2018-01-18 19:20:08 +0100 | [diff] [blame] | 48 | if(CATCH_BUILD_EXAMPLES) |
Martin Moene | 85de072 | 2017-11-05 09:15:22 +0100 | [diff] [blame] | 49 | add_subdirectory(examples) |
| 50 | endif() |
| 51 | |
Martin Hořeňovský | f061dab | 2018-08-28 09:44:47 +0200 | [diff] [blame] | 52 | if(CATCH_BUILD_EXTRA_TESTS) |
| 53 | add_subdirectory(projects/ExtraTests) |
| 54 | endif() |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 55 | |
| 56 | # add catch as a 'linkable' target |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 57 | add_library(Catch2 INTERFACE) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 58 | |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 59 | |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 60 | |
| 61 | # depend on some obvious c++11 features so the dependency is transitively added dependents |
| 62 | target_compile_features(Catch2 |
| 63 | INTERFACE |
| 64 | cxx_alignas |
| 65 | cxx_alignof |
| 66 | cxx_attributes |
| 67 | cxx_auto_type |
| 68 | cxx_constexpr |
| 69 | cxx_defaulted_functions |
| 70 | cxx_deleted_functions |
| 71 | cxx_final |
| 72 | cxx_lambdas |
| 73 | cxx_noexcept |
| 74 | cxx_override |
| 75 | cxx_range_for |
| 76 | cxx_rvalue_references |
| 77 | cxx_static_assert |
| 78 | cxx_strong_enums |
| 79 | cxx_trailing_return_types |
| 80 | cxx_unicode_literals |
| 81 | cxx_user_literals |
| 82 | cxx_variadic_macros |
| 83 | ) |
| 84 | |
| 85 | target_include_directories(Catch2 |
| 86 | INTERFACE |
| 87 | $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include> |
| 88 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 89 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 90 | |
| 91 | # provide a namespaced alias for clients to 'link' against if catch is included as a sub-project |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 92 | add_library(Catch2::Catch2 ALIAS Catch2) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 93 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 94 | # Only perform the installation steps when Catch is not being used as |
| 95 | # a subproject via `add_subdirectory`, or the destinations will break, |
| 96 | # see https://github.com/catchorg/Catch2/issues/1373 |
| 97 | if (NOT_SUBPROJECT) |
| 98 | set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 99 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 100 | configure_package_config_file( |
| 101 | ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in |
| 102 | ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake |
| 103 | INSTALL_DESTINATION |
| 104 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 105 | ) |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 106 | |
| 107 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 108 | # create and install an export set for catch target as Catch2::Catch |
| 109 | install( |
| 110 | TARGETS |
| 111 | Catch2 |
| 112 | EXPORT |
| 113 | Catch2Targets |
| 114 | DESTINATION |
| 115 | ${CMAKE_INSTALL_LIBDIR} |
| 116 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 117 | |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 118 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 119 | install( |
| 120 | EXPORT |
| 121 | Catch2Targets |
| 122 | NAMESPACE |
| 123 | Catch2:: |
| 124 | DESTINATION |
| 125 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 126 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 127 | |
Martin Hořeňovský | 646e1f6 | 2018-09-01 21:51:49 +0200 | [diff] [blame] | 128 | # By default, FooConfigVersion is tied to architecture that it was |
| 129 | # generated on. Because Catch2 is header-only, it is arch-independent |
| 130 | # and thus Catch2ConfigVersion should not be tied to the architecture |
| 131 | # it was generated on. |
| 132 | # |
| 133 | # CMake does not provide a direct customization point for this in |
| 134 | # `write_basic_package_version_file`, but it can be accomplished |
| 135 | # indirectly by temporarily undefining `CMAKE_SIZEOF_VOID_P`. |
| 136 | set(CATCH2_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) |
| 137 | unset(CMAKE_SIZEOF_VOID_P) |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 138 | write_basic_package_version_file( |
| 139 | "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" |
| 140 | COMPATIBILITY |
| 141 | SameMajorVersion |
| 142 | ) |
Martin Hořeňovský | 646e1f6 | 2018-09-01 21:51:49 +0200 | [diff] [blame] | 143 | set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P}) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 144 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 145 | install( |
| 146 | DIRECTORY |
| 147 | "single_include/" |
| 148 | DESTINATION |
| 149 | "${CMAKE_INSTALL_INCLUDEDIR}" |
| 150 | ) |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 151 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 152 | install( |
| 153 | FILES |
| 154 | "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake" |
| 155 | "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" |
| 156 | DESTINATION |
| 157 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 158 | ) |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 159 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 160 | # Install documentation |
| 161 | if(CATCH_INSTALL_DOCS) |
| 162 | install( |
| 163 | DIRECTORY |
| 164 | docs/ |
| 165 | DESTINATION |
| 166 | "${CMAKE_INSTALL_DOCDIR}" |
| 167 | ) |
| 168 | endif() |
Martin Hořeňovský | ed582bd | 2018-06-23 19:04:22 +0200 | [diff] [blame] | 169 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 170 | if(CATCH_INSTALL_HELPERS) |
| 171 | # Install CMake scripts |
| 172 | install( |
| 173 | FILES |
| 174 | "contrib/ParseAndAddCatchTests.cmake" |
| 175 | "contrib/Catch.cmake" |
| 176 | "contrib/CatchAddTests.cmake" |
| 177 | DESTINATION |
| 178 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 179 | ) |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 180 | |
Martin Hořeňovský | 0646e02 | 2018-08-31 11:40:55 +0200 | [diff] [blame] | 181 | # Install debugger helpers |
| 182 | install( |
| 183 | FILES |
| 184 | "contrib/gdbinit" |
| 185 | "contrib/lldbinit" |
| 186 | DESTINATION |
| 187 | ${CMAKE_INSTALL_DATAROOTDIR}/Catch2 |
| 188 | ) |
| 189 | endif() |
| 190 | |
| 191 | ## Provide some pkg-config integration |
| 192 | set(PKGCONFIG_INSTALL_DIR |
| 193 | "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" |
| 194 | CACHE PATH "Path where catch2.pc is installed" |
| 195 | ) |
| 196 | configure_file( |
| 197 | ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in |
| 198 | ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc |
| 199 | @ONLY |
| 200 | ) |
| 201 | install( |
| 202 | FILES |
| 203 | "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc" |
| 204 | DESTINATION |
| 205 | ${PKGCONFIG_INSTALL_DIR} |
| 206 | ) |
| 207 | |
| 208 | endif(NOT_SUBPROJECT) |