forked from catchorg/Catch2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
74 lines (57 loc) · 2.6 KB
/
CMakeLists.txt
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
#[[
Catch, Formlabs fork
====================
Usage
-----
* Include the directory containing this CMakeLists.txt into your project.
* Link your test binaries against the build target, `Catch`.
* The header `catch.hpp` should be visible in the sources of those bianries.
* Use Catch as normal.
More details
------------
This CMakeLists.txt will check whether there is already a target called `Catch`
defined. If so, it will try to determine whether that version of Catch is
compatible with this one. The way this is done is that the `_CATCH_GIT_REVISION`
property of the target is queried, and compared for equality with the Git
revision of this repository. If that target property is not found, or does not
match this repository's Git revision, then a warning message is printed.
If no `Catch` target exists, one will be defined as normal.
This is all done to support, for example, the scenario that your repository uses
submodules A and B, and both A and B use Catch. If both A and B include Catch
using this repository, and their Catch revisions are in sync, there will be no
problem. If the revisions are out-of-sync, then you will get a warning message,
and if the Catch versions are actually incompatible then your test code may
break.
]]
cmake_minimum_required (VERSION 3.4)
find_package (Git REQUIRED)
execute_process (
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE _CATCH_GIT_REVISION
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
string (STRIP "${_CATCH_GIT_REVISION}" _CATCH_GIT_REVISION)
if (TARGET Catch)
get_target_property (_OTHER_CATCH_INCLUDE_DIRECTORIES
Catch INTERFACE_INCLUDE_DIRECTORIES
)
list (GET _OTHER_CATCH_INCLUDE_DIRECTORIES 0 _OTHER_CATCH_INCLUDE_DIRECTORY)
execute_process (
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE _OTHER_CATCH_GIT_REVISION
WORKING_DIRECTORY ${_OTHER_CATCH_INCLUDE_DIRECTORY}
)
string (STRIP "${_OTHER_CATCH_GIT_REVISION}" _OTHER_CATCH_GIT_REVISION)
if (NOT ${_CATCH_GIT_REVISION} STREQUAL ${_OTHER_CATCH_GIT_REVISION})
message (WARNING "
Potentially incompatible versions of Catch found!
The revision at ${CMAKE_CURRENT_SOURCE_DIR} is ${_CATCH_GIT_REVISION}.
The revision of the existing Catch target is ${_OTHER_CATCH_GIT_REVISION}.
The include directories of the existing Catch target are ${_OTHER_CATCH_INCLUDE_DIRECTORIES}.
The other Catch target is the one that will be used.
")
endif ()
else ()
add_library (Catch INTERFACE)
target_include_directories (Catch INTERFACE single_include)
endif ()