VS: ASM_MASM not fully implemented by Visual Studio generators
Trying to compile a .asm
file against MSVC 9.0. It's an older project that's locked to this toolchain. By design, this particular .asm
may only be compiled on x64 platforms.
Here is my minimal CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(TestMASM)
enable_language(ASM_MASM)
add_library(Common winos_x64.asm)
Make phase:
mkdir build
cd build
cmake -G "Visual Studio 9 2008" -A x64 ..\source
-- The C compiler identification is MSVC 15.0.21022.8
-- The CXX compiler identification is MSVC 15.0.21022.8
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM_MASM compiler identification is MSVC
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/ml64.exe
-- Configuring done
-- Generating done
-- Build files have been written to: xxx
It has correctly detected the ml64
ASM compiler. This is also verified in CMakeCache.txt
:
########################
# EXTERNAL cache entries
########################
//ASM_MASM compiler
CMAKE_ASM_MASM_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/ml64.exe
However, the build phase fails because the ml.exe
is somehow used in place of ml64.exe
.
Build Log
Build started: Project: Common, Configuration: Release|x64
Command Lines
Creating temporary file "xxx\Release\BAT00000144169512.bat" with contents
[
@echo off
ml.exe /c /nologo /Fo"\Release\winos_x64.obj" /D"CMAKE_INTDIR=\"Release\"" /W3 /Zi /errorReport:prompt /Ta..\source\winos_x64.asm
if errorlevel 1 goto VCReportError
goto VCEnd
:VCReportError
echo Project : error PRJ0019: A tool returned an error code from "Assembling..."
exit 1
:VCEnd
]
Creating command line "xxx\Release\BAT00000144169512.bat"
Output Window
Assembling...
Assembling: ..\source\winos_x64.asm
..\source\Common\winos_x64.asm(4) : error A2013:.MODEL must precede this directive
..\source\Common\winos_x64.asm(6) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(7) : error A2034:must be in segment block : cpuid64
..\source\Common\winos_x64.asm(10) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(11) : error A2008:syntax error : .
..\source\Common\winos_x64.asm(12) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(13) : error A2008:syntax error : .
..\source\Common\winos_x64.asm(14) : error A2008:syntax error : .
..\source\Common\winos_x64.asm(16) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(17) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(18) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(19) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(20) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(21) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(22) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(23) : error A2085:instruction or register not accepted in current CPU mode
..\source\Common\winos_x64.asm(25) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(26) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(28) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(29) : error A2034:must be in segment block
..\source\Common\winos_x64.asm(30) : fatal error A1010:unmatched block nesting : cpuid64
Project : error PRJ0019: A tool returned an error code from "Assembling..."
As you can see, the generated .BAT has elected to use ml.exe
instead of ml64.exe
. The CMake variables all align with a x64 configuration.
I've isolated problem to MSVC 9.0 (Visual Studio 2008) projects.
I generated solutions for the latest Visual Studio 2019 and it works correctly.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information