From 87a65f6913429b26e63fdee17cb8cfe93990db35 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 2 Jan 2018 17:38:18 +0100 Subject: Add support for cmake Not working fully yet, will investigate why --- src/GlobalLib.cpp | 159 +++++++++++++++++++++++++++++------------------------- 1 file changed, 85 insertions(+), 74 deletions(-) (limited to 'src/GlobalLib.cpp') diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index 69c4ebb..3334655 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -4,6 +4,7 @@ #include "../include/Conf.hpp" #include "../include/curl.hpp" #include "../include/Archive.hpp" +#include "../include/CmakeModule.hpp" using namespace std; @@ -147,43 +148,7 @@ namespace sibs errMsg += ")"; return Result::Err(errMsg); } - - backend::Ninja ninja; - // TODO: Use same source file finder as in main.cpp - 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 fileNameNative = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size() + 1); - ninja.addSourceFile(fileNameNative.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... - // OR I believe there is no reason to run tests in dependencies. The main projects tests should cover that? - // But you might want to know exactly which dependency is causing issue and which part of it... - 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(packageDir.c_str(), collectSourceFiles); - + FileString buildPath = packageDir + TINYDIR_STRING("/sibs-build/"); switch (sibsConfig.getOptimizationLevel()) { @@ -214,60 +179,106 @@ namespace sibs break; } } - - if (!ninja.getSourceFiles().empty()) + + if(sibsConfig.shouldUseCmake()) + { + CmakeModule cmakeModule; + Result cmakeCompileResult = cmakeModule.compile(sibsConfig, buildPath, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback); + if(!cmakeCompileResult) + return cmakeCompileResult; + } + else { - string libPath = toUtf8(buildPath); - switch (sibsConfig.getCompiler()) + backend::Ninja ninja; + // TODO: Use same source file finder as in main.cpp + FileWalkCallbackFunc collectSourceFiles = [&ninja, &sibsConfig, &collectSourceFiles](tinydir_file *file) { - case Compiler::GCC: + FileString pathNative = file->path; + #if OS_FAMILY == OS_FAMILY_WINDOWS + replaceChar(pathNative, L'/', L'\\'); + #endif + if(file->is_reg) { - libPath += "/lib"; - libPath += name; - if (sibsConfig.getPackageType() == PackageType::STATIC) + if (isSourceFile(file)) { - libPath += ".a"; - string libPathCmd = "'"; - libPathCmd += libPath; - libPathCmd += "'"; - staticLinkerFlagCallbackFunc(libPathCmd); + string fileNameNative = toUtf8(pathNative.c_str() + sibsConfig.getProjectPath().size() + 1); + ninja.addSourceFile(fileNameNative.c_str()); } else { - libPath += ".so"; - string libPathCmd = "'"; - libPathCmd += libPath; - libPathCmd += "'"; - dynamicLinkerFlagCallbackFunc(libPathCmd); + //printf("Ignoring non-source file: %s\n", file->path + projectPath.size()); } - break; } - case Compiler::MSVC: + else { - libPath += "/"; - libPath += name; - if (sibsConfig.getPackageType() == PackageType::STATIC) + // TODO: If compiling without "test" option, do not add test source dir to ninja. Ninja logic will then not build tests... + // OR I believe there is no reason to run tests in dependencies. The main projects tests should cover that? + // But you might want to know exactly which dependency is causing issue and which part of it... + if (!sibsConfig.getTestPath().empty() && isPathSubPathOf(pathNative.c_str(), sibsConfig.getTestPath())) { - libPath += ".lib"; - string libPathCmd = "\""; - libPathCmd += libPath; - libPathCmd += "\""; - staticLinkerFlagCallbackFunc(libPathCmd); + string filePathUtf8 = toUtf8(pathNative.c_str()); + ninja.addTestSourceDir(filePathUtf8.c_str()); } - else + else if(!directoryToIgnore(pathNative, sibsConfig.getIgnoreDirs())) + walkDir(file->path, collectSourceFiles); + } + }; + walkDir(packageDir.c_str(), collectSourceFiles); + + if (!ninja.getSourceFiles().empty()) + { + string libPath = toUtf8(buildPath); + switch (sibsConfig.getCompiler()) + { + case Compiler::GCC: { - libPath += ".lib"; - string libPathCmd = "\""; - libPathCmd += libPath; - libPathCmd += "\""; - dynamicLinkerFlagCallbackFunc(libPathCmd); + libPath += "/lib"; + libPath += name; + if (sibsConfig.getPackageType() == PackageType::STATIC) + { + libPath += ".a"; + string libPathCmd = "'"; + libPathCmd += libPath; + libPathCmd += "'"; + staticLinkerFlagCallbackFunc(libPathCmd); + } + else + { + libPath += ".so"; + string libPathCmd = "'"; + libPathCmd += libPath; + libPathCmd += "'"; + dynamicLinkerFlagCallbackFunc(libPathCmd); + } + break; + } + case Compiler::MSVC: + { + libPath += "/"; + libPath += name; + if (sibsConfig.getPackageType() == PackageType::STATIC) + { + libPath += ".lib"; + string libPathCmd = "\""; + libPathCmd += libPath; + libPathCmd += "\""; + staticLinkerFlagCallbackFunc(libPathCmd); + } + else + { + libPath += ".lib"; + string libPathCmd = "\""; + libPathCmd += libPath; + libPathCmd += "\""; + dynamicLinkerFlagCallbackFunc(libPathCmd); + } + break; } - break; } } - } - return ninja.build(sibsConfig, buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback); + return ninja.build(sibsConfig, buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback); + } } Result GlobalLib::downloadDependency(const Dependency &dependency) -- cgit v1.2.3