update
This commit is contained in:
parent
2daf890ed1
commit
be18fb8568
12 changed files with 427 additions and 19 deletions
|
|
@ -27,6 +27,7 @@ module;
|
|||
#include "json.hpp"
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include <glslang/SPIRV/GlslangToSpv.h>
|
||||
module Crafter.Build;
|
||||
using namespace Crafter::Build;
|
||||
namespace fs = std::filesystem;
|
||||
|
|
@ -102,7 +103,24 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
pcmDir = config.buildDir;
|
||||
}
|
||||
|
||||
std::string libs;
|
||||
|
||||
std::string libs = " -L/usr/local/lib";
|
||||
|
||||
if(config.target != "x86_64-w64-mingw64" && config.target != "x86_64-w64-mingw32") {
|
||||
libs += " -L/usr/lib/";
|
||||
}
|
||||
|
||||
for(const std::string& path : config.lib_paths) {
|
||||
libs += std::format(" -L{}", path);
|
||||
}
|
||||
|
||||
for(const std::string& path : config.includeDirs) {
|
||||
libs += std::format(" -I{}", path);
|
||||
}
|
||||
|
||||
for(Shader& shader : config.shaderFiles) {
|
||||
shader.Compile(outputDir);
|
||||
}
|
||||
|
||||
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||
|
||||
|
|
@ -161,6 +179,14 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
flags+=flag;
|
||||
}
|
||||
|
||||
if(config.debug) {
|
||||
flags+=" -g";
|
||||
}
|
||||
|
||||
for(const std::string& lib : config.libs) {
|
||||
libs+= std::format(" -l{}",lib);
|
||||
}
|
||||
|
||||
for(std::thread& thread : depThreads){
|
||||
thread.join();
|
||||
}
|
||||
|
|
@ -182,12 +208,26 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
march = std::format("-march={}", config.march);
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for(std::uint_fast32_t i = 0; i < config.sourceFiles.size(); i++) {
|
||||
files+=std::format("{}_source.o ",(config.buildDir/config.sourceFiles[i].filename()).generic_string());
|
||||
//if(!fs::exists((config.buildDir/config.sourceFiles[i].filename()).generic_string()+"_source.o") || fs::last_write_time(config.sourceFiles[i].generic_string()+".cpp") > fs::last_write_time((config.buildDir/config.sourceFiles[i].filename()).generic_string()+"_source.o")) {
|
||||
threads.emplace_back([i, &config, pcmDir, target, clangDir, flags, march](){
|
||||
system(std::format("{} -std={} {}.cpp -fprebuilt-module-path={} -c -O{} {} {} -o {}_source.o {}", clangDir, config.standard, config.sourceFiles[i].generic_string(), pcmDir.generic_string(), config.optimizationLevel, march, flags, (config.buildDir/config.sourceFiles[i].filename()).generic_string(), target).c_str());
|
||||
std::string command = std::format("{} -std={} {}.cpp -fprebuilt-module-path={} -c -O{} {} {} -o {}_source.o {}", clangDir, config.standard, config.sourceFiles[i].generic_string(), pcmDir.generic_string(), config.optimizationLevel, march, flags, (config.buildDir/config.sourceFiles[i].filename()).generic_string(), target);
|
||||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
system(command.c_str());
|
||||
});
|
||||
//}
|
||||
}
|
||||
|
||||
for(std::uint_fast32_t i = 0; i < config.c_files.size(); i++) {
|
||||
files+=std::format("{}_source.o ",(config.buildDir/config.c_files[i].filename()).generic_string());
|
||||
//if(!fs::exists((config.buildDir/config.sourceFiles[i].filename()).generic_string()+"_source.o") || fs::last_write_time(config.sourceFiles[i].generic_string()+".cpp") > fs::last_write_time((config.buildDir/config.sourceFiles[i].filename()).generic_string()+"_source.o")) {
|
||||
threads.emplace_back([i, &config, pcmDir, target, clangDir, flags, march](){
|
||||
system(std::format("clang {}.c -c -O{} {} {} -o {}_source.o {}", config.c_files[i].generic_string(), config.optimizationLevel, march, flags, (config.buildDir/config.c_files[i].filename()).generic_string(), target).c_str());
|
||||
});
|
||||
//}
|
||||
}
|
||||
|
|
@ -197,9 +237,18 @@ void Project::Build(Configuration config, fs::path outputDir, fs::path binDir) c
|
|||
}
|
||||
|
||||
if(config.type == "executable"){
|
||||
system(std::format("{} {}-O{} -o {} {} {} -fuse-ld=lld", clangDir, files, config.optimizationLevel, (outputDir/name).generic_string(), target, libs).c_str());
|
||||
//std::cout << std::format("{} {} {}-O{} -o {} {} {} -fuse-ld=lld", clangDir, flags, files, config.optimizationLevel, (outputDir/name).generic_string(), target, libs).c_str() << std::endl;
|
||||
if(config.target == "x86_64-w64-mingw64" || config.target == "x86_64-w64-mingw32") {
|
||||
flags += " -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread";
|
||||
name += ".exe";
|
||||
}
|
||||
std::string command = std::format("{} {} {}-O{} -o {} {} {} -fuse-ld=lld", clangDir, flags, files, config.optimizationLevel, (outputDir/name).generic_string(), target, libs);
|
||||
if(config.verbose) {
|
||||
std::cout << command << std::endl;
|
||||
}
|
||||
system(command.c_str());
|
||||
} else if(config.type == "library"){
|
||||
system(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
system(std::format("ar r {}.a {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
} else if(config.type == "shared-library"){
|
||||
system(std::format("ar r {}.so {}", (outputDir/fs::path("lib"+name)).generic_string(), files).c_str());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue