0

When trying to assemble a MASM project using cmake version 3.24.3, the target_compile_options() below

if(WIN32)
target_compile_options(HelloWorld
    PUBLIC
        /DBUILD_HelloWorld
        /FlHelloWorld.lst
)
target_link_options(HelloWorld
    PUBLIC
        /SUBSYSTEM:Console,6.01
        /SAFESEH:NO
)
...

are not added to the MASM command

[Build:x86] ml.exe /c /nologo /Zi /Fo"HelloWorld.dir\Debug\CodeBaseEND.obj" /D"CMAKE_INTDIR="Debug"" ...

However, during the linking phase, the target_link_options() are added

[Build:x86] C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x86\link.exe /ERRORREPORT:QUEUE ... /SAFESEH:NO /SUBSYSTEM:Console,6.01

The root CMakeLists.txt file has these languages defined

project(HelloWorld VERSION 1.0.0 LANGUAGES C CXX ASM_MASM)

Any ideas why the compile options are omitted or where the fix might be?

EDIT

Seems related to CMake not adding preprocessor definitions for ASM_MASM

vengy
  • 1,548
  • 10
  • 18

1 Answers1

0

Got it working using set_source_files_properties

set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/asm/helloWorld.asm PROPERTIES COMPILE_FLAGS "/DBUILD_HelloWorld /FlHelloWorld.lst")   

The options were correctly added

[Build:x86] ml.exe /c /nologo /Zi /Fo"HelloWorld.dir\Debug\helloWorld.obj" /D"CMAKE_INTDIR="Debug"" /D"BUILD_HelloWorld" /Fl"HelloWorld.lst" ...

To apply to multiple unique asm files

foreach(FILE {PROJECT_SOURCES})
    get_filename_component(FILENAMEONLY ${FILE} NAME_WLE)
    set_source_files_properties(${FILE} PROPERTIES COMPILE_FLAGS "/Fl${FILENAMEONLY}.lst /DBUILD_{BINARY_NAME}")
endforeach()

Still not sure why target_compile_options does not work?

target_compile_options(HelloWorld
    PUBLIC
        /DBUILD_HelloWorld
        /FlHelloWorld.lst
)

Submitted a bug report to CMAKE: https://gitlab.kitware.com/cmake/cmake/-/issues/24289

vengy
  • 1,548
  • 10
  • 18