diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-01-02 17:38:18 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-01-02 20:10:53 +0100 |
commit | 87a65f6913429b26e63fdee17cb8cfe93990db35 (patch) | |
tree | c2cfac67fc09f9c364869a107a140c34c5b73fd8 /src/main.cpp | |
parent | e8afe1630280335e5c7f4938f7c265b8798049d1 (diff) |
Add support for cmake
Not working fully yet, will investigate why
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/src/main.cpp b/src/main.cpp index a4e493e..b3b6d63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "../include/FileUtil.hpp" #include "../include/Conf.hpp" #include "../include/Exec.hpp" +#include "../include/CmakeModule.hpp" #include "../backend/ninja/Ninja.hpp" using namespace std; @@ -226,43 +227,7 @@ int buildProject(int argc, const _tinydir_char_t **argv) cerr << errMsg << endl; exit(11); } - - //string projectSrcPath = projectPath + "/src"; - //validateDirectoryPath(projectSrcPath.c_str()); - - backend::Ninja ninja; - FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file) - { - FileString pathNative = file->path; -#if OS_FAMILY == OS_FAMILY_WINDOWS - replaceChar(pathNative, L'/', L'\\'); -#endif - if(file->is_reg) - { - if (isSourceFile(file)) - { - string filePathUtf8 = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size()); - ninja.addSourceFile(filePathUtf8.c_str()); - } - else - { - //printf("Ignoring non-source file: %s\n", file->path + projectPath.size()); - } - } - else - { - // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests - if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath())) - { - string filePathUtf8 = toUtf8(pathNative.c_str()); - ninja.addTestSourceDir(filePathUtf8.c_str()); - } - else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs())) - walkDir(file->path, collectSourceFiles); - } - }; - walkDir(projectPath.c_str(), collectSourceFiles); - + FileString buildPath = projectPath + TINYDIR_STRING("/sibs-build/"); switch(sibsConfig.getOptimizationLevel()) { @@ -275,11 +240,59 @@ int buildProject(int argc, const _tinydir_char_t **argv) } auto startTime = high_resolution_clock::now(); - Result<bool> buildFileResult = ninja.build(sibsConfig, buildPath.c_str()); - if(buildFileResult.isErr()) + if(sibsConfig.shouldUseCmake()) + { + auto dummyCallback = [](const string&){}; + + CmakeModule cmakeModule; + Result<bool> cmakeCompileResult = cmakeModule.compile(sibsConfig, buildPath, dummyCallback, dummyCallback, dummyCallback); + if(!cmakeCompileResult) + { + ferr << "Failed to compile using cmake: " << toFileString(cmakeCompileResult.getErrMsg()) << endl; + exit(7); + } + } + else { - ferr << "Failed to build ninja file: " << toFileString(buildFileResult.getErrMsg()) << endl; - exit(7); + backend::Ninja ninja; + FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file) + { + FileString pathNative = file->path; + #if OS_FAMILY == OS_FAMILY_WINDOWS + replaceChar(pathNative, L'/', L'\\'); + #endif + if(file->is_reg) + { + if (isSourceFile(file)) + { + string filePathUtf8 = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size()); + ninja.addSourceFile(filePathUtf8.c_str()); + } + else + { + //printf("Ignoring non-source file: %s\n", file->path + projectPath.size()); + } + } + else + { + // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests + if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath())) + { + string filePathUtf8 = toUtf8(pathNative.c_str()); + ninja.addTestSourceDir(filePathUtf8.c_str()); + } + else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs())) + walkDir(file->path, collectSourceFiles); + } + }; + walkDir(projectPath.c_str(), collectSourceFiles); + + Result<bool> buildFileResult = ninja.build(sibsConfig, buildPath.c_str()); + if(buildFileResult.isErr()) + { + ferr << "Failed to build ninja file: " << toFileString(buildFileResult.getErrMsg()) << endl; + exit(7); + } } auto elapsedTime = duration_cast<duration<double>>(high_resolution_clock::now() - startTime); printf("Build finished in %fs\n", elapsedTime.count()); |