ASM_MASM: Missing support for MSVC_DEBUG_INFORMATION_FORMAT
Repros with CMake 3.25.0 shipping in VS 2022 17.5 Preview 2.
In our project ([MSVC's STL](https://github.com/microsoft/STL)), we have ASM_MASM sources. When I tried to increase our minimum required version of CMake, it failed with:
```
CMake Error in CMakeLists.txt:
MSVC_DEBUG_INFORMATION_FORMAT value 'ProgramDatabase' not known for this
ASM_MASM compiler.
```
This is related to this new feature mentioned in the [CMake 3.25 release notes](https://cmake.org/cmake/help/latest/release/3.25.html):
> The [`CMAKE_MSVC_DEBUG_INFORMATION_FORMAT`](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_DEBUG_INFORMATION_FORMAT.html#variable:CMAKE_MSVC_DEBUG_INFORMATION_FORMAT) variable and [`MSVC_DEBUG_INFORMATION_FORMAT`](https://cmake.org/cmake/help/latest/prop_tgt/MSVC_DEBUG_INFORMATION_FORMAT.html#prop_tgt:MSVC_DEBUG_INFORMATION_FORMAT) target property were introduced to select the debug information format for compilers targeting the MSVC ABI. See policy [`CMP0141`](https://cmake.org/cmake/help/latest/policy/CMP0141.html#policy:CMP0141).
As the example below demonstrates, we can work around this by setting the `CMP0141` policy to `OLD`. However, I believe that this workaround should not be necessary, and that this is a bug in CMake - it appears that its internal machinery wasn't taught how to send debug info options to MASM.
While I am not a MASM expert, [MASM documentation](https://learn.microsoft.com/en-us/cpp/assembler/masm/ml-and-ml64-command-line-reference?view=msvc-170) says that `/Zi` "Generates CodeView information in object file.", and comments in MSVC's STL note that (somewhat confusingly) this is equivalent to what `/Z7` does for the `cl.exe` compiler - so `Embedded` in CMake's terminology should be translated to `/Zi` for MASM.
As linked from the release notes, CMake's documentation for [`CMAKE_MSVC_DEBUG_INFORMATION_FORMAT`](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_DEBUG_INFORMATION_FORMAT.html#variable:CMAKE_MSVC_DEBUG_INFORMATION_FORMAT) says:
> If this variable is not set, the `MSVC_DEBUG_INFORMATION_FORMAT` target property will not be set automatically. If that property is not set, CMake selects a debug information format using the default value `$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>`, if supported by the compiler, and otherwise `$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>`.
If I understand this correctly, because MASM doesn't support `ProgramDatabase`, CMake should fall back to `Embedded` instead of emitting an error that it doesn't know what to do.
```
C:\Temp\REPRO>"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.5.0-pre.2.0
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\Temp\REPRO>cmake --version
cmake version 3.25.0-msvc1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
C:\Temp\REPRO>type CMakeLists.txt
```
```cmake
cmake_minimum_required(VERSION 3.25)
if(DEFINED OVERRIDE_CMP0141)
cmake_policy(SET CMP0141 ${OVERRIDE_CMP0141})
endif()
project(meow_project LANGUAGES CXX ASM_MASM)
set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/meow.cpp
${CMAKE_CURRENT_LIST_DIR}/square.asm
)
add_executable(meow ${SOURCES})
```
```
C:\Temp\REPRO>type meow.cpp
```
```cpp
#include <cstdio>
extern "C" int square(int x);
int main() {
std::printf("\nHello, CMake world!\n");
std::printf("square(7): %d\n", square(7));
}
```
```
C:\Temp\REPRO>type square.asm
PUBLIC square
_TEXT SEGMENT
square PROC
imul ecx, ecx
mov eax, ecx
ret 0
square ENDP
_TEXT ENDS
END
C:\Temp\REPRO>cmake -G Ninja -S . -B out && ninja -C out && out\meow.exe
-- The CXX compiler identification is MSVC 19.35.32124.0
-- The ASM_MASM compiler identification is MSVC
-- Found assembler: C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32124/bin/Hostx64/x64/ml64.exe
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32124/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error in CMakeLists.txt:
MSVC_DEBUG_INFORMATION_FORMAT value 'ProgramDatabase' not known for this
ASM_MASM compiler.
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
C:\Temp\REPRO>cmake -G Ninja -S . -B out -DOVERRIDE_CMP0141=OLD && ninja -C out && out\meow.exe
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Temp/REPRO/out
ninja: Entering directory `out'
[1/3] Building ASM_MASM object CMakeFiles\meow.dir\square.asm.obj
Microsoft (R) Macro Assembler (x64) Version 14.35.32124.0
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: C:\Temp\REPRO\square.asm
[3/3] Linking CXX executable meow.exe
Hello, CMake world!
square(7): 49
```
Note: This seems to be similar to an old issue https://gitlab.kitware.com/cmake/cmake/-/issues/19453 but it is definitely not a duplicate of that issue.
issue