in our project, we have a few
.S assembly files which up to now were treated like regular C files (i.e. they were compiled with the same compiler + flags/options as C files). This was achieved by
set_source_files_properties(file1.S file2.S PROPERTIES LANGUAGE C) before
add_library(foo some.c other.c file1.S file2.S etc.c).
As long as project stated
cmake_minimum_required(VERSION 3.17), everything was fine with CMake in version 3.21.3. However, the very same CMake adds
-x c to the compile flags when the project uses
cmake_minimum_required(VERSION 3.20); in consequence,
gcc reports problems with the assembly file.
What is the correct way to tell CMake that the
.S files are to be compiled in the same way as C language files (i.e. without adding
From your description, I suppose that your files are not C source but assembly with pre-processing.
So, it is, anyway, an error to specify
C as language when the files do not contained
Maybe this discussion can be of some help.
@marc.chevrier, I admit that declaring the assembler files C language is kind of wrong. However, up to somwhere between
cmake_minimum_required(VERSION 3.17) and
... 3.20), this was a successful workaround without having cumbersome constructs like
Isn’t there some official way to tell CMake “please treat this
.S source file in exactly the same way as you would usually do with
.c files even if it is no C language file”?
Possibly, specify your
C compiler as
env ASM=gcc cmake ...
And do not specify any
LANGUAGE for your assembly files.
For the record, I just found the comments on the
LANGUAGE property in the context of
set_source_files_properties(file1.S file2.c PROPERTIES LANGUAGE C) and instead declaring
enable_language(ASM) solved my problem. Thanks for your support.