diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | backend/ninja/Ninja.cpp | 19 | ||||
-rwxr-xr-x | scripts/download_dependencies.sh | 8 | ||||
-rw-r--r-- | src/CmakeModule.cpp | 59 |
4 files changed, 74 insertions, 15 deletions
@@ -1,3 +1,6 @@ +# TODO +Make shell scripts portable. Currently they only work with bash... Use shellcheck to find the issues. + # Simple Build System for Native Languages Sibs is still in very early testing phase, use with caution. New releases can have changes that are not backwards compatible. diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index f5c92a4..1848e99 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -5,6 +5,7 @@ #include "../../include/Exec.hpp" #include "../../include/PkgConfig.hpp" #include "../../include/GlobalLib.hpp" +#include "../../include/CmakeModule.hpp" #include <algorithm> using namespace std; @@ -380,10 +381,20 @@ namespace backend errMsg += " is an executable. Only libraries can be sub projects"; return Result<bool>::Err(errMsg); } - - Result<bool> buildResult = subProject.subProject->build(*subProject.config, subProject.buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallback, globalIncludeDirCallback); - if(!buildResult) - return buildResult; + + if(subProject.config->shouldUseCmake()) + { + CmakeModule cmakeModule; + Result<bool> buildResult = cmakeModule.compile(*subProject.config, subProject.buildPath, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallback, globalIncludeDirCallback); + if(!buildResult) + return buildResult; + } + else + { + Result<bool> buildResult = subProject.subProject->build(*subProject.config, subProject.buildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallback, globalIncludeDirCallback); + if(!buildResult) + return buildResult; + } } return Result<bool>::Ok(true); } diff --git a/scripts/download_dependencies.sh b/scripts/download_dependencies.sh index ff68267..9f8ec7a 100755 --- a/scripts/download_dependencies.sh +++ b/scripts/download_dependencies.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh if (( "$#" != 1 )); then echo "usage: download_dependencies.sh <program_name>" @@ -11,8 +11,8 @@ if [ $(id -u) = 0 ]; then fi program_name="$1" -script_path=`readlink -f $0` -script_dir=`dirname $script_path` +script_path=$(readlink -f "$0") +script_dir=$(dirname "$script_path") if [ -f /usr/lib/sibs/"$program_name".cache ]; then #echo "No need to download dependencies, all dependencies exist in cache" @@ -123,4 +123,4 @@ if [ $is_root -eq 0 ]; then touch ~/.local/lib/sibs/"$program_name".cache else touch /usr/lib/sibs/"$program_name".cache -fi
\ No newline at end of file +fi diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp index 348597d..9e399ac 100644 --- a/src/CmakeModule.cpp +++ b/src/CmakeModule.cpp @@ -18,6 +18,33 @@ namespace sibs { static FileString cmakePath = TINYDIR_STRING("cmake"); + static FileString getIncludeOptionFlag(Compiler compiler, const FileString &filepath) + { + FileString result; + switch (compiler) + { + case Compiler::MINGW_W64: + case Compiler::GCC: + { + result = FileString("'-I"); + result += filepath; + result += FileString("'"); + break; + } + case Compiler::MSVC: + { + result = FileString("/I \""); + result += filepath; + result += FileString("\""); + break; + } + default: + assert(false); + break; + } + return result; + } + void CmakeModule::setCmakePath(const FileString &path) { cmakePath = path; @@ -137,7 +164,8 @@ namespace sibs Result<bool> createBuildDirResult = createDirectoryRecursive(buildPath.c_str()); if (createBuildDirResult.isErr()) return createBuildDirResult; - + +#if 0 #if OS_FAMILY == OS_FAMILY_POSIX setenv("CFLAGS", "-fPIC", 1); setenv("CXXFLAGS", "-fPIC", 1); @@ -145,16 +173,33 @@ namespace sibs _putenv("CFLAGS=-fPIC"); _putenv("CXXFLAGS=-fPIC"); #endif +#endif FileString cmd = cmakePath; cmd += TINYDIR_STRING(" "); - if(config.getCompiler() == Compiler::GCC) + + FileString cflags = TINYDIR_STRING("-fPIC"); + FileString cxxflags; + + if(config.getCompiler() == Compiler::GCC && config.getSanitize()) { - if(config.getSanitize()) - { - cmd += TINYDIR_STRING(" \"-CMAKE_C_FLAGS=-fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=leak -lasan -lubsan -llsan\" " - "\"-CMAKE_CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=leak -lasan -lubsan -llsan\""); - } + cflags += TINYDIR_STRING(" -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=leak -lasan -lubsan -llsan"); } + +#if OS_FAMILY == OS_FAMILY_POSIX + cflags += TINYDIR_STRING(" -I/usr/local/include"); +#endif + for(const auto &includeDir : config.getIncludeDirs()) + { + FileString includeDirRelative = FileString("../../../"); + includeDirRelative += toFileString(includeDir); + cflags += TINYDIR_STRING(" "); + cflags += getIncludeOptionFlag(config.getCompiler(), includeDirRelative); + } + + cxxflags = cflags; + cmd += TINYDIR_STRING(" \"-DCMAKE_C_FLAGS=") + cflags + TINYDIR_STRING("\""); + cmd += TINYDIR_STRING(" \"-DCMAKE_CXX_FLAGS=") + cxxflags + TINYDIR_STRING("\" "); + switch(config.getPackageType()) { case PackageType::EXECUTABLE: |