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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.