一旦定义,是否可以将其他源文件添加到可执行文件中? [英] Can one add further source files to an executable once defined?
本文介绍了一旦定义,是否可以将其他源文件添加到可执行文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于我已经在 CMakeList.txt
文件中定义了一个带有其主要源文件的可执行文件:
ADD_EXECUTABLE(MyExampleApp main.cpp)
我可以在此行之后将其他源文件添加到此可执行文件中,但添加到相同或包含的 CMakeList.txt
文件中吗?
解决方案
使用自cmake 3.1起可用的 target_sources
例如 target_sources(MyExampleApp PRIVATE $ {extra_file})
https://cmake.org/cmake/help/v3.1/command/target_sources.html
Given I have defined an executable with its main source file in a CMakeList.txt
file:
ADD_EXECUTABLE(MyExampleApp main.cpp)
Can I add further source files to this executable after this line but in the same or an included CMakeList.txt
file?
解决方案
Use target_sources
, available since cmake 3.1
eg.
target_sources(MyExampleApp PRIVATE ${extra_file})
https://cmake.org/cmake/help/v3.1/command/target_sources.html
这篇关于一旦定义,是否可以将其他源文件添加到可执行文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文