Skip to content

Commit

Permalink
cmake: disable min() and max() macros in windows.h
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hundeboll committed May 27, 2024
1 parent ee43260 commit 25982cb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ if(WIN32)
# so that build environments which lack a C compiler, but have a C++
# compiler may build ninja.
set_source_files_properties(src/getopt.c PROPERTIES LANGUAGE CXX)

# windows.h defines min() and max() which conflict with std::min()
# and std::max(), which both might be used in sources. Avoid compile
# errors by telling windows.h to not define those two.
add_compile_definitions(-DNOMINMAX)
else()
target_sources(libninja PRIVATE src/subprocess-posix.cc)
if(CMAKE_SYSTEM_NAME STREQUAL "OS400" OR CMAKE_SYSTEM_NAME STREQUAL "AIX")
Expand Down

0 comments on commit 25982cb

Please sign in to comment.