Suppose that I’ve got two main entries, one in main1.cpp and one in main2.cpp (there are other files too, but only two main entries). How can I configure the CMakeLists.txt file so that I can include either main1.cpp or main2.cpp based on different targets? i.e. I will eventually be able to use “make target1” to produce exec1 based on main1.cpp and “make target2” to produce exec2 based on main2.cpp along with other files.
Suppose that I’ve got two main entries, one in main1.cpp and one in main2.cpp
Share
Sounds like a case for making a library out of all your sources except the mains. Then just add two executable targets, each linked to the library.
You can just include all the sources twice, so
MyExe1would have everything except main2.cpp, andMyExe2everything except main1.cpp, but this would involve compiling the sources twice and is inefficient.