VS: ASM_NASM adding incompatible (MSVC) target_compile_options() to the NASM.exe command
Starting with CMake 3.26, a change was made for ASM_NASM to honor compile_options
(24bcad5b) in VS generators. From my understanding, this was made to be aligned with Makefiles and Ninja (i.e. more like Unix platforms), and while NASM reject unrecognized arguments starting with -
, it does not handle well MSVC ones (starting with /
).
I have an OpenSSL build using CMake (and NASM -- using
enable_language
) with Visual Studio, and the consuming project basically sets/W0
on it to disable warnings only for this dependency. Migrating from CMake 3.22 to 3.28, now,/W0
ends up on the NASM command, and NASM treats it was an input file, so it fails saying that two inputs were provided.This is an excerpt of the command:
"nasm.exe" -o "x86_64cpuid.obj" -fwin64 -I"openssl\include" -D"OPENSSL_SYS_WIN32" /W0 -fwin64 "x86_64cpuid.s"
Not too sure about the best solution.
As pointed out by Brad King (#24289 (comment 1299718)), the original code "[..] might have been left out to avoid conflicting with C-specific flags.". And indeed, the assembler may have the same flags and people will often attach flags without specifying the language (here, the test for the commit specify ASM_NASM language). At the same time, consistency across generators is desirable, so reverting the patch is not better either.
Maybe there should be a CMAKE_ASM_NASM_FLAG_REGEX
defined to only take arguments starting with -
, as the others are/won't be recognized by NASM?