From 154ce9b1ce22532a68f95f2291fa12fd90c49fde Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 19 Jun 2021 14:10:36 +0200 Subject: Make sources relative to the build-file (include paths are still relative to project rootdir). Add -b to control build-dir. --- libcppbuild.cc | 66 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'libcppbuild.cc') diff --git a/libcppbuild.cc b/libcppbuild.cc index d58705d..f641a90 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -26,7 +27,8 @@ using namespace std::chrono_literals; std::list> 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> taskFactory(const BuildConfiguration& config, std::list> tasks; for(const auto& file : config.sources) { - tasks.emplace_back(std::make_shared(config, settings, file)); + tasks.emplace_back(std::make_shared(config, settings, + sourceDir, file)); objects.push_back(tasks.back()->target()); } @@ -93,8 +96,7 @@ std::array 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 (*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 build_configs; + std::deque build_configs; + std::list> 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 objects; + auto t = taskFactory(build_config, settings, path); + tasks.insert(tasks.end(), t.begin(), t.end()); } } - std::list> tasks; - for(const auto& build_config : build_configs) - { - std::vector objects; - auto t = taskFactory(build_config, settings); - tasks.insert(tasks.end(), t.begin(), t.end()); - } - for(auto task : tasks) { task->registerDepTasks(tasks); -- cgit v1.2.3