Building Lib file from asm - cmake bug?

Hello!

I’m trying to convert a larger project to cmake. It consists or various C and ASM files.
I was trying to create a static library containing the functions provided by the ASM files and then linking this static lib with the C files. But I ran into a strange error:

Microsoft (R) Library Manager Version 14.16.27043.0
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : fatal error LNK1181: cannot open input file ‘cr’

OS: Win10, Build tools: VS 2017, Generator: NMAKE, platform: x64. Cmake version: 3.18.2

I tried this with a minimal example and got the same error:

cmake_minimum_required(VERSION 3.10)
# set the project name
project(LibTest)
enable_language(ASM_MASM)
set(SOURCES_ASM test.asm)
set_source_files_properties(${SOURCES_ASM} PROPERTY LANGUAGE ASM_MASM)
ADD_LIBRARY(LibAsm STATIC ${SOURCES_ASM})

When examining the “build.make” file being generated, I found this:

C:\PROGRA~2.…\Hostx64\x64\lib.exe cr LibAsm.lib /machine:x64 $(LibAsm_OBJECTS) $(LibAsm_EXTERNAL_OBJECTS)

Is there a problem with my Cmake file? Is this a bug? Any hints, how to avoid that?

Any help is appreciated. Thanks

EDIT:

  • with ninja generator the same error of the lib tool appears
  • a similar small example with a C file works fine

After some research it seems, it is actually a bug in cmake:

https://gitlab.kitware.com/cmake/cmake/-/issues/18889

Adding this to the project file causes the error to disappear:

set(CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> /OUT:<TARGET> <LINK_FLAGS> <OBJECTS>")
1 Like

@brad.king Seems like an env-regression?

I’ve already responded in the corresponding issue to suggest a path forward.