cmake to make multiple executable files

ⅰ亾dé卋堺 提交于 2021-02-08 10:19:08

问题


Currently, I have CMakeLists and hoge.cpp in a directory, and running CMakeLists and make command generates hoge executable file.

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.

How can I do this?


回答1:


Create two build targets in your CMakeLists.txt file.

add_executable( hoge hoge.cpp )
add_executable( hoge2 hoge2.cpp )

Then you can run (from same directory as your CMakeLists.txt file,

cmake --build . --target hoge

For the other build target use

cmake --build . --target hoge2

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.



来源:https://stackoverflow.com/questions/50342578/cmake-to-make-multiple-executable-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!