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) |
| 21 | option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF) |
| 22 | option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON) |
Paul le Roux | 0eb99fb | 2018-06-19 07:14:09 +0200 | [diff] [blame] | 23 | option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON) |
Martin Hořeňovský | ed582bd | 2018-06-23 19:04:22 +0200 | [diff] [blame] | 24 | option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON) |
| 25 | |
Martin Hořeňovský | a20b286 | 2017-11-05 12:46:04 +0100 | [diff] [blame] | 26 | |
Phil Nash | 8abe17a | 2017-01-09 16:27:06 +0000 | [diff] [blame] | 27 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 28 | |
Kosta | ce441a9 | 2013-08-05 12:40:33 +0200 | [diff] [blame] | 29 | # define some folders |
Phil Nash | c8fefc4 | 2017-01-06 16:19:20 +0000 | [diff] [blame] | 30 | set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Kosta | ce441a9 | 2013-08-05 12:40:33 +0200 | [diff] [blame] | 31 | set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest) |
Martin Hořeňovský | 3b7511e | 2017-01-14 21:55:37 +0100 | [diff] [blame] | 32 | set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark) |
Phil Nash | e1fbbe1 | 2017-01-06 16:59:18 +0000 | [diff] [blame] | 33 | set(HEADER_DIR ${CATCH_DIR}/include) |
| 34 | |
Antonio Di Monaco | b8443e6 | 2017-05-11 13:00:03 +0200 | [diff] [blame] | 35 | if(USE_WMAIN) |
| 36 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") |
| 37 | endif() |
| 38 | |
David Seifert | 7f18282 | 2018-08-18 22:06:25 +0200 | [diff] [blame^] | 39 | find_package(PythonInterp) |
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) |
David Seifert | 7f18282 | 2018-08-18 22:06:25 +0200 | [diff] [blame^] | 41 | if (NOT PYTHONINTERP_FOUND) |
| 42 | message(FATAL_ERROR "Python not found, but required for tests") |
| 43 | endif() |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 44 | add_subdirectory(projects) |
| 45 | endif() |
Saad K | 7dd4f29 | 2017-01-31 14:22:45 -0500 | [diff] [blame] | 46 | |
David Seifert | b0f4f16 | 2018-01-18 19:20:08 +0100 | [diff] [blame] | 47 | if(CATCH_BUILD_EXAMPLES) |
Martin Moene | 85de072 | 2017-11-05 09:15:22 +0100 | [diff] [blame] | 48 | add_subdirectory(examples) |
| 49 | endif() |
| 50 | |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 51 | |
| 52 | # add catch as a 'linkable' target |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 53 | add_library(Catch2 INTERFACE) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 54 | |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 55 | |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 56 | |
| 57 | # depend on some obvious c++11 features so the dependency is transitively added dependents |
| 58 | target_compile_features(Catch2 |
| 59 | INTERFACE |
| 60 | cxx_alignas |
| 61 | cxx_alignof |
| 62 | cxx_attributes |
| 63 | cxx_auto_type |
| 64 | cxx_constexpr |
| 65 | cxx_defaulted_functions |
| 66 | cxx_deleted_functions |
| 67 | cxx_final |
| 68 | cxx_lambdas |
| 69 | cxx_noexcept |
| 70 | cxx_override |
| 71 | cxx_range_for |
| 72 | cxx_rvalue_references |
| 73 | cxx_static_assert |
| 74 | cxx_strong_enums |
| 75 | cxx_trailing_return_types |
| 76 | cxx_unicode_literals |
| 77 | cxx_user_literals |
| 78 | cxx_variadic_macros |
| 79 | ) |
| 80 | |
| 81 | target_include_directories(Catch2 |
| 82 | INTERFACE |
| 83 | $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include> |
| 84 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 85 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 86 | |
| 87 | # 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] | 88 | add_library(Catch2::Catch2 ALIAS Catch2) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 89 | |
| 90 | set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") |
| 91 | |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 92 | include(CMakePackageConfigHelpers) |
| 93 | configure_package_config_file( |
| 94 | ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in |
| 95 | ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake |
| 96 | INSTALL_DESTINATION |
| 97 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 98 | ) |
| 99 | |
| 100 | |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 101 | # create and install an export set for catch target as Catch2::Catch |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 102 | install( |
| 103 | TARGETS |
| 104 | Catch2 |
| 105 | EXPORT |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 106 | Catch2Targets |
| 107 | DESTINATION |
| 108 | ${CMAKE_INSTALL_LIBDIR} |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 109 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 110 | |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 111 | |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 112 | install( |
| 113 | EXPORT |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 114 | Catch2Targets |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 115 | NAMESPACE |
| 116 | Catch2:: |
| 117 | DESTINATION |
| 118 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 119 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 120 | |
Bastian Dörig | d38f782 | 2018-02-09 10:50:14 +0100 | [diff] [blame] | 121 | write_basic_package_version_file( |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 122 | "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" |
| 123 | COMPATIBILITY |
| 124 | SameMajorVersion |
| 125 | ) |
Daniel J. Rollins | 39bfc6e | 2018-01-29 22:56:43 +0000 | [diff] [blame] | 126 | |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 127 | install( |
| 128 | DIRECTORY |
| 129 | "single_include/" |
| 130 | DESTINATION |
| 131 | "${CMAKE_INSTALL_INCLUDEDIR}" |
| 132 | ) |
| 133 | |
| 134 | install( |
| 135 | FILES |
Martin Hořeňovský | 1af60ef | 2018-06-24 10:11:14 +0200 | [diff] [blame] | 136 | "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake" |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 137 | "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" |
| 138 | DESTINATION |
| 139 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 140 | ) |
| 141 | |
| 142 | # Install documentation |
Paul le Roux | 0eb99fb | 2018-06-19 07:14:09 +0200 | [diff] [blame] | 143 | if(CATCH_INSTALL_DOCS) |
| 144 | install( |
| 145 | DIRECTORY |
| 146 | docs/ |
| 147 | DESTINATION |
| 148 | "${CMAKE_INSTALL_DOCDIR}" |
| 149 | ) |
| 150 | endif() |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 151 | |
Martin Hořeňovský | ed582bd | 2018-06-23 19:04:22 +0200 | [diff] [blame] | 152 | if(CATCH_INSTALL_HELPERS) |
| 153 | # Install CMake scripts |
| 154 | install( |
| 155 | FILES |
| 156 | "contrib/ParseAndAddCatchTests.cmake" |
| 157 | "contrib/Catch.cmake" |
| 158 | "contrib/CatchAddTests.cmake" |
| 159 | DESTINATION |
| 160 | ${CATCH_CMAKE_CONFIG_DESTINATION} |
| 161 | ) |
| 162 | |
| 163 | # Install debugger helpers |
| 164 | install( |
| 165 | FILES |
| 166 | "contrib/gdbinit" |
| 167 | "contrib/lldbinit" |
| 168 | DESTINATION |
| 169 | ${CMAKE_INSTALL_DATAROOTDIR}/Catch2 |
| 170 | ) |
| 171 | endif() |
Martin Hořeňovský | 44722f9 | 2018-06-11 10:48:10 +0200 | [diff] [blame] | 172 | |
| 173 | ## Provide some pkg-config integration |
| 174 | set(PKGCONFIG_INSTALL_DIR |
| 175 | "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" |
| 176 | CACHE PATH "Path where catch2.pc is installed" |
| 177 | ) |
| 178 | configure_file( |
| 179 | ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in |
| 180 | ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc |
| 181 | @ONLY |
| 182 | ) |
| 183 | install( |
| 184 | FILES |
| 185 | "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc" |
| 186 | DESTINATION |
| 187 | ${PKGCONFIG_INSTALL_DIR} |
| 188 | ) |