aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-06-08 22:04:38 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit2f2555bb21dc0f53cf28155082a2bb0ac12c8959 (patch)
treee7c61243bfa9e93e91db244de7792197d5e47a5e
parent3605255a8e6eabd20490e784f9535ee540c1d079 (diff)
Compile cmake sub project as cmake
-rw-r--r--README.md3
-rw-r--r--backend/ninja/Ninja.cpp19
-rwxr-xr-xscripts/download_dependencies.sh8
-rw-r--r--src/CmakeModule.cpp59
4 files changed, 74 insertions, 15 deletions
diff --git a/README.md b/README.md
index c3e0956..4d7cf0f 100644
--- a/README.md
+++ b/README.md
@@ -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: