From 2f2555bb21dc0f53cf28155082a2bb0ac12c8959 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 8 Jun 2019 22:04:38 +0200 Subject: Compile cmake sub project as cmake --- src/CmakeModule.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) (limited to 'src') 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,24 +164,42 @@ namespace sibs Result 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); #else _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: -- cgit v1.2.3