Skip to content

add_compile_options get passed to assembler

I have a project with a mix of C and assembly, but the compiler options I'm setting are being incorrectly passed to the assembler, resulting in warnings about unrecognized options.

Here's a small example using Visual C++ compilers with the /W4 option to increase warning levels:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.19)
project(test LANGUAGES C)
enable_language(ASM_MASM)
if(MSVC)
    add_compile_options(/W4) # Increase warning level
endif()
add_executable(test_project test.c test.asm)
/* test.c */
int asm_func(void);
int main() { return asm_func(); }
; test.asm
.model flat
.code
asm_func proto c
asm_func proc c
    ret 0
asm_func endp
end

Build instructions:

$ mkdir build && cd build
$ cmake -G Ninja ..
-- The C compiler identification is MSVC 19.28.29336.0
...
-- The ASM_MASM compiler identification is MSVC
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29333/bin/Hostx86/x86/ml.exe
$ cmake --build .
...
MASM : warning A4008:invalid command-line option value, default is used : /W
...
  • Cmake version: 3.19.3
  • Ninja version: 1.10.2
  • Masm version: 14.28.29336.0
Edited by Chris Waddell
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information