cja 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cja-0.2.0 → cja-0.2.2}/PKG-INFO +3 -3
- {cja-0.2.0 → cja-0.2.2}/pyproject.toml +3 -3
- {cja-0.2.0 → cja-0.2.2}/src/cja/cli.py +68 -2
- cja-0.2.2/src/cja/cmake/Modules/FindGTest.cmake +509 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/commands.py +136 -10
- {cja-0.2.0 → cja-0.2.2}/src/cja/find_package.py +45 -64
- {cja-0.2.0 → cja-0.2.2}/src/cja/generator.py +515 -120
- {cja-0.2.0 → cja-0.2.2}/src/cja/ninja_syntax.py +5 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/utils.py +4 -1
- {cja-0.2.0 → cja-0.2.2}/README.md +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/__init__.py +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/__main__.py +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/build_context.py +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/parser.py +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/py.typed +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/syntax.py +0 -0
- {cja-0.2.0 → cja-0.2.2}/src/cja/targets.py +0 -0
{cja-0.2.0 → cja-0.2.2}/PKG-INFO
RENAMED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: cja
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: CMake-compatible build system that generates Ninja build files
|
|
5
5
|
Author: Jan Niklas Hasse
|
|
6
6
|
Author-email: Jan Niklas Hasse <jhasse@bixense.com>
|
|
7
7
|
License: GPL-3.0-or-later
|
|
8
|
-
Requires-Dist: rich>=14.3.
|
|
8
|
+
Requires-Dist: rich>=14.3.3
|
|
9
9
|
Requires-Dist: termcolor>=3.3.0
|
|
10
|
-
Requires-Python: >=3.
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
11
|
Project-URL: Repository, https://github.com/jhasse/cja
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "cja"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.2"
|
|
4
4
|
description = "CMake-compatible build system that generates Ninja build files"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = { text = "GPL-3.0-or-later" }
|
|
7
7
|
authors = [
|
|
8
8
|
{ name = "Jan Niklas Hasse", email = "jhasse@bixense.com" }
|
|
9
9
|
]
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"rich>=14.3.
|
|
12
|
+
"rich>=14.3.3",
|
|
13
13
|
"termcolor>=3.3.0",
|
|
14
14
|
]
|
|
15
15
|
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"""Command-line interface for cja."""
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
+
import importlib.metadata
|
|
5
|
+
import json
|
|
4
6
|
import subprocess
|
|
5
7
|
import sys
|
|
6
8
|
from pathlib import Path
|
|
7
9
|
|
|
8
10
|
from termcolor import colored
|
|
9
11
|
|
|
12
|
+
from . import __version__
|
|
10
13
|
from .generator import configure
|
|
11
14
|
|
|
12
15
|
|
|
16
|
+
def _get_version() -> str:
|
|
17
|
+
"""Get cja package version."""
|
|
18
|
+
try:
|
|
19
|
+
return importlib.metadata.version("cja")
|
|
20
|
+
except importlib.metadata.PackageNotFoundError:
|
|
21
|
+
return __version__
|
|
22
|
+
|
|
23
|
+
|
|
13
24
|
def parse_define(value: str) -> tuple[str, str]:
|
|
14
25
|
"""Parse a -D argument into (name, value) tuple."""
|
|
15
26
|
if "=" in value:
|
|
@@ -79,8 +90,58 @@ def cmd_test(args: argparse.Namespace) -> int:
|
|
|
79
90
|
|
|
80
91
|
|
|
81
92
|
def cmd_run(args: argparse.Namespace) -> int:
|
|
82
|
-
"""
|
|
83
|
-
|
|
93
|
+
"""Build and run the first executable."""
|
|
94
|
+
source_dir = Path(".")
|
|
95
|
+
|
|
96
|
+
if args.release:
|
|
97
|
+
build_dir = "build-release"
|
|
98
|
+
variables: dict[str, str] = {"CMAKE_BUILD_TYPE": "Release"}
|
|
99
|
+
else:
|
|
100
|
+
build_dir = "build"
|
|
101
|
+
variables = {}
|
|
102
|
+
|
|
103
|
+
ninja_file = Path(f"{build_dir}.ninja")
|
|
104
|
+
|
|
105
|
+
cja_json_path = Path(build_dir) / "cja.json"
|
|
106
|
+
|
|
107
|
+
if not ninja_file.exists() or not cja_json_path.exists():
|
|
108
|
+
try:
|
|
109
|
+
configure(source_dir, build_dir, variables=variables if variables else None)
|
|
110
|
+
except FileNotFoundError as e:
|
|
111
|
+
error_label = colored("error:", "red", attrs=["bold"])
|
|
112
|
+
print(f"{error_label} {e}", file=sys.stderr)
|
|
113
|
+
return 1
|
|
114
|
+
except SyntaxError as e:
|
|
115
|
+
if e.filename and e.lineno:
|
|
116
|
+
rel_file = e.filename
|
|
117
|
+
try:
|
|
118
|
+
p = Path(e.filename)
|
|
119
|
+
if p.is_absolute():
|
|
120
|
+
rel_file = str(p.relative_to(Path(".").resolve()))
|
|
121
|
+
except ValueError:
|
|
122
|
+
pass
|
|
123
|
+
error_label = colored("error:", "red", attrs=["bold"])
|
|
124
|
+
print(f"{rel_file}:{e.lineno}: {error_label} {e.msg}", file=sys.stderr)
|
|
125
|
+
else:
|
|
126
|
+
error_label = colored("error:", "red", attrs=["bold"])
|
|
127
|
+
print(f"{error_label} Parse error: {e}", file=sys.stderr)
|
|
128
|
+
return 1
|
|
129
|
+
|
|
130
|
+
cja_config = json.loads(cja_json_path.read_text())
|
|
131
|
+
exe_path = cja_config["run_executable"]
|
|
132
|
+
|
|
133
|
+
# Build just the executable
|
|
134
|
+
ninja_cmd = ["ninja", "-f", str(ninja_file), exe_path]
|
|
135
|
+
result = subprocess.run(ninja_cmd)
|
|
136
|
+
if result.returncode != 0:
|
|
137
|
+
return result.returncode
|
|
138
|
+
|
|
139
|
+
# Run the executable directly, passing through any extra arguments
|
|
140
|
+
exe_cmd = [str(Path(exe_path))]
|
|
141
|
+
if hasattr(args, "ninja_args"):
|
|
142
|
+
exe_cmd.extend(args.ninja_args)
|
|
143
|
+
result = subprocess.run(exe_cmd)
|
|
144
|
+
return result.returncode
|
|
84
145
|
|
|
85
146
|
|
|
86
147
|
def cmd_command_mode(args: list[str]) -> int:
|
|
@@ -155,6 +216,11 @@ def main() -> int:
|
|
|
155
216
|
prog="cja",
|
|
156
217
|
description="A CMake reimplementation in Python with Ninja generator",
|
|
157
218
|
)
|
|
219
|
+
parser.add_argument(
|
|
220
|
+
"--version",
|
|
221
|
+
action="version",
|
|
222
|
+
version=f"%(prog)s {_get_version()}",
|
|
223
|
+
)
|
|
158
224
|
|
|
159
225
|
subparsers = parser.add_subparsers(dest="command")
|
|
160
226
|
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
2
|
+
# file LICENSE.rst or https://cmake.org/licensing for details.
|
|
3
|
+
|
|
4
|
+
#[=======================================================================[.rst:
|
|
5
|
+
FindGTest
|
|
6
|
+
---------
|
|
7
|
+
|
|
8
|
+
Finds GoogleTest, the Google C++ testing and mocking framework:
|
|
9
|
+
|
|
10
|
+
.. code-block:: cmake
|
|
11
|
+
|
|
12
|
+
find_package(GTest [...])
|
|
13
|
+
|
|
14
|
+
The GoogleTest framework also includes GoogleMock, a library for writing
|
|
15
|
+
and using C++ mock classes. On some systems, GoogleMock may be distributed
|
|
16
|
+
as a separate package.
|
|
17
|
+
|
|
18
|
+
When both debug and release (optimized) variants of the GoogleTest and
|
|
19
|
+
GoogleMock libraries are available, this module selects the appropriate
|
|
20
|
+
variants based on the current :ref:`Build Configuration <Build Configurations>`.
|
|
21
|
+
|
|
22
|
+
.. versionadded:: 3.20
|
|
23
|
+
If GoogleTest is built and installed using its CMake-based build system, it
|
|
24
|
+
provides a :ref:`package configuration file <Config File Packages>`
|
|
25
|
+
(``GTestConfig.cmake``) that can be used with :command:`find_package` in
|
|
26
|
+
:ref:`Config mode`. By default, this module now searches for that
|
|
27
|
+
configuration file and, if found, returns the results without further
|
|
28
|
+
action. If the upstream configuration file is not found, this module falls
|
|
29
|
+
back to :ref:`Module mode` and searches standard locations.
|
|
30
|
+
|
|
31
|
+
Imported Targets
|
|
32
|
+
^^^^^^^^^^^^^^^^
|
|
33
|
+
|
|
34
|
+
This module provides the following :ref:`Imported Targets`:
|
|
35
|
+
|
|
36
|
+
``GTest::gtest``
|
|
37
|
+
.. versionadded:: 3.20
|
|
38
|
+
|
|
39
|
+
Target encapsulating the usage requirements of the GoogleTest ``gtest``
|
|
40
|
+
library, available if GoogleTest is found. The ``gtest`` library provides
|
|
41
|
+
the core GoogleTest testing framework functionality.
|
|
42
|
+
|
|
43
|
+
``GTest::gtest_main``
|
|
44
|
+
.. versionadded:: 3.20
|
|
45
|
+
|
|
46
|
+
Target encapsulating the usage requirements of the GoogleTest ``gtest_main``
|
|
47
|
+
library, available if GoogleTest is found. The ``gtest_main`` library
|
|
48
|
+
provides a ``main()`` function, allowing tests to be run without defining
|
|
49
|
+
one manually.
|
|
50
|
+
|
|
51
|
+
Only link to ``GTest::gtest_main`` if GoogleTest should supply the
|
|
52
|
+
``main()`` function for the executable. If the project is supplying its
|
|
53
|
+
own ``main()`` implementation, link only to ``GTest::gtest``.
|
|
54
|
+
|
|
55
|
+
``GTest::gmock``
|
|
56
|
+
.. versionadded:: 3.23
|
|
57
|
+
|
|
58
|
+
Target encapsulating the usage requirements of the GoogleMock ``gmock``
|
|
59
|
+
library, available if GoogleTest and its Mock library are found. The
|
|
60
|
+
``gmock`` library provides facilities for writing and using mock classes
|
|
61
|
+
in C++.
|
|
62
|
+
|
|
63
|
+
``GTest::gmock_main``
|
|
64
|
+
.. versionadded:: 3.23
|
|
65
|
+
|
|
66
|
+
Target encapsulating the usage requirements of the GoogleMock ``gmock_main``
|
|
67
|
+
library, available if GoogleTest and ``gmock_main`` are found. The
|
|
68
|
+
``gmock_main`` library provides a ``main()`` function, allowing GoogleMock
|
|
69
|
+
tests to be run without defining one manually.
|
|
70
|
+
|
|
71
|
+
Only link to ``GTest::gmock_main`` if GoogleTest should supply the
|
|
72
|
+
``main()`` function for the executable. If project is supplying its own
|
|
73
|
+
``main()`` implementation, link only to ``GTest::gmock``.
|
|
74
|
+
|
|
75
|
+
Result Variables
|
|
76
|
+
^^^^^^^^^^^^^^^^
|
|
77
|
+
|
|
78
|
+
This module defines the following variables:
|
|
79
|
+
|
|
80
|
+
``GTest_FOUND``
|
|
81
|
+
.. versionadded:: 3.3
|
|
82
|
+
|
|
83
|
+
Boolean indicating whether GoogleTest was found.
|
|
84
|
+
|
|
85
|
+
Hints
|
|
86
|
+
^^^^^
|
|
87
|
+
|
|
88
|
+
This module accepts the following variables before calling
|
|
89
|
+
``find_package(GTest)``:
|
|
90
|
+
|
|
91
|
+
``GTEST_ROOT``
|
|
92
|
+
The root directory of the GoogleTest installation (may also be set as an
|
|
93
|
+
environment variable). This variable is used only when GoogleTest is found
|
|
94
|
+
in :ref:`Module mode`.
|
|
95
|
+
|
|
96
|
+
``GTEST_MSVC_SEARCH``
|
|
97
|
+
When compiling with MSVC, this variable controls which GoogleTest build
|
|
98
|
+
variant to search for, based on the runtime library linkage model. This
|
|
99
|
+
variable is used only when GoogleTest is found in :ref:`Module mode` and
|
|
100
|
+
accepts one of the following values:
|
|
101
|
+
|
|
102
|
+
``MD``
|
|
103
|
+
(Default) Searches for shared library variants of GoogleTest that are
|
|
104
|
+
built to link against the dynamic C runtime. These libraries are
|
|
105
|
+
typically compiled with the MSVC runtime flags ``/MD`` or ``/MDd`` (for
|
|
106
|
+
Release or Debug, respectively).
|
|
107
|
+
|
|
108
|
+
``MT``
|
|
109
|
+
Searches for static library variants of GoogleTest that are built to
|
|
110
|
+
link against the static C runtime. These libraries are typically
|
|
111
|
+
compiled with the MSVC runtime flags ``/MT`` or ``/MTd``.
|
|
112
|
+
|
|
113
|
+
Deprecated Items
|
|
114
|
+
^^^^^^^^^^^^^^^^
|
|
115
|
+
|
|
116
|
+
Deprecated Variables
|
|
117
|
+
""""""""""""""""""""
|
|
118
|
+
|
|
119
|
+
The following variables are provided for backward compatibility:
|
|
120
|
+
|
|
121
|
+
``GTEST_INCLUDE_DIRS``
|
|
122
|
+
.. deprecated:: 4.1
|
|
123
|
+
Use the ``GTest::gtest`` imported target instead, which exposes the
|
|
124
|
+
required include directories through its
|
|
125
|
+
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property.
|
|
126
|
+
|
|
127
|
+
Result variable that provides include directories containing headers
|
|
128
|
+
needed to use GoogleTest. This variable is only guaranteed to be available
|
|
129
|
+
when GoogleTest is found in :ref:`Module mode`.
|
|
130
|
+
|
|
131
|
+
``GTEST_LIBRARIES``
|
|
132
|
+
.. deprecated:: 4.1
|
|
133
|
+
Use the ``GTest::gtest`` imported target instead.
|
|
134
|
+
|
|
135
|
+
Result variable providing libraries needed to link against to use the
|
|
136
|
+
GoogleTest ``gtest`` library. Note that projects are also responsible
|
|
137
|
+
for linking with an appropriate thread library in addition to the libraries
|
|
138
|
+
specified by this variable.
|
|
139
|
+
|
|
140
|
+
``GTEST_MAIN_LIBRARIES``
|
|
141
|
+
.. deprecated:: 4.1
|
|
142
|
+
Use the ``GTest::gtest_main`` imported target instead.
|
|
143
|
+
|
|
144
|
+
Result variable providing libraries needed to link against to use the
|
|
145
|
+
GoogleTest ``gtest_main`` library.
|
|
146
|
+
|
|
147
|
+
``GTEST_BOTH_LIBRARIES``
|
|
148
|
+
.. deprecated:: 4.1
|
|
149
|
+
Use the ``GTest::gtest`` and ``GTest::gtest_main`` imported targets
|
|
150
|
+
instead.
|
|
151
|
+
|
|
152
|
+
Result variable providing both ``gtest`` and ``gtest_main`` libraries
|
|
153
|
+
combined.
|
|
154
|
+
|
|
155
|
+
``GTEST_FOUND``
|
|
156
|
+
.. deprecated:: 4.2
|
|
157
|
+
Use ``GTest_FOUND``, which has the same value.
|
|
158
|
+
|
|
159
|
+
Boolean indicating whether GoogleTest was found.
|
|
160
|
+
|
|
161
|
+
Deprecated Imported Targets
|
|
162
|
+
"""""""""""""""""""""""""""
|
|
163
|
+
|
|
164
|
+
For backward compatibility, this module also provides the following imported
|
|
165
|
+
targets (available since CMake 3.5):
|
|
166
|
+
|
|
167
|
+
``GTest::GTest``
|
|
168
|
+
.. deprecated:: 3.20
|
|
169
|
+
Use the ``GTest::gtest`` imported target instead.
|
|
170
|
+
|
|
171
|
+
Imported target linking the ``GTest::gtest`` library.
|
|
172
|
+
|
|
173
|
+
``GTest::Main``
|
|
174
|
+
.. deprecated:: 3.20
|
|
175
|
+
Use the ``GTest::gtest_main`` imported target instead.
|
|
176
|
+
|
|
177
|
+
Imported target linking the ``GTest::gtest_main`` library.
|
|
178
|
+
|
|
179
|
+
Examples
|
|
180
|
+
^^^^^^^^
|
|
181
|
+
|
|
182
|
+
Examples: Finding GoogleTest
|
|
183
|
+
""""""""""""""""""""""""""""
|
|
184
|
+
|
|
185
|
+
Finding GoogleTest:
|
|
186
|
+
|
|
187
|
+
.. code-block:: cmake
|
|
188
|
+
|
|
189
|
+
find_package(GoogleTest)
|
|
190
|
+
|
|
191
|
+
Or, finding GoogleTest and making it required (if not found, processing stops
|
|
192
|
+
with an error message):
|
|
193
|
+
|
|
194
|
+
.. code-block:: cmake
|
|
195
|
+
|
|
196
|
+
find_package(GoogleTest REQUIRED)
|
|
197
|
+
|
|
198
|
+
Examples: Using Imported Targets
|
|
199
|
+
""""""""""""""""""""""""""""""""
|
|
200
|
+
|
|
201
|
+
In the following example, the ``GTest::gtest`` imported target is linked to
|
|
202
|
+
a project target, which enables using the core GoogleTest testing framework:
|
|
203
|
+
|
|
204
|
+
.. code-block:: cmake
|
|
205
|
+
|
|
206
|
+
find_package(GTest REQUIRED)
|
|
207
|
+
|
|
208
|
+
target_link_libraries(foo PRIVATE GTest::gtest)
|
|
209
|
+
|
|
210
|
+
In the next example, the ``GTest::gtest_main`` imported target is also linked
|
|
211
|
+
to the executable, and a test is registered. The ``GTest::gtest_main`` library
|
|
212
|
+
provides a ``main()`` function, so there is no need to write one manually.
|
|
213
|
+
The ``GTest::gtest`` library is still linked because the test code directly
|
|
214
|
+
uses things provided by ``GTest::gtest``, and good practice is to link directly
|
|
215
|
+
to libraries used directly.
|
|
216
|
+
|
|
217
|
+
.. code-block:: cmake
|
|
218
|
+
|
|
219
|
+
enable_testing()
|
|
220
|
+
|
|
221
|
+
find_package(GTest REQUIRED)
|
|
222
|
+
|
|
223
|
+
add_executable(foo foo.cc)
|
|
224
|
+
target_link_libraries(foo PRIVATE GTest::gtest GTest::gtest_main)
|
|
225
|
+
|
|
226
|
+
add_test(NAME AllTestsInFoo COMMAND foo)
|
|
227
|
+
|
|
228
|
+
Deeper Integration With CTest
|
|
229
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
230
|
+
|
|
231
|
+
This module is commonly used with the :module:`GoogleTest` module, which
|
|
232
|
+
provides :command:`gtest_discover_tests` and :command:`gtest_add_tests`
|
|
233
|
+
commands to help integrate GoogleTest infrastructure with CTest:
|
|
234
|
+
|
|
235
|
+
.. code-block:: cmake
|
|
236
|
+
|
|
237
|
+
find_package(GTest)
|
|
238
|
+
target_link_libraries(example PRIVATE GTest::gtest GTest::gtest_main)
|
|
239
|
+
|
|
240
|
+
include(GoogleTest)
|
|
241
|
+
gtest_discover_tests(example)
|
|
242
|
+
|
|
243
|
+
# ...
|
|
244
|
+
|
|
245
|
+
.. versionchanged:: 3.9
|
|
246
|
+
Previous CMake versions defined the :command:`gtest_add_tests` command in
|
|
247
|
+
this module.
|
|
248
|
+
#]=======================================================================]
|
|
249
|
+
|
|
250
|
+
include(${CMAKE_CURRENT_LIST_DIR}/GoogleTest.cmake)
|
|
251
|
+
|
|
252
|
+
function(__gtest_append_debugs _endvar _library)
|
|
253
|
+
if(${_library} AND ${_library}_DEBUG)
|
|
254
|
+
set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
|
|
255
|
+
else()
|
|
256
|
+
set(_output ${${_library}})
|
|
257
|
+
endif()
|
|
258
|
+
set(${_endvar} ${_output} PARENT_SCOPE)
|
|
259
|
+
endfunction()
|
|
260
|
+
|
|
261
|
+
function(__gtest_find_library _name)
|
|
262
|
+
set(_gtest_hints "")
|
|
263
|
+
if(DEFINED GTEST_ROOT)
|
|
264
|
+
set(_gtest_hints ${GTEST_ROOT})
|
|
265
|
+
endif()
|
|
266
|
+
find_library(${_name}
|
|
267
|
+
NAMES ${ARGN}
|
|
268
|
+
HINTS
|
|
269
|
+
ENV GTEST_ROOT
|
|
270
|
+
${_gtest_hints}
|
|
271
|
+
PATH_SUFFIXES ${_gtest_libpath_suffixes}
|
|
272
|
+
)
|
|
273
|
+
mark_as_advanced(${_name})
|
|
274
|
+
endfunction()
|
|
275
|
+
|
|
276
|
+
macro(__gtest_determine_windows_library_type _var)
|
|
277
|
+
if(EXISTS "${${_var}}")
|
|
278
|
+
file(TO_NATIVE_PATH "${${_var}}" _lib_path)
|
|
279
|
+
get_filename_component(_name "${${_var}}" NAME_WE)
|
|
280
|
+
cmake_policy(PUSH)
|
|
281
|
+
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
|
|
282
|
+
file(STRINGS "${${_var}}" _match REGEX "${_name}\\.dll" LIMIT_COUNT 1)
|
|
283
|
+
cmake_policy(POP)
|
|
284
|
+
if(NOT _match STREQUAL "")
|
|
285
|
+
set(${_var}_TYPE SHARED PARENT_SCOPE)
|
|
286
|
+
else()
|
|
287
|
+
set(${_var}_TYPE UNKNOWN PARENT_SCOPE)
|
|
288
|
+
endif()
|
|
289
|
+
return()
|
|
290
|
+
endif()
|
|
291
|
+
endmacro()
|
|
292
|
+
|
|
293
|
+
function(__gtest_determine_library_type _var)
|
|
294
|
+
if(WIN32)
|
|
295
|
+
# For now, at least, only Windows really needs to know the library type
|
|
296
|
+
__gtest_determine_windows_library_type(${_var})
|
|
297
|
+
__gtest_determine_windows_library_type(${_var}_RELEASE)
|
|
298
|
+
__gtest_determine_windows_library_type(${_var}_DEBUG)
|
|
299
|
+
endif()
|
|
300
|
+
# If we get here, no determination was made from the above checks
|
|
301
|
+
set(${_var}_TYPE UNKNOWN PARENT_SCOPE)
|
|
302
|
+
endfunction()
|
|
303
|
+
|
|
304
|
+
function(__gtest_import_library _target _var _config)
|
|
305
|
+
if(_config)
|
|
306
|
+
set(_config_suffix "_${_config}")
|
|
307
|
+
else()
|
|
308
|
+
set(_config_suffix "")
|
|
309
|
+
endif()
|
|
310
|
+
|
|
311
|
+
set(_lib "${${_var}${_config_suffix}}")
|
|
312
|
+
if(EXISTS "${_lib}")
|
|
313
|
+
if(_config)
|
|
314
|
+
set_property(TARGET ${_target} APPEND PROPERTY
|
|
315
|
+
IMPORTED_CONFIGURATIONS ${_config})
|
|
316
|
+
endif()
|
|
317
|
+
set_target_properties(${_target} PROPERTIES
|
|
318
|
+
IMPORTED_LINK_INTERFACE_LANGUAGES${_config_suffix} "CXX")
|
|
319
|
+
if(WIN32 AND ${_var}_TYPE STREQUAL SHARED)
|
|
320
|
+
set_target_properties(${_target} PROPERTIES
|
|
321
|
+
IMPORTED_IMPLIB${_config_suffix} "${_lib}")
|
|
322
|
+
else()
|
|
323
|
+
set_target_properties(${_target} PROPERTIES
|
|
324
|
+
IMPORTED_LOCATION${_config_suffix} "${_lib}")
|
|
325
|
+
endif()
|
|
326
|
+
endif()
|
|
327
|
+
endfunction()
|
|
328
|
+
|
|
329
|
+
function(__gtest_define_backwards_compatible_library_targets)
|
|
330
|
+
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} PARENT_SCOPE)
|
|
331
|
+
|
|
332
|
+
# Add targets mapping the same library names as defined in
|
|
333
|
+
# older versions of CMake's FindGTest
|
|
334
|
+
if(NOT TARGET GTest::GTest)
|
|
335
|
+
add_library(GTest::GTest INTERFACE IMPORTED)
|
|
336
|
+
target_link_libraries(GTest::GTest INTERFACE GTest::gtest)
|
|
337
|
+
endif()
|
|
338
|
+
if(NOT TARGET GTest::Main)
|
|
339
|
+
add_library(GTest::Main INTERFACE IMPORTED)
|
|
340
|
+
target_link_libraries(GTest::Main INTERFACE GTest::gtest_main)
|
|
341
|
+
endif()
|
|
342
|
+
endfunction()
|
|
343
|
+
|
|
344
|
+
#
|
|
345
|
+
|
|
346
|
+
include(FindPackageHandleStandardArgs)
|
|
347
|
+
|
|
348
|
+
# first specifically look for the CMake version of GTest
|
|
349
|
+
find_package(GTest QUIET NO_MODULE)
|
|
350
|
+
|
|
351
|
+
# if we found the GTest cmake package then we are done, and
|
|
352
|
+
# can print what we found and return.
|
|
353
|
+
if(GTest_FOUND)
|
|
354
|
+
find_package_handle_standard_args(GTest HANDLE_COMPONENTS CONFIG_MODE)
|
|
355
|
+
|
|
356
|
+
set(GTEST_LIBRARIES GTest::gtest)
|
|
357
|
+
set(GTEST_MAIN_LIBRARIES GTest::gtest_main)
|
|
358
|
+
|
|
359
|
+
__gtest_define_backwards_compatible_library_targets()
|
|
360
|
+
|
|
361
|
+
return()
|
|
362
|
+
endif()
|
|
363
|
+
|
|
364
|
+
if(NOT DEFINED GTEST_MSVC_SEARCH)
|
|
365
|
+
set(GTEST_MSVC_SEARCH MD)
|
|
366
|
+
endif()
|
|
367
|
+
|
|
368
|
+
set(_gtest_libpath_suffixes lib)
|
|
369
|
+
if(MSVC)
|
|
370
|
+
if(GTEST_MSVC_SEARCH STREQUAL "MD")
|
|
371
|
+
list(APPEND _gtest_libpath_suffixes
|
|
372
|
+
msvc/gtest-md/Debug
|
|
373
|
+
msvc/gtest-md/Release
|
|
374
|
+
msvc/x64/Debug
|
|
375
|
+
msvc/x64/Release
|
|
376
|
+
msvc/2010/gtest-md/Win32-Debug
|
|
377
|
+
msvc/2010/gtest-md/Win32-Release
|
|
378
|
+
msvc/2010/gtest-md/x64-Debug
|
|
379
|
+
msvc/2010/gtest-md/x64-Release
|
|
380
|
+
)
|
|
381
|
+
elseif(GTEST_MSVC_SEARCH STREQUAL "MT")
|
|
382
|
+
list(APPEND _gtest_libpath_suffixes
|
|
383
|
+
msvc/gtest/Debug
|
|
384
|
+
msvc/gtest/Release
|
|
385
|
+
msvc/x64/Debug
|
|
386
|
+
msvc/x64/Release
|
|
387
|
+
msvc/2010/gtest/Win32-Debug
|
|
388
|
+
msvc/2010/gtest/Win32-Release
|
|
389
|
+
msvc/2010/gtest/x64-Debug
|
|
390
|
+
msvc/2010/gtest/x64-Release
|
|
391
|
+
)
|
|
392
|
+
endif()
|
|
393
|
+
endif()
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
set(_gtest_hints "")
|
|
397
|
+
if(DEFINED GTEST_ROOT AND NOT GTEST_ROOT STREQUAL "")
|
|
398
|
+
list(APPEND _gtest_hints "${GTEST_ROOT}/include")
|
|
399
|
+
endif()
|
|
400
|
+
|
|
401
|
+
if(DEFINED ENV{GTEST_ROOT} AND NOT "$ENV{GTEST_ROOT}" STREQUAL "")
|
|
402
|
+
list(APPEND _gtest_hints "$ENV{GTEST_ROOT}/include")
|
|
403
|
+
endif()
|
|
404
|
+
find_path(GTEST_INCLUDE_DIR gtest/gtest.h
|
|
405
|
+
HINTS ${_gtest_hints}
|
|
406
|
+
)
|
|
407
|
+
mark_as_advanced(GTEST_INCLUDE_DIR)
|
|
408
|
+
|
|
409
|
+
if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
|
|
410
|
+
# The provided /MD project files for Google Test add -md suffixes to the
|
|
411
|
+
# library names.
|
|
412
|
+
__gtest_find_library(GTEST_LIBRARY gtest-md gtest)
|
|
413
|
+
__gtest_find_library(GTEST_LIBRARY_DEBUG gtest-mdd gtestd)
|
|
414
|
+
__gtest_find_library(GTEST_MAIN_LIBRARY gtest_main-md gtest_main)
|
|
415
|
+
__gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_main-mdd gtest_maind)
|
|
416
|
+
__gtest_find_library(GMOCK_LIBRARY gmock-md gmock)
|
|
417
|
+
__gtest_find_library(GMOCK_LIBRARY_DEBUG gmock-mdd gmockd)
|
|
418
|
+
__gtest_find_library(GMOCK_MAIN_LIBRARY gmock_main-md gmock_main)
|
|
419
|
+
__gtest_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_main-mdd gmock_maind)
|
|
420
|
+
else()
|
|
421
|
+
__gtest_find_library(GTEST_LIBRARY gtest)
|
|
422
|
+
__gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
|
|
423
|
+
__gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
|
|
424
|
+
__gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
|
|
425
|
+
__gtest_find_library(GMOCK_LIBRARY gmock)
|
|
426
|
+
__gtest_find_library(GMOCK_LIBRARY_DEBUG gmockd)
|
|
427
|
+
__gtest_find_library(GMOCK_MAIN_LIBRARY gmock_main)
|
|
428
|
+
__gtest_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind)
|
|
429
|
+
endif()
|
|
430
|
+
|
|
431
|
+
find_package_handle_standard_args(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
|
|
432
|
+
|
|
433
|
+
if(GMOCK_LIBRARY AND GMOCK_MAIN_LIBRARY)
|
|
434
|
+
set(GMock_FOUND True)
|
|
435
|
+
else()
|
|
436
|
+
set(GMock_FOUND False)
|
|
437
|
+
endif()
|
|
438
|
+
|
|
439
|
+
if(GTest_FOUND)
|
|
440
|
+
set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
|
|
441
|
+
__gtest_append_debugs(GTEST_LIBRARIES GTEST_LIBRARY)
|
|
442
|
+
__gtest_append_debugs(GTEST_MAIN_LIBRARIES GTEST_MAIN_LIBRARY)
|
|
443
|
+
|
|
444
|
+
find_package(Threads QUIET)
|
|
445
|
+
|
|
446
|
+
if(NOT TARGET GTest::gtest)
|
|
447
|
+
__gtest_determine_library_type(GTEST_LIBRARY)
|
|
448
|
+
add_library(GTest::gtest ${GTEST_LIBRARY_TYPE} IMPORTED)
|
|
449
|
+
if(TARGET Threads::Threads)
|
|
450
|
+
set_target_properties(GTest::gtest PROPERTIES
|
|
451
|
+
INTERFACE_LINK_LIBRARIES Threads::Threads)
|
|
452
|
+
endif()
|
|
453
|
+
if(GTEST_LIBRARY_TYPE STREQUAL "SHARED")
|
|
454
|
+
set_target_properties(GTest::gtest PROPERTIES
|
|
455
|
+
INTERFACE_COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
|
|
456
|
+
endif()
|
|
457
|
+
if(GTEST_INCLUDE_DIRS)
|
|
458
|
+
set_target_properties(GTest::gtest PROPERTIES
|
|
459
|
+
INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
|
|
460
|
+
endif()
|
|
461
|
+
__gtest_import_library(GTest::gtest GTEST_LIBRARY "")
|
|
462
|
+
__gtest_import_library(GTest::gtest GTEST_LIBRARY "RELEASE")
|
|
463
|
+
__gtest_import_library(GTest::gtest GTEST_LIBRARY "DEBUG")
|
|
464
|
+
endif()
|
|
465
|
+
if(NOT TARGET GTest::gtest_main)
|
|
466
|
+
__gtest_determine_library_type(GTEST_MAIN_LIBRARY)
|
|
467
|
+
add_library(GTest::gtest_main ${GTEST_MAIN_LIBRARY_TYPE} IMPORTED)
|
|
468
|
+
set_target_properties(GTest::gtest_main PROPERTIES
|
|
469
|
+
INTERFACE_LINK_LIBRARIES "GTest::gtest")
|
|
470
|
+
__gtest_import_library(GTest::gtest_main GTEST_MAIN_LIBRARY "")
|
|
471
|
+
__gtest_import_library(GTest::gtest_main GTEST_MAIN_LIBRARY "RELEASE")
|
|
472
|
+
__gtest_import_library(GTest::gtest_main GTEST_MAIN_LIBRARY "DEBUG")
|
|
473
|
+
endif()
|
|
474
|
+
|
|
475
|
+
__gtest_define_backwards_compatible_library_targets()
|
|
476
|
+
endif()
|
|
477
|
+
|
|
478
|
+
if(GMock_FOUND AND GTest_FOUND)
|
|
479
|
+
if(NOT TARGET GTest::gmock)
|
|
480
|
+
__gtest_determine_library_type(GMOCK_LIBRARY)
|
|
481
|
+
add_library(GTest::gmock ${GMOCK_LIBRARY_TYPE} IMPORTED)
|
|
482
|
+
set(_gmock_link_libraries "GTest::gtest")
|
|
483
|
+
if(TARGET Threads::Threads)
|
|
484
|
+
list(APPEND _gmock_link_libraries Threads::Threads)
|
|
485
|
+
endif()
|
|
486
|
+
set_target_properties(GTest::gmock PROPERTIES
|
|
487
|
+
INTERFACE_LINK_LIBRARIES "${_gmock_link_libraries}")
|
|
488
|
+
if(GMOCK_LIBRARY_TYPE STREQUAL "SHARED")
|
|
489
|
+
set_target_properties(GTest::gmock PROPERTIES
|
|
490
|
+
INTERFACE_COMPILE_DEFINITIONS "GMOCK_LINKED_AS_SHARED_LIBRARY=1")
|
|
491
|
+
endif()
|
|
492
|
+
if(GTEST_INCLUDE_DIRS)
|
|
493
|
+
set_target_properties(GTest::gmock PROPERTIES
|
|
494
|
+
INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
|
|
495
|
+
endif()
|
|
496
|
+
__gtest_import_library(GTest::gmock GMOCK_LIBRARY "")
|
|
497
|
+
__gtest_import_library(GTest::gmock GMOCK_LIBRARY "RELEASE")
|
|
498
|
+
__gtest_import_library(GTest::gmock GMOCK_LIBRARY "DEBUG")
|
|
499
|
+
endif()
|
|
500
|
+
if(NOT TARGET GTest::gmock_main)
|
|
501
|
+
__gtest_determine_library_type(GMOCK_MAIN_LIBRARY)
|
|
502
|
+
add_library(GTest::gmock_main ${GMOCK_MAIN_LIBRARY_TYPE} IMPORTED)
|
|
503
|
+
set_target_properties(GTest::gmock_main PROPERTIES
|
|
504
|
+
INTERFACE_LINK_LIBRARIES "GTest::gmock")
|
|
505
|
+
__gtest_import_library(GTest::gmock_main GMOCK_MAIN_LIBRARY "")
|
|
506
|
+
__gtest_import_library(GTest::gmock_main GMOCK_MAIN_LIBRARY "RELEASE")
|
|
507
|
+
__gtest_import_library(GTest::gmock_main GMOCK_MAIN_LIBRARY "DEBUG")
|
|
508
|
+
endif()
|
|
509
|
+
endif()
|