John M. John M. - 10 months ago 36
C++ Question

Can I create a single file that mentions all files I want to build : c++

In React, I can write code like this for my containers/components:

export App from './App/App';
export Chat from './Chat/Chat';
export Home from './Home/Home';

This allows me to specify the stuff that I am exporting from that dir. Can I do something like that in

What I want is to be able to create a header file that includes the files that I want to build. I dont want to list them out in
as it becomes too cluttered. I also dont want to
as it doesnt allow me to select files. How do I do this?

Answer Source

Just create file which lists sources:



and read it using file(STRINGS) command into the variable:


# Load list of sources into 'sources' variable
file(STRINGS "sources.list" sources)

# Use the variable
add_executable(my_exe ${sources})