Skip to content

Commit ab6f955

Browse files
committed
Initial commit: Build the libs
0 parents  commit ab6f955

File tree

5 files changed

+237
-0
lines changed

5 files changed

+237
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.zig-cache
2+
zig-out

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

REAMDE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# `build.zig` for Catch2
2+
3+
Provides a package to be used by the zig package manager for C++ programs.
4+
5+
## Status
6+
7+
| Refname | Catch2 version | Zig `0.12.x` | Zig `0.13.x` | Zig `0.14.0-dev` |
8+
|:--------|:---------------|:------------:|:------------:|:----------------:|
9+
| `3.7.1` | `v3.7.1` ||||
10+
11+
## Use
12+
13+
Add the dependency in your `build.zig.zon` by running the following command:
14+
```bash
15+
zig fetch --save git+https://github.com/allyourcodebase/catch2#3.7.1
16+
```
17+
18+
Then, in your `build.zig`:
19+
```zig
20+
const catch2_dep = b.dependency("catch2", { .target = target, .optimize = optimize });
21+
const catch2 = catch2_dep.artifact("Catch2"); // or Catch2WithMain
22+
// wherever needed:
23+
exe.linkLibrary(catch2);
24+
```

build.zig

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
const std = @import("std");
2+
3+
const version = .{ .major = 3, .minor = 7, .patch = 1 };
4+
5+
pub fn build(b: *std.Build) !void {
6+
const target = b.standardTargetOptions(.{});
7+
const optimize = b.standardOptimizeOption(.{});
8+
9+
const upstream = b.dependency("upstream", .{ .target = target, .optimize = optimize });
10+
11+
const add_prefix = b.option(bool, "add-prefix", "Prefix all macros with CATCH_") orelse false;
12+
const console_width = b.option(u32, "console-width", "Number of columns in the output: affects line wraps. (Defaults to 80)") orelse 80;
13+
const fast_compile = b.option(bool, "fast-compile", "Sacrifices some (rather minor) features for compilation speed") orelse false;
14+
const disable = b.option(bool, "disable", "Disables assertions and test case registration") orelse false;
15+
16+
const config = b.addConfigHeader(
17+
.{
18+
.style = .{ .cmake = upstream.path("src/catch2/catch_user_config.hpp.in") },
19+
.include_path = "catch2/catch_user_config.hpp",
20+
},
21+
.{
22+
.CATCH_CONFIG_PREFIX_ALL = add_prefix,
23+
.CATCH_CONFIG_CONSOLE_WIDTH = console_width,
24+
.CATCH_CONFIG_FAST_COMPILE = fast_compile,
25+
.CATCH_CONFIG_DISABLE = disable,
26+
.CATCH_CONFIG_DEFAULT_REPORTER = null,
27+
.CATCH_CONFIG_FALLBACK_STRINGIFIER = null,
28+
},
29+
);
30+
31+
const catch2 = b.addStaticLibrary(.{ .name = "catch2", .target = target, .optimize = optimize });
32+
catch2.addCSourceFiles(.{
33+
.root = upstream.path("src/catch2"),
34+
.files = &source_files,
35+
.flags = &CXXFLAGS,
36+
});
37+
catch2.installConfigHeader(config);
38+
39+
const with_main = b.addStaticLibrary(.{ .name = "Catch2WithMain", .target = target, .optimize = optimize });
40+
with_main.addCSourceFiles(.{
41+
.root = upstream.path("src/catch2/internal"),
42+
.files = &.{"catch_main.cpp"},
43+
.flags = &CXXFLAGS,
44+
});
45+
46+
const libs = [_]*std.Build.Step.Compile{ catch2, with_main };
47+
for (libs) |lib| {
48+
lib.linkLibCpp();
49+
lib.addIncludePath(upstream.path("src"));
50+
lib.addConfigHeader(config);
51+
b.installArtifact(lib);
52+
}
53+
}
54+
55+
const CXXFLAGS = .{
56+
"--std=c++20",
57+
"-Wall",
58+
"-Wextra",
59+
"-Werror",
60+
};
61+
62+
const source_files = .{
63+
"benchmark/catch_chronometer.cpp",
64+
"benchmark/detail/catch_analyse.cpp",
65+
"benchmark/detail/catch_benchmark_function.cpp",
66+
"benchmark/detail/catch_run_for_at_least.cpp",
67+
"benchmark/detail/catch_stats.cpp",
68+
69+
"catch_approx.cpp",
70+
"catch_assertion_result.cpp",
71+
"catch_config.cpp",
72+
"catch_get_random_seed.cpp",
73+
"catch_message.cpp",
74+
"catch_registry_hub.cpp",
75+
"catch_session.cpp",
76+
"catch_tag_alias_autoregistrar.cpp",
77+
"catch_test_case_info.cpp",
78+
"catch_test_spec.cpp",
79+
"catch_timer.cpp",
80+
"catch_tostring.cpp",
81+
"catch_totals.cpp",
82+
"catch_translate_exception.cpp",
83+
"catch_version.cpp",
84+
"internal/catch_assertion_handler.cpp",
85+
"internal/catch_case_insensitive_comparisons.cpp",
86+
"internal/catch_clara.cpp",
87+
"internal/catch_commandline.cpp",
88+
"internal/catch_console_colour.cpp",
89+
"internal/catch_context.cpp",
90+
"internal/catch_debug_console.cpp",
91+
"internal/catch_debugger.cpp",
92+
"internal/catch_decomposer.cpp",
93+
"internal/catch_enforce.cpp",
94+
"internal/catch_enum_values_registry.cpp",
95+
"internal/catch_errno_guard.cpp",
96+
"internal/catch_exception_translator_registry.cpp",
97+
"internal/catch_fatal_condition_handler.cpp",
98+
"internal/catch_floating_point_helpers.cpp",
99+
"internal/catch_getenv.cpp",
100+
"internal/catch_istream.cpp",
101+
"internal/catch_jsonwriter.cpp",
102+
"internal/catch_lazy_expr.cpp",
103+
"internal/catch_leak_detector.cpp",
104+
"internal/catch_list.cpp",
105+
"internal/catch_message_info.cpp",
106+
"internal/catch_output_redirect.cpp",
107+
"internal/catch_parse_numbers.cpp",
108+
"internal/catch_polyfills.cpp",
109+
"internal/catch_random_number_generator.cpp",
110+
"internal/catch_random_seed_generation.cpp",
111+
"internal/catch_reporter_registry.cpp",
112+
"internal/catch_reporter_spec_parser.cpp",
113+
"internal/catch_reusable_string_stream.cpp",
114+
"internal/catch_run_context.cpp",
115+
"internal/catch_section.cpp",
116+
"internal/catch_singletons.cpp",
117+
"internal/catch_source_line_info.cpp",
118+
"internal/catch_startup_exception_registry.cpp",
119+
"internal/catch_stdstreams.cpp",
120+
"internal/catch_string_manip.cpp",
121+
"internal/catch_stringref.cpp",
122+
"internal/catch_tag_alias_registry.cpp",
123+
"internal/catch_test_case_info_hasher.cpp",
124+
"internal/catch_test_case_registry_impl.cpp",
125+
"internal/catch_test_case_tracker.cpp",
126+
"internal/catch_test_failure_exception.cpp",
127+
"internal/catch_test_registry.cpp",
128+
"internal/catch_test_spec_parser.cpp",
129+
"internal/catch_textflow.cpp",
130+
"internal/catch_uncaught_exceptions.cpp",
131+
"internal/catch_wildcard_pattern.cpp",
132+
"internal/catch_xmlwriter.cpp",
133+
134+
"interfaces/catch_interfaces_capture.cpp",
135+
"interfaces/catch_interfaces_config.cpp",
136+
"interfaces/catch_interfaces_exception.cpp",
137+
"interfaces/catch_interfaces_generatortracker.cpp",
138+
"interfaces/catch_interfaces_registry_hub.cpp",
139+
"interfaces/catch_interfaces_reporter.cpp",
140+
"interfaces/catch_interfaces_reporter_factory.cpp",
141+
"interfaces/catch_interfaces_testcase.cpp",
142+
143+
"generators/catch_generator_exception.cpp",
144+
"generators/catch_generators.cpp",
145+
"generators/catch_generators_random.cpp",
146+
147+
"matchers/catch_matchers.cpp",
148+
"matchers/catch_matchers_container_properties.cpp",
149+
"matchers/catch_matchers_exception.cpp",
150+
"matchers/catch_matchers_floating_point.cpp",
151+
"matchers/catch_matchers_predicate.cpp",
152+
"matchers/catch_matchers_quantifiers.cpp",
153+
"matchers/catch_matchers_string.cpp",
154+
"matchers/catch_matchers_templated.cpp",
155+
"matchers/internal/catch_matchers_impl.cpp",
156+
157+
"reporters/catch_reporter_automake.cpp",
158+
"reporters/catch_reporter_common_base.cpp",
159+
"reporters/catch_reporter_compact.cpp",
160+
"reporters/catch_reporter_console.cpp",
161+
"reporters/catch_reporter_cumulative_base.cpp",
162+
"reporters/catch_reporter_event_listener.cpp",
163+
"reporters/catch_reporter_helpers.cpp",
164+
"reporters/catch_reporter_json.cpp",
165+
"reporters/catch_reporter_junit.cpp",
166+
"reporters/catch_reporter_multi.cpp",
167+
"reporters/catch_reporter_registrars.cpp",
168+
"reporters/catch_reporter_sonarqube.cpp",
169+
"reporters/catch_reporter_streaming_base.cpp",
170+
"reporters/catch_reporter_tap.cpp",
171+
"reporters/catch_reporter_teamcity.cpp",
172+
"reporters/catch_reporter_xml.cpp",
173+
};

build.zig.zon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.{
2+
.name = "catch2",
3+
.version = "3.7.1",
4+
.minimum_zig_version = "0.12.0",
5+
.dependencies = .{
6+
.upstream = .{
7+
.url = "git+https://github.com/catchorg/Catch2?ref=v3.7.1#fa43b77429ba76c462b1898d6cd2f2d7a9416b14",
8+
.hash = "12203b77f3dc2161e6074743f5c9e7bcca49016380317e83bbc14ec293d80d9bb8fe",
9+
},
10+
},
11+
.paths = .{
12+
"build.zig",
13+
"build.zig.zon",
14+
"LICENSE",
15+
"README.md",
16+
},
17+
}

0 commit comments

Comments
 (0)