summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-13 21:25:03 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-13 21:25:03 +0200
commit23eee0d41ba0dcc88f568a7124538368688db1ce (patch)
tree512a4b683a011f8570d2ffcf43f85907e8ab99c5 /libcppbuild.cc
parent5ea97553355c8109e81a560ba90ce942fa8db429 (diff)
Add support for multiple build configurations.
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc128
1 files changed, 65 insertions, 63 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index c75f43e..bf1a7fa 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -30,62 +30,81 @@ int main(int argc, const char* argv[])
std::filesystem::path builddir(settings.builddir);
std::filesystem::create_directories(builddir);
- auto config = configs();
-
- std::vector<std::string> objects;
- std::vector<std::unique_ptr<Task>> tasks;
- for(const auto& file : config.sources)
+ auto build_configs = configs();
+ for(const auto& build_config : build_configs)
{
- tasks.emplace_back(std::make_unique<TaskCC>(config, settings, file));
- objects.push_back(tasks.back()->target());
- }
+ std::vector<std::string> objects;
+ std::vector<std::unique_ptr<Task>> tasks;
+ for(const auto& file : build_config.sources)
+ {
+ tasks.emplace_back(std::make_unique<TaskCC>(build_config, settings, file));
+ objects.push_back(tasks.back()->target());
+ }
- TaskLD task_ld(config, settings, config.target, objects);
+ TaskLD task_ld(build_config, settings, build_config.target, objects);
- if(argc == 2 && std::string(argv[1]) == "clean")
- {
- std::cout << "Cleaning\n";
- //std::filesystem::remove_all(builddir);
- for(auto& task : tasks)
+ if(argc == 2 && std::string(argv[1]) == "clean")
{
- if(task->clean() != 0)
+ std::cout << "Cleaning\n";
+ //std::filesystem::remove_all(builddir);
+ for(auto& task : tasks)
+ {
+ if(task->clean() != 0)
+ {
+ return 1;
+ }
+ }
+
+ if(task_ld.clean() != 0)
{
return 1;
}
- }
- if(task_ld.clean() != 0)
- {
- return 1;
+ return 0;
}
- return 0;
- }
-
- std::cout << "Building\n";
+ std::cout << "Building\n";
- std::list<std::future<int>> processes;
+ std::list<std::future<int>> processes;
- // Start all tasks
- auto task = tasks.begin();
- while(task != tasks.end())
- {
- while(processes.size() < settings.parallel_processes &&
- task != tasks.end())
+ // Start all tasks
+ auto task = tasks.begin();
+ while(task != tasks.end())
{
- if(!(*task)->dirty())
+ while(processes.size() < settings.parallel_processes &&
+ task != tasks.end())
{
+ if(!(*task)->dirty())
+ {
+ ++task;
+ continue;
+ }
+
+ processes.emplace_back(
+ std::async(std::launch::async,
+ [&t = *task]()
+ {
+ return t->run();
+ }));
++task;
- continue;
+ std::this_thread::sleep_for(2ms);
+ }
+
+ for(auto process = processes.begin();
+ process != processes.end();
+ ++process)
+ {
+ if(process->valid())
+ {
+ if(process->get() != 0)
+ {
+ return 1;
+ }
+ processes.erase(process);
+ break;
+ }
}
- processes.emplace_back(
- std::async(std::launch::async,
- [&t = *task]()
- {
- return t->run();
- }));
- ++task;
std::this_thread::sleep_for(2ms);
}
@@ -93,37 +112,20 @@ int main(int argc, const char* argv[])
process != processes.end();
++process)
{
- if(process->valid())
+ process->wait();
+ auto ret = process->get();
+ if(ret != 0)
{
- if(process->get() != 0)
- {
- return 1;
- }
- processes.erase(process);
- break;
+ return 1;
}
}
- std::this_thread::sleep_for(2ms);
- }
-
- for(auto process = processes.begin();
- process != processes.end();
- ++process)
- {
- process->wait();
- auto ret = process->get();
- if(ret != 0)
+ std::cout << "Linking\n";
+ if(task_ld.dirty())
{
- return 1;
+ return task_ld.run();
}
}
- std::cout << "Linking\n";
- if(task_ld.dirty())
- {
- return task_ld.run();
- }
-
return 0;
}