Skip to content

Commit 93cfddb

Browse files
helmesjokris-jusiak
authored andcommitted
Don't define 'NOMINMAX' in CMake script, but instead make sure it works correctly with 'Windows.h'
1 parent 5fd8c5d commit 93cfddb

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

cmake/AddCustomCommandOrTest.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function(ut_add_custom_command_or_test)
1111
include(CMakeParseArguments)
1212
cmake_parse_arguments("${prefix}" "${noValues}" "${singleValues}" "${multiValues}" ${ARGN})
1313
target_link_libraries(${PARSE_TARGET} PRIVATE Boost::ut)
14-
target_compile_definitions(${PARSE_TARGET} PRIVATE NOMINMAX)
1514

1615
if(BOOST_UT_ENABLE_RUN_AFTER_BUILD)
1716
add_custom_command(TARGET ${PARSE_TARGET} COMMAND ${PARSE_COMMAND})

include/boost/ut.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export import std;
1919
#endif
2020

2121
#include <version>
22+
#if defined(_MSC_VER)
23+
#pragma push_macro("min")
24+
#pragma push_macro("max")
25+
#undef min
26+
#undef max
27+
#endif
2228
// Before libc++ 17 had experimental support for format and it required a
2329
// special build flag. Currently libc++ has not implemented all C++20 chrono
2430
// improvements. Therefore doesn't define __cpp_lib_format, instead query the
@@ -3283,4 +3289,9 @@ __attribute__((constructor)) inline void cmd_line_args(int argc,
32833289
// For MSVC, largc/largv are initialized with __argc/__argv
32843290
#endif
32853291

3292+
#if defined(_MSC_VER)
3293+
#pragma pop_macro("min")
3294+
#pragma pop_macro("max")
3295+
#endif
3296+
32863297
#endif

test/ut/win_compat_test.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
//
88

99
// ensure no conflict between `Windows.h` and `ut.hpp`
10-
#define WIN32_LEAN_AND_MEAN
11-
#define NOMINMAX
1210
#include <Windows.h>
1311

12+
#if not defined(min) || not defined(max)
13+
#error 'min' and 'max' should be defined
14+
#endif
15+
1416
#include "boost/ut.hpp"
1517

18+
#if not defined(min) || not defined(max)
19+
#error 'min' and 'max' should still be defined
20+
#endif
21+
1622
namespace ut = boost::ut;
1723

1824
int main() {

0 commit comments

Comments
 (0)