aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parent3605255a8e6eabd20490e784f9535ee540c1d079 (diff)
Compile cmake sub project as cmake
Diffstat (limited to 'src')
-rw-r--r--src/CmakeModule.cpp59
1 files changed, 52 insertions, 7 deletions
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: