Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one add further source files to an executable once defined?

Tags:

cmake

Given I have defined an executable with its main source file in a CMakeList.txt file:

ADD_EXECUTABLE(MyExampleApp main.cpp) 

Can I add further source files to this executable after this line but in the same or an included CMakeList.txt file?

like image 825
Torbjörn Avatar asked Feb 18 '12 08:02

Torbjörn


People also ask

What is a executable target?

An IMPORTED executable target references an executable file located outside the project. No rules are generated to build it, and the IMPORTED target property is True . The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility.


1 Answers

Use target_sources, available since cmake 3.1

eg. target_sources(MyExampleApp PRIVATE ${extra_file})

https://cmake.org/cmake/help/v3.1/command/target_sources.html

like image 172
ACyclic Avatar answered Oct 26 '22 12:10

ACyclic