开发者

CMake automatically recognizing new file extensions

When I add source files to a target they are automatically recognized if the开发者_如何学Cy are from the C/C++ file extensions. What I want to accomplish is that if I put in the sources xxx.foo all the .foo files are processed with a predefined set of compiler commands.

I know that the way to go is using add_custom_command but all the examples I have seen are using fixed filenames like the ones used here http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F

Any ideas about the right approach to the problem?


One way to approach the problem is to replace the plain CMake add_executable and add_library commands with wrapper functions or macros which do special processing of the files with the .foo extension and pass the other arguments and options through to the standard add_executable or add_library commands. E.g.:

set (FOO_SRCS "main.cpp" "module.cpp" "xxx.foo" "yyy.foo")
foo_add_executable(fooexec ${FOO_SRCS})
foo_add_library(foolib ${FOO_SRCS})

The FindCUDA standard CMake module takes that approach. It adds CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY commands which feed source files with the extension .cu to the NVIDIA C compiler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜