summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc66
1 files changed, 41 insertions, 25 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index d58705d..f641a90 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -10,6 +10,7 @@
#include <algorithm>
#include <list>
#include <array>
+#include <deque>
#include <getoptpp/getoptpp.hpp>
@@ -26,7 +27,8 @@
using namespace std::chrono_literals;
std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
- const Settings& settings)
+ const Settings& settings,
+ const std::string& sourceDir)
{
std::filesystem::path targetFile(config.target);
@@ -34,7 +36,8 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
std::list<std::shared_ptr<Task>> tasks;
for(const auto& file : config.sources)
{
- tasks.emplace_back(std::make_shared<TaskCC>(config, settings, file));
+ tasks.emplace_back(std::make_shared<TaskCC>(config, settings,
+ sourceDir, file));
objects.push_back(tasks.back()->target());
}
@@ -93,8 +96,7 @@ std::array<Config, 100> configFiles;
int numConfigFiles{0};
// TODO: Use c++20 when ready, somehing like this:
-//void reg(const std::source_location location =
-// std::source_location::current())
+//int reg(const std::source_location location = std::source_location::current())
int reg(const char* location,
std::vector<BuildConfiguration> (*cb)())
{
@@ -105,7 +107,7 @@ int reg(const char* location,
return 0;
}
-void recompileCheck(int argc, char* argv[])
+void recompileCheck(const Settings& settings, int argc, char* argv[])
{
bool dirty{false};
@@ -117,11 +119,18 @@ void recompileCheck(int argc, char* argv[])
std::filesystem::path binFile("cppbuild");
- std::cout << "Recompile check (" << numConfigFiles << "):\n";
+ if(settings.verbose > 1)
+ {
+ std::cout << "Recompile check (" << numConfigFiles << "):\n";
+ }
+
for(int i = 0; i < numConfigFiles; ++i)
{
std::string location = configFiles[i].file;
- std::cout << " - " << location << "\n";
+ if(settings.verbose > 1)
+ {
+ std::cout << " - " << location << "\n";
+ }
std::filesystem::path configFile(location);
if(std::filesystem::last_write_time(binFile) <=
std::filesystem::last_write_time(configFile))
@@ -163,21 +172,17 @@ void recompileCheck(int argc, char* argv[])
int main(int argc, char* argv[])
{
- recompileCheck(argc, argv);
-
- Settings settings;
- // TODO: Set from commandline
- settings.builddir = "build/foo";
+ Settings settings{};
+ settings.builddir = "build/";
settings.parallel_processes =
std::max(1u, std::thread::hardware_concurrency() * 2 - 1);
-
settings.verbose = 0;
dg::Options opt;
opt.add("jobs", required_argument, 'j',
- "Number of parallel jobs.",
+ "Number of parallel jobs. (default: cpucount * 2 - 1 )",
[&]() {
try
{
@@ -191,8 +196,15 @@ int main(int argc, char* argv[])
return 0;
});
+ opt.add("build-dir", required_argument, 'b',
+ "Set output directory for build files (default: build).",
+ [&]() {
+ settings.builddir = optarg;
+ return 0;
+ });
+
opt.add("verbose", no_argument, 'v',
- "Be verbose.",
+ "Be verbose. Add multiple times for more verbosity.",
[&]() {
settings.verbose++;
return 0;
@@ -208,28 +220,32 @@ int main(int argc, char* argv[])
opt.process(argc, argv);
+ recompileCheck(settings, argc, argv);
+
std::filesystem::path builddir(settings.builddir);
std::filesystem::create_directories(builddir);
- std::vector<BuildConfiguration> build_configs;
+ std::deque<BuildConfiguration> build_configs;
+ std::list<std::shared_ptr<Task>> tasks;
for(int i = 0; i < numConfigFiles; ++i)
{
- //std::string location = configFiles[i].file;
+ std::string path =
+ std::filesystem::path(configFiles[i].file).parent_path();
+ if(settings.verbose > 1)
+ {
+ std::cout << configFiles[i].file << " in path " << path << "\n";
+ }
auto configs = configFiles[i].cb();
for(const auto& config : configs)
{
build_configs.push_back(config);
+ const auto& build_config = build_configs.back();
+ std::vector<std::string> objects;
+ auto t = taskFactory(build_config, settings, path);
+ tasks.insert(tasks.end(), t.begin(), t.end());
}
}
- std::list<std::shared_ptr<Task>> tasks;
- for(const auto& build_config : build_configs)
- {
- std::vector<std::string> objects;
- auto t = taskFactory(build_config, settings);
- tasks.insert(tasks.end(), t.begin(), t.end());
- }
-
for(auto task : tasks)
{
task->registerDepTasks(tasks);