Reputation: 411
I currently have a project with a template for one CMakeLists.txt
for one executable, one header and one .cpp
file. I would like for it to have several .cpp
files, but still have it all compiled and build. How should I make the CMakeLists.txt
file build and compile all the .cpp
files, and how can I check if it worked?
Upvotes: 4
Views: 7714
Reputation: 5683
How should I make the CMakeLists file build and compile all the .cpp files
add_executable
in cmake accepts more than just one argument.
So write your .cpp files as follows:
add_executable(my_project_executable main.cpp include/helper.cpp ...)
Furthermore, using set
is a basic practice for this, as follows:
set(SOURCES main.cpp include/helper.cpp ...)
add_executable(my_project_executable ${SOURCES})
how can I check if it worked?
Well, why don't you just build it to see if it works?
# See it build okay.
$ cmake .
$ make
Upvotes: 9