Reputation: 35
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:
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS acpp)
SET_SOURCE_FILES_PROPERTIES(${SOURCE_FILES} PROPERTIES LANGUAGE CXX)
add_definitions("-x c++")
set_target_properties(lib PROPERTIES LINKER_LANGUAGE CXX)
And have looked at these related questions:
Upvotes: 0
Views: 582
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