context icon indicating copy to clipboard operation
context copied to clipboard

MASM : fatal error A1013:invalid numerical command-line argument : /W

Open marakew opened this issue 10 months ago • 24 comments

https://github.com/boostorg/context/blob/afd2ce33722e223d75723f3b44dc9fa94302e764/CMakeLists.txt#L192-L193

i use clan-cl as CMAKE_CXX_COMPILER_ID but masm is ml64.exe

[1/198] D:\PROGRA~1\MICROS~1\2019\ENTERP~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\ml64.exe -DBOOST_CLANG=1 -DBOOST_CONTEXT_EXPORT="" -DBOOST_CONTEXT_NO_LIB="" -DBOOST_CONTEXT_SOURCE="" -DBOOST_CONTEXT_STATIC_LINK="" -D_CRT_SECURE_NO_WARNINGS -ID:\git\boost_\libs\context\include -ID:\git\boost_\libs\assert\include -ID:\git\boost_\libs\config\include -ID:\git\boost_\libs\core\include -ID:\git\boost_\libs\static_assert\include -ID:\git\boost_\libs\throw_exception\include -ID:\git\boost_\libs\mp11\include -ID:\git\boost_\libs\pool\include -ID:\git\boost_\libs\integer\include -ID:\git\boost_\libs\type_traits\include -ID:\git\boost_\libs\winapi\include -ID:\git\boost_\libs\predef\include -ID:\git\boost_\libs\smart_ptr\include -I"D:\Program Files (x86)\Microsoft Visual Studio\2019\EnterprisePreview\VC\Tools\MSVC\14.29.30133\include" -I"D:\Program Files (x86)\Microsoft Visual Studio\2019\EnterprisePreview\VC\Tools\MSVC\14.29.30133\atlmfc\include" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt" /nologo /quiet -Wno-unused-command-line-argument -c -Fo boost\libs\context\CMakeFiles\boost_context.dir\src\asm\jump_x86_64_ms_pe_masm.asm.obj D:\git\boost_\libs\context\src\asm\jump_x86_64_ms_pe_masm.asm
FAILED: boost/libs/context/CMakeFiles/boost_context.dir/src/asm/jump_x86_64_ms_pe_masm.asm.obj 
D:\PROGRA~1\MICROS~1\2019\ENTERP~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\ml64.exe -DBOOST_CLANG=1 -DBOOST_CONTEXT_EXPORT="" -DBOOST_CONTEXT_NO_LIB="" -DBOOST_CONTEXT_SOURCE="" -DBOOST_CONTEXT_STATIC_LINK="" -D_CRT_SECURE_NO_WARNINGS -ID:\git\boost_\libs\context\include -ID:\git\boost_\libs\assert\include -ID:\git\boost_\libs\config\include -ID:\git\boost_\libs\core\include -ID:\git\boost_\libs\static_assert\include -ID:\git\boost_\libs\throw_exception\include -ID:\git\boost_\libs\mp11\include -ID:\git\boost_\libs\pool\include -ID:\git\boost_\libs\integer\include -ID:\git\boost_\libs\type_traits\include -ID:\git\boost_\libs\winapi\include -ID:\git\boost_\libs\predef\include -ID:\git\boost_\libs\smart_ptr\include -I"D:\Program Files (x86)\Microsoft Visual Studio\2019\EnterprisePreview\VC\Tools\MSVC\14.29.30133\include" -I"D:\Program Files (x86)\Microsoft Visual Studio\2019\EnterprisePreview\VC\Tools\MSVC\14.29.30133\atlmfc\include" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um" -I"D:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt" /nologo /quiet -Wno-unused-command-line-argument -c -Fo boost\libs\context\CMakeFiles\boost_context.dir\src\asm\jump_x86_64_ms_pe_masm.asm.obj D:\git\boost_\libs\context\src\asm\jump_x86_64_ms_pe_masm.asm
Microsoft (R) Macro Assembler (x64) Version 14.29.30154.0

Copyright (C) Microsoft Corporation.  All rights reserved.



MASM : warning A4018:invalid command-line option : /quiet

MASM : fatal error A1013:invalid numerical command-line argument : /W

marakew avatar Feb 21 '25 19:02 marakew

Looks like we need CMAKE_<LANG>_SIMULATE_ID and/or CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT to detect clang-cl (MSVC) and not to pass -Wno-unused-command-line-argument https://discourse.cmake.org/t/how-to-determine-if-clang-or-clang-cl-is-used-on-windows/4129

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND (NOT (CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")))

But why /quiet is not working!?

if(MSVC AND NOT(MSVC_VERSION LESS 1936)) # Visual Studio 2022 version 17.6
      set_property(SOURCE ${ASM_SOURCES} APPEND PROPERTY COMPILE_OPTIONS "/quiet")

can you change 1936 -> 1937 and check it?

Challanger524 avatar Feb 22 '25 00:02 Challanger524

1937 works and check simulate_id works

but i dont like your logic your check cxx compiler but set options for asm files

marakew avatar Feb 22 '25 08:02 marakew

maybe set(BOOST_CONTEXT_ASSEMBLER "${_default_asm}".. should be used then!?

Challanger524 avatar Feb 22 '25 09:02 Challanger524

but i dont like your logic, your check cxx compiler, but set options for asm files

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set_property(SOURCE ${ASM_SOURCES} APPEND PROPERTY COMPILE_OPTIONS "-Wno-unused-command-line-argument")

was added (by me) in the same manner as

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set_property(SOURCE ${ASM_SOURCES} APPEND PROPERTY COMPILE_OPTIONS "-x" "assembler-with-cpp")

that was existed before me.

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") should then be (I suppose) elseif(BOOST_CONTEXT_ARCHITECTURE STREQUAL "armclang")

Challanger524 avatar Feb 22 '25 10:02 Challanger524

Managed to setup Clang-CL in VS Code and reproduce the issue, will fix soonely.

@marakew how did you setup your clang-cl? vcvarsall.bat does not setup mt.exe path so it fails with MT: command "CMAKE_MT-NOTFOUND ... and vscode cmake-tools failed with lld-link: error: <root>: undefined symbol: mainCRTStartup without "cmake.useVsDeveloperEnvironment": "always"

Challanger524 avatar Feb 22 '25 13:02 Challanger524

1937 works

A bit unclear what you mean by "works". You want to say that your message(STATUS "MSVC_VERSION: ${MSVC_VERSION}") is exactly 1936 but MASM fails to understand /quiet? I had concern coz author of this option stated 17.7 here, but doc says 17.6:

Concern It is better to check if we can pass /quiet on any 17.6 patch version, or better to set 1937 to be 100% sure that it works.

Challanger524 avatar Feb 22 '25 15:02 Challanger524

i have own toolchain and build cmd

I am doing it with as least amount of custom setups as possible, like: CMakePresets.json:

    {
      "name": "base",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir":  "${sourceDir}/out/build/${presetName}",
      "installDir": "${sourceDir}/out/install/${presetName}",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "MinSizeRel",
      }
    },
    {
      "name": "clang-cl-dbg",
      "displayName": "Clang-CL - debug",
      "inherits": "base",
      "architecture": { "strategy": "external", "value":      "x64" },
      "toolset":      { "strategy": "external", "value": "host=x64" },
      "cacheVariables": {
        "CMAKE_C_COMPILER"  : "clang-cl",
        "CMAKE_CXX_COMPILER": "clang-cl",
        "CMAKE_BUILD_TYPE": "Debug"
      }
    },
set(BOOST_SOURCE_DIR_ "${CMAKE_SOURCE_DIR}/../boost")
set(BOOST_INCLUDE_LIBRARIES beast)
add_subdirectory("${BOOST_SOURCE_DIR_}" "${CMAKE_CURRENT_BINARY_DIR}/dep/boost" EXCLUDE_FROM_ALL)
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::beast)
if (MINGW)
  target_link_libraries(boost_asio INTERFACE ws2_32)
endif()

Challanger524 avatar Feb 22 '25 15:02 Challanger524

-- MSVC_VERSION: 1936 when i set 1937 is works without /quiet

this is VS 2019

D:\…sePreview\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64>ml64.exe /?
Microsoft (R) Macro Assembler (x64) Version 14.29.30154.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        ML64 [ /options ] filelist [ /link linkoptions ]

/Bl<linker> Use alternate linker          /Sf Generate first pass listing
/c Assemble without linking               /Sl<width> Set line width
/Cp Preserve case of user identifiers     /Sn Suppress symbol-table listing
/Cx Preserve case in publics, externs     /Sp<length> Set page length
/D<name>[=text] Define text macro         /Ss<string> Set subtitle
/EP Output preprocessed listing to stdout /St<string> Set title
/F <hex> Set stack size (bytes)           /Sx List false conditionals
/Fe<file> Name executable                 /Ta<file> Assemble non-.ASM file
/Fl[file] Generate listing                /w Same as /W0 /WX
/Fm[file] Generate map                    /WX Treat warnings as errors
/Fo<file> Name object file                /W<number> Set warning level
/Fr[file] Generate limited browser info   /X Ignore INCLUDE environment path
/FR[file] Generate full browser info      /Zd Add line number debug info
/I<name> Add include path                 /Zf Make all symbols public
/link <linker options and libraries>      /Zi Add symbolic debug info
/nologo Suppress copyright message        /Zp[n] Set structure alignment
/Sa Maximize source listing               /Zs Perform syntax check only
/ZH:SHA_256 Use SHA256 for checksum
    in debug info (experimental)
/Gy[-] separate functions for linker
/errorReport:<option> Deprecated. Report internal assembler errors to Microsoft
    none - do not send report
    prompt - prompt to immediately send report
    queue - at next admin logon, prompt to send report
    send - send report automatically

VS about says this is Microsoft Visual Studio Enterprise 2019 Version 16.11.35

marakew avatar Feb 22 '25 15:02 marakew

It is super strange since NOT(MSVC_VERSION LESS 1936) should apply /quiet only for MSVC_VERSION >= 1936, but your Visual Studio is way older than 17.6 - "Microsoft Visual Studio Enterprise 2019 Version 16.11.35" Mine is: [cmake] -- MSVC_VERSION: 1939

PS ...\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\Hostx64\x64> .\ml64.exe /?
Microsoft (R) Macro Assembler (x64) Version 14.39.33523.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        ML64 [ /options ] filelist [ /link linkoptions ]

...
/ZH:SHA_256 Use SHA256 for checksum in debug info (default)
/Gy[-] separate functions for linker      /quiet Suppress 'Assembling' message <<<---------
...

Not sure what to do with 1936, probably will change it to 1937 and ask that guy from CMake forum about Visual Studio vs ML versioning vs Doc validity

Challanger524 avatar Feb 22 '25 16:02 Challanger524

VS 2022 LTS 17.6.14

D:\…sePreview\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64>ml64.exe /?
Microsoft (R) Macro Assembler (x64) Version 14.36.32545.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        ML64 [ /options ] filelist [ /link linkoptions ]

/Bl<linker> Use alternate linker          /Sf Generate first pass listing
/c Assemble without linking               /Sl<width> Set line width
/Cp Preserve case of user identifiers     /Sn Suppress symbol-table listing
/Cx Preserve case in publics, externs     /Sp<length> Set page length
/D<name>[=text] Define text macro         /Ss<string> Set subtitle
/EP Output preprocessed listing to stdout /St<string> Set title
/F <hex> Set stack size (bytes)           /Sx List false conditionals
/Fe<file> Name executable                 /Ta<file> Assemble non-.ASM file
/Fl[file] Generate listing                /w Same as /W0 /WX
/Fm[file] Generate map                    /WX Treat warnings as errors
/Fo<file> Name object file                /W<number> Set warning level
/Fr[file] Generate limited browser info   /X Ignore INCLUDE environment path
/FR[file] Generate full browser info      /Zd Add line number debug info
/I<name> Add include path                 /Zf Make all symbols public
/link <linker options and libraries>      /Zi Add symbolic debug info
/nologo Suppress copyright message        /Zp[n] Set structure alignment
/Sa Maximize source listing               /Zs Perform syntax check only
/ZH:MD5 Use MD5 for checksum in debug info
/ZH:SHA_256 Use SHA256 for checksum in debug info (default)
/Gy[-] separate functions for linker      /quiet Suppress 'Assembling' message
/errorReport:<option> Deprecated. Report internal assembler errors to Microsoft
    none - do not send report
    prompt - prompt to immediately send report
    queue - at next admin logon, prompt to send report
    send - send report automatically

marakew avatar Feb 22 '25 16:02 marakew

Not sure what to do with 1936, probably will change it to 1937 and ask that guy from CMake forum about Visual Studio vs ML versioning vs Doc validity

its depend how cmake detect version may be it read form windows reg installed VS != use VS

marakew avatar Feb 22 '25 17:02 marakew

Are you using VS Code? https://github.com/microsoft/vscode-cmake-tools/issues/1053

When I add 'VCToolsInstallDir' to MSVC_ENVIRONMENT_VARIABLES array in .vscode\extensions\ms-vscode.cmake-tools-1.3.0\dist\main.js(or src/kit.ts) of extension. and reconfigure my project. It works as expected. The cmake variable ${MSVC_VERSION} is correct.

Challanger524 avatar Feb 22 '25 17:02 Challanger524

No I don't use it

marakew avatar Feb 22 '25 17:02 marakew

At least /quiet flag gives warning and not an error, so in case of further incorrect CMake MSVC_VERSION detecting - it is not critical but probably should be discussed. @olk what you think?

Challanger524 avatar Feb 22 '25 17:02 Challanger524

D:\git\A_BUILD\cmake\Modules\Platform\Windows-Clang.cmake

if("${CMAKE_${lang}_SIMULATE_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
  math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
endif()

in general we can't rely on MSVC_VERSION when clang-cl is used

marakew avatar Feb 22 '25 17:02 marakew

Probably /quiet support for clang-cl should be dropped since we can't be sure about real MSVC_VERSION:

if(MSVC AND NOT(MSVC_VERSION LESS 1937) AND NOT(CMAKE_C_SIMULATE_VERSION) AND NOT(CMAKE_CXX_SIMULATE_VERSION))
  set_property(SOURCE ${ASM_SOURCES} APPEND PROPERTY COMPILE_OPTIONS "/quiet")

Challanger524 avatar Feb 22 '25 17:02 Challanger524

you didn't get me you can't rely on the MSVC_VERSION variable in setting the option for masm ml because I can, for example, change ml64 to a newer version so what? all your checks will go to waste

marakew avatar Feb 22 '25 18:02 marakew

in a special case I can not install VS at all and just pull a separate masm package from VS and use ml64 from there your checks will go to waste again

marakew avatar Feb 22 '25 18:02 marakew

[cmake] -- CMAKE_CXX_SIMULATE_VERSION: 19.39
[cmake] -- MSVC_VERSION: 1939

That's exactly why I want to drop it, in order to know for sure - assembler version is needed, but there no easy way to get it, only by executing <assembler> --version and parsing the output, which is unlikely will be accepted in PR.

Challanger524 avatar Feb 22 '25 18:02 Challanger524

@marakew can you tell (somewhere) your noreply GitHub email so I can add you as commit co-author? (not the private email) https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#required-co-author-information

Challanger524 avatar Feb 22 '25 18:02 Challanger524

Response (Y/n)? Keeping PR draft for a day more

Challanger524 avatar Feb 23 '25 13:02 Challanger524

no thanks

marakew avatar Feb 23 '25 13:02 marakew

@marakew found a way to load Visual Studio environment in CMake: https://github.com/Challanger524/test-boost-beast/blob/main/msvcToolchain.cmake

Challanger524 avatar Feb 24 '25 13:02 Challanger524

I don't look for ways to integrate VS I don't need it You probably forget that there are many scenarios when it is not necessary When using wine on Linux or any other OS Even a separate utility, be it cl or ml or rc, can be taken separately without using the entire toolchain or the entire VS

One way or another, I customize the entire scenario Since mine is very diverse

marakew avatar Feb 24 '25 13:02 marakew

PR #294 merged

olk avatar Apr 17 '25 04:04 olk