diff --git a/cmake/AddCustomCommandOrTest.cmake b/cmake/AddCustomCommandOrTest.cmake index e3f6e8bf..467b7a85 100644 --- a/cmake/AddCustomCommandOrTest.cmake +++ b/cmake/AddCustomCommandOrTest.cmake @@ -11,7 +11,6 @@ function(ut_add_custom_command_or_test) include(CMakeParseArguments) cmake_parse_arguments("${prefix}" "${noValues}" "${singleValues}" "${multiValues}" ${ARGN}) target_link_libraries(${PARSE_TARGET} PRIVATE Boost::ut) - target_compile_definitions(${PARSE_TARGET} PRIVATE NOMINMAX) if(BOOST_UT_ENABLE_RUN_AFTER_BUILD) add_custom_command(TARGET ${PARSE_TARGET} COMMAND ${PARSE_COMMAND}) diff --git a/include/boost/ut.hpp b/include/boost/ut.hpp index 78a2a822..d68161ac 100644 --- a/include/boost/ut.hpp +++ b/include/boost/ut.hpp @@ -19,6 +19,12 @@ export import std; #endif #include +#if defined(_MSC_VER) + #pragma push_macro("min") + #pragma push_macro("max") + #undef min + #undef max +#endif // Before libc++ 17 had experimental support for format and it required a // special build flag. Currently libc++ has not implemented all C++20 chrono // improvements. Therefore doesn't define __cpp_lib_format, instead query the @@ -3283,4 +3289,9 @@ __attribute__((constructor)) inline void cmd_line_args(int argc, // For MSVC, largc/largv are initialized with __argc/__argv #endif +#if defined(_MSC_VER) + #pragma pop_macro("min") + #pragma pop_macro("max") +#endif + #endif diff --git a/test/ut/win_compat_test.cpp b/test/ut/win_compat_test.cpp index f9544dd4..bcecf511 100644 --- a/test/ut/win_compat_test.cpp +++ b/test/ut/win_compat_test.cpp @@ -7,12 +7,18 @@ // // ensure no conflict between `Windows.h` and `ut.hpp` -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX #include +#if not defined(min) || not defined(max) +#error 'min' and 'max' should be defined +#endif + #include "boost/ut.hpp" +#if not defined(min) || not defined(max) +#error 'min' and 'max' should still be defined +#endif + namespace ut = boost::ut; int main() {