Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: disable min() and max() macros in windows.h #2455

Merged
merged 1 commit into from
May 28, 2024

Conversation

hundeboll
Copy link
Contributor

Using std::min() and/or std::max() in sources where windows.h has been include fails with

error C2589: '(': illegal token on right side of '::' [D:\a\ninja\ninja\build\libninja.vcxproj]
error C2062: type 'unknown-type' unexpected [D:\a\ninja\ninja\build\libninja.vcxproj]
error C2059: syntax error: ')' [D:\a\ninja\ninja\build\libninja.vcxproj]
error C2589: '(': illegal token on right side of '::' [D:\a\ninja\ninja\build\libninja.vcxproj]
error C2059: syntax error: ')' [D:\a\ninja\ninja\build\libninja.vcxproj]

Avoid this by defining NOMINMAX for windows builds, which causes the windows.h header to skip defining those two macros.

CMakeLists.txt Outdated Show resolved Hide resolved
@jhasse
Copy link
Collaborator

jhasse commented May 27, 2024

New in version 3.26: Any leading -D on an item will be removed.

https://cmake.org/cmake/help/latest/command/add_compile_definitions.html

If I interpret this correctly this will therefore break with CMake < 3.26. Can you remove the leading -D?

@jhasse jhasse added the windows label May 27, 2024
@hundeboll
Copy link
Contributor Author

New in version 3.26: Any leading -D on an item will be removed.

https://cmake.org/cmake/help/latest/command/add_compile_definitions.html

If I interpret this correctly this will therefore break with CMake < 3.26. Can you remove the leading -D?

Done

Using std::min() and/or std::max() in sources where windows.h has been
include fails with

    error C2589: '(': illegal token on right side of '::' [D:\a\ninja\ninja\build\libninja.vcxproj]
    error C2062: type 'unknown-type' unexpected [D:\a\ninja\ninja\build\libninja.vcxproj]
    error C2059: syntax error: ')' [D:\a\ninja\ninja\build\libninja.vcxproj]
    error C2589: '(': illegal token on right side of '::' [D:\a\ninja\ninja\build\libninja.vcxproj]
    error C2059: syntax error: ')' [D:\a\ninja\ninja\build\libninja.vcxproj]

Avoid this by defining NOMINMAX for windows builds, which causes the
windows.h header to skip defining those two macros.
@jhasse jhasse merged commit 8aa51b2 into ninja-build:master May 28, 2024
11 checks passed
@jhasse
Copy link
Collaborator

jhasse commented May 28, 2024

Thanks.

Windows sucks.

@hundeboll hundeboll deleted the nominmax branch May 28, 2024 19:55
@jhasse jhasse added this to the 1.13.0 milestone Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants