File tree Expand file tree Collapse file tree 6 files changed +59
-3
lines changed Expand file tree Collapse file tree 6 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ function(fetch_catch2)
30
30
string (REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " )
31
31
string (REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
32
32
33
+ # Ensure consistent default calling convention with test executables.
34
+ if (MSVC )
35
+ string (APPEND CMAKE_CXX_FLAGS " /Gv" )
36
+ endif ()
37
+
33
38
FetchContent_MakeAvailable (EP_Catch2 )
34
39
35
40
# Avoid building unnecessary targets. Use FetchContent_Declare(EXCLUDE_FROM_ALL) in CMake 3.28 and newer.
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ function(add_examples_executable source)
75
75
RUNTIME_OUTPUT_DIRECTORY ${subdir}
76
76
)
77
77
78
- # Deliberately use `__vectorcall` by default with MSVC to catch missing `__cdecl`.
78
+ # Use `__vectorcall` by default with MSVC to catch missing `__cdecl`.
79
79
target_compile_options (${target_name} PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/Gv>" )
80
80
81
81
# Keep build and run targets completely separate.
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ add_executable(test_bson
36
36
bson_util_itoa.cpp
37
37
bson_validate.cpp
38
38
bson_value.cpp
39
+ catch.cpp
39
40
exception_guard.cpp
40
41
json.cpp
41
42
oid.cpp
@@ -62,11 +63,14 @@ target_include_directories(bsoncxx_test_properties INTERFACE
62
63
${CMAKE_CURRENT_SOURCE_DIR} /../..
63
64
)
64
65
target_compile_definitions (bsoncxx_test_properties INTERFACE ${libbson_definitions} )
66
+ # Use `__vectorcall` by default with MSVC to catch missing `__cdecl`.
67
+ target_compile_options (bsoncxx_test_properties INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:/Gv>" )
65
68
add_library (bsoncxx::test_properties ALIAS bsoncxx_test_properties )
66
69
67
70
# Avoid redundant recompilation of catch/main.cpp.
68
71
add_library (bsoncxx_test_properties_with_main INTERFACE )
69
- target_link_libraries (bsoncxx_test_properties_with_main INTERFACE bsoncxx::test_properties Catch2::Catch2WithMain )
72
+ target_link_libraries (bsoncxx_test_properties_with_main INTERFACE bsoncxx::test_properties )
73
+ target_sources (bsoncxx_test_properties INTERFACE catch.cpp )
70
74
add_library (bsoncxx::test_properties_with_main ALIAS bsoncxx_test_properties_with_main )
71
75
72
76
target_link_libraries (test_bson PRIVATE bsoncxx::test_properties_with_main )
@@ -158,6 +162,7 @@ set_dist_list(src_bsoncxx_test_DIST
158
162
bson_util_itoa.cpp
159
163
bson_validate.cpp
160
164
bson_value.cpp
165
+ catch.cpp
161
166
catch.hh
162
167
exception_guard.cpp
163
168
exception_guard.hh
Original file line number Diff line number Diff line change
1
+ // Copyright 2009-present MongoDB, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include < bsoncxx/config/prelude.hpp>
16
+
17
+ #include < catch2/catch_session.hpp>
18
+
19
+ int BSONCXX_ABI_CDECL main (int argc, char * argv[]) {
20
+ return Catch::Session ().run (argc, argv);
21
+ }
Original file line number Diff line number Diff line change @@ -157,10 +157,13 @@ target_include_directories(mongocxx_test_properties INTERFACE
157
157
# Allow `#include <mongocxx/test/...>`.
158
158
${CMAKE_CURRENT_SOURCE_DIR} /../..
159
159
)
160
+ # Use `__vectorcall` by default with MSVC to catch missing `__cdecl`.
161
+ target_compile_options (mongocxx_test_properties INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:/Gv>" )
160
162
add_library (mongocxx::test_properties ALIAS mongocxx_test_properties )
161
163
162
164
add_library (mongocxx_test_properties_with_main INTERFACE )
163
- target_link_libraries (mongocxx_test_properties_with_main INTERFACE mongocxx::test_properties Catch2::Catch2WithMain )
165
+ target_link_libraries (mongocxx_test_properties_with_main INTERFACE mongocxx::test_properties )
166
+ target_sources (mongocxx_test_properties_with_main INTERFACE catch.cpp )
164
167
add_library (mongocxx::test_properties_with_main ALIAS mongocxx_test_properties_with_main )
165
168
166
169
set_property (
@@ -335,6 +338,7 @@ set_dist_list(src_mongocxx_test_DIST
335
338
bulk_write.cpp
336
339
catch_helpers.cpp
337
340
catch_helpers.hh
341
+ catch.cpp
338
342
change_streams.cpp
339
343
client_helpers.cpp
340
344
client_helpers.hh
Original file line number Diff line number Diff line change
1
+ // Copyright 2009-present MongoDB, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #include < mongocxx/config/prelude.hpp>
16
+
17
+ #include < catch2/catch_session.hpp>
18
+
19
+ int MONGOCXX_ABI_CDECL main (int argc, char * argv[]) {
20
+ return Catch::Session ().run (argc, argv);
21
+ }
You can’t perform that action at this time.
0 commit comments