Evan La Fontaine
Evan La Fontaine

Reputation: 35

CMake does not compile files with non-standard extensions

I have a project which have custom scripts which auto-generate C++ code files with nonstandard extensions (.acpp and .ah for generated source files and headers respectively). However, this code is not compiled as I get linker errors when compiling which disappear when renaming the files from .acpp to .cpp.

set(HEADER_FILES
    normal.h
    foo.ah
)


set(SOURCE_FILES
    normal.cpp
    foo.acpp
)

add_library(lib STATIC ${SOURCE_FILES} ${HEADER_FILES})

In the above case, only normal.cpp is compiled and if it calls functions defined in foo.acpp there would be linker errors.

I have attempted to use:

And have looked at these related questions:

Upvotes: 0

Views: 582

Answers (1)

Connor Fuhrman
Connor Fuhrman

Reputation: 831

Using CMake 3.22.0 set_source_files_properties(file.nonstandard_extention PROPERTIES LANGUAGE C) or LANGUAGE CXX worked to treat a file as either C or C++. Testing on MacOS AppleClang 13.0. See CMake docs here.

Upvotes: 1

Related Questions