问题
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