From 87c378c20c30c9251c3787f6fd5496b72511f344 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 10 Dec 2017 15:22:45 +0100 Subject: Do not build dependency as library if it's header only library --- backend/ninja/Ninja.cpp | 5 +++++ backend/ninja/Ninja.hpp | 1 + src/GlobalLib.cpp | 39 +++++++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 20e2374..1185366 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -51,6 +51,11 @@ namespace backend sourceFiles.emplace_back(filepath); } + const std::vector& Ninja::getSourceFiles() const + { + return sourceFiles; + } + bool Ninja::containsSourceFile(const char *filepath) const { for(const string &sourceFile : sourceFiles) diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp index 71b12a5..3ccee1e 100644 --- a/backend/ninja/Ninja.hpp +++ b/backend/ninja/Ninja.hpp @@ -24,6 +24,7 @@ namespace backend Ninja(LibraryType libraryType = LibraryType::EXECUTABLE); void addSourceFile(const char *filepath); + const std::vector& getSourceFiles() const; sibs::Result createBuildFile(const std::string &packageName, const std::vector &dependencies, const char *savePath, sibs::LinkerFlagCallbackFunc linkerFlagCallbackFunc = nullptr); sibs::Result build(const char *buildFilePath); private: diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index 44652b8..cbd822e 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -124,21 +124,28 @@ namespace sibs } }); - // TODO: Create build path if it doesn't exist - string debugBuildPath = packageDir + "/build/debug"; - Result buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), linkerFlagCallbackFunc); - if(buildFileResult.isErr()) - return Result::Err(buildFileResult.getErrMsg()); - - Result buildResult = ninja.build(debugBuildPath.c_str()); - if(buildResult.isErr()) - return Result::Err(buildResult.getErrMsg()); - - string staticLibPath = debugBuildPath; - staticLibPath += "/lib"; - staticLibPath += name; - staticLibPath += ".a"; - linkerFlagCallbackFunc(staticLibPath); - return Result::Ok(staticLibPath); + if(ninja.getSourceFiles().empty()) + { + return Result::Ok(""); + } + else + { + // TODO: Create build path if it doesn't exist + string debugBuildPath = packageDir + "/build/debug"; + Result buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), linkerFlagCallbackFunc); + if (buildFileResult.isErr()) + return Result::Err(buildFileResult.getErrMsg()); + + Result buildResult = ninja.build(debugBuildPath.c_str()); + if (buildResult.isErr()) + return Result::Err(buildResult.getErrMsg()); + + string staticLibPath = debugBuildPath; + staticLibPath += "/lib"; + staticLibPath += name; + staticLibPath += ".a"; + linkerFlagCallbackFunc(staticLibPath); + return Result::Ok(staticLibPath); + } } } \ No newline at end of file -- cgit v1.2.3