cmake制作多个可执行文件 [英] cmake to make multiple executable files
问题描述
当前,我在目录中有CMakeLists和hoge.cpp,并运行CMakeLists和make命令生成hoge可执行文件.
Currently, I have CMakeLists and hoge.cpp in a directory, and running CMakeLists and make command generates hoge executable file.
现在,我添加了hoge2.cpp,并希望能够通过运行CMakeLists以及"make hoge"和"make hoge2"命令来生成两个不同的hoge和hoge2可执行文件.
Now I added hoge2.cpp and want to be able to generate two different hoge and hoge2 executable files by running CMakeLists and "make hoge" and "make hoge2" commands.
我该怎么做?
推荐答案
在CMakeLists.txt文件中创建两个构建目标.
Create two build targets in your CMakeLists.txt file.
add_executable( hoge hoge.cpp )
add_executable( hoge2 hoge2.cpp )
然后您可以运行(与CMakeLists.txt文件位于同一目录,
Then you can run (from same directory as your CMakeLists.txt file,
cmake --build . --target hoge
用于其他构建目标
cmake --build . --target hoge2
有关更多信息,请参考CMake文档或手册页.尝试仅使用-build
标志运行CMake以获得帮助.
You can refer to the CMake documentation or the man pages for more information. Try running CMake with just the --build
flag to get help.
这篇关于cmake制作多个可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!