简体   繁体   English

CMake 不编译具有非标准扩展名的文件

[英]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).我有一个项目,其中包含自定义脚本,这些脚本自动生成带有非标准扩展名的 C++ 代码文件(分别用于生成的源文件和头文件为 .acpp 和 .ah)。 However, this code is not compiled as I get linker errors when compiling which disappear when renaming the files from .acpp to .cpp.但是,此代码未编译,因为编译时出现链接器错误,将文件从 .acpp 重命名为 .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.在上述情况下,只编译 normal.cpp,如果它调用 foo.acpp 中定义的函数,则会出现链接器错误。

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:并查看了这些相关问题:

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++.使用 CMake 3.22.0 set_source_files_properties(file.nonstandard_extention PROPERTIES LANGUAGE C)LANGUAGE CXX可以将文件视为 C 或 C++。 Testing on MacOS AppleClang 13.0.在 MacOS AppleClang 13.0 上测试。 See CMake docs here .请参阅此处的CMake 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM