Assembly files are not processed at all

Hi guys,

This one below works with Ninja / Linux but on windows / VS2019 it does not.
Here is a simple CMakeList.txt with hello.cpp and file.asm sources:

cmake_minimum_required (VERSION 3.19)
enable_language(CXX C ASM)
add_executable(hello hello.cpp  file.asm)
set_property(SOURCE file.asm PROPERTY LANGUAGE ASM)

The build completes with zero error but file.asm is not addressed at all, i.e. file.obj is not generated by any command. The link command includes only hello.obj.
Some remarks:

  1. commenting the set_property above gives the same result
  2. setting CMAKE_ASM_COMPILER to ml64 assembly tool gives the same result
  3. Adding: set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> /nologo /c /Fo ") does not change a thing
  4. A weird thing is that $<TARGET_OBJECTS:hello> includes file.obj…

That seems to be such a simple case, I am wondering what is missing.

Thanks,
Serge

You’re missing a call to project(), which should come right after cmake_minimum_required() in your example code. You can replace your call to enable_language() with the following:

project(MyExample LANGUAGES C CXX ASM)

I can’t say for sure if that’s the cause of your problem, but see how you go. You shouldn’t need the call to set_property() either.

I don’t know how up-to-date it is, but you might also find some useful details in the following wiki article:

https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/languages/Assembler

Thanks Craig for your answer.

Indeed having project seems to cause CMake to handle the assembly file.
Although it is not clear how this can be related and why Linux does not need it.

In addition, adding enable_language(ASM_MASM) (without the project sentence) also causes CMake to handle the assembly file.

Well, those workarounds work and let us proceed but it is confusing and difficult to figure out the engine behind.

Thanks anyway for your help,
Serge