aboutsummaryrefslogtreecommitdiff
path: root/src/CmakeModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/CmakeModule.cpp')
-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: