Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
blob: 94f90d9f12f58fa5063eaadfd7fc04a97c326c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
cmake_minimum_required(VERSION 3.5)

# detect if Catch is being bundled,
# disable testsuite in that case
if(NOT DEFINED PROJECT_NAME)
  set(NOT_SUBPROJECT ON)
endif()

project(Catch2 LANGUAGES CXX VERSION 2.3.0)

# Provide path for scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CTest)

option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF)
option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF)
option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)


set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# define some folders
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
set(HEADER_DIR ${CATCH_DIR}/include)

if(USE_WMAIN)
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
endif()

if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
    add_subdirectory(projects)
endif()

if(CATCH_BUILD_EXAMPLES)
    add_subdirectory(examples)
endif()


# add catch as a 'linkable' target
add_library(Catch2 INTERFACE)



# depend on some obvious c++11 features so the dependency is transitively added dependents
target_compile_features(Catch2
  INTERFACE
    cxx_alignas
    cxx_alignof
    cxx_attributes
    cxx_auto_type
    cxx_constexpr
    cxx_defaulted_functions
    cxx_deleted_functions
    cxx_final
    cxx_lambdas
    cxx_noexcept
    cxx_override
    cxx_range_for
    cxx_rvalue_references
    cxx_static_assert
    cxx_strong_enums
    cxx_trailing_return_types
    cxx_unicode_literals
    cxx_user_literals
    cxx_variadic_macros
)

target_include_directories(Catch2
  INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
add_library(Catch2::Catch2 ALIAS Catch2)

set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")

include(CMakePackageConfigHelpers)
configure_package_config_file(
    ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
    INSTALL_DESTINATION
      ${CATCH_CMAKE_CONFIG_DESTINATION}
)


# create and install an export set for catch target as Catch2::Catch
install(
  TARGETS
    Catch2
  EXPORT
    Catch2Targets
  DESTINATION
    ${CMAKE_INSTALL_LIBDIR}
)


install(
  EXPORT
    Catch2Targets
  NAMESPACE
    Catch2::
  DESTINATION
    ${CATCH_CMAKE_CONFIG_DESTINATION}
)

write_basic_package_version_file(
  "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
  COMPATIBILITY
    SameMajorVersion
)

install(
  DIRECTORY
    "single_include/"
  DESTINATION
    "${CMAKE_INSTALL_INCLUDEDIR}"
)
    
install(
  FILES 
    "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
  DESTINATION
    ${CATCH_CMAKE_CONFIG_DESTINATION}
)

# Install documentation
if(CATCH_INSTALL_DOCS)
  install(
    DIRECTORY
      docs/
    DESTINATION
      "${CMAKE_INSTALL_DOCDIR}"
  )
endif()

if(CATCH_INSTALL_HELPERS)
# Install CMake scripts
install(
  FILES
    "contrib/ParseAndAddCatchTests.cmake"
    "contrib/Catch.cmake"
    "contrib/CatchAddTests.cmake"
  DESTINATION
    ${CATCH_CMAKE_CONFIG_DESTINATION}
)

# Install debugger helpers
install(
  FILES
    "contrib/gdbinit"
    "contrib/lldbinit"
  DESTINATION
    ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
)
endif()

## Provide some pkg-config integration
set(PKGCONFIG_INSTALL_DIR
    "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
    CACHE PATH "Path where catch2.pc is installed"
)
configure_file(
  ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
  ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
  @ONLY
)
install(
  FILES
    "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
  DESTINATION
    ${PKGCONFIG_INSTALL_DIR}
)