From 55db1098b8249e80b3140520283f65a7956eb5cf Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Thu, 2 Nov 2023 18:27:39 -0400 Subject: [PATCH] Switch default compiler to clang with ninja --- CMakeLists.txt | 2 +- src/main.cpp | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6df9ce7..aa05063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16.3) # Set the project name and version -project(cgen VERSION 1.0.5) +project(cgen VERSION 1.1.0) # specify the C++ standard set(CMAKE_CXX_STANDARD 17) diff --git a/src/main.cpp b/src/main.cpp index f3d0585..49279c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,7 @@ int main(int argc, char** argv) argParser.AddArg(ArgDesc("-x", true, 1, "Add executable submodule projects, separated by ',' (ex: -x first,second,third)")); argParser.AddArg(ArgDesc("-r", true, 0, "Remove the root project executable")); argParser.AddArg(ArgDesc("-gs", true, 0, "Add git subsystem updating to the main cmake file.")); + argParser.AddArg(ArgDesc("-b", true, 1, "Set the default compiler on windows (msvc, clang). Default is msvc")); bool result = argParser.Parse(); @@ -496,7 +497,15 @@ int main(int argc, char** argv) ofs << "\n echo Build mode is Debug"; ofs << "\n)"; ofs << "\necho using options %options%"; - ofs << "\ncmake -Wno-dev %build_type% %options% -B build/ -S . -G " << vs_version.c_str() << " -A x64"; + + if (argParser.ContainsOption("-b") && jpUtils::StringManip::ToLower(argParser.GetOptionValue("-b").values[0]) == "msvc") + { + ofs << "\ncmake -Wno-dev %build_type% %options% -B build/ -S . -G " << vs_version.c_str() << " -A x64"; + } + else + { + ofs << "\ncmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -Wno-dev -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang %build_type% %options% -B build/ -S . -G Ninja"; + } ofs << "\ngoto exit"; ofs << "\n"; @@ -553,8 +562,16 @@ int main(int argc, char** argv) ofs << "\n\tgoto END"; ofs << "\n)"; - + + if (argParser.ContainsOption("-b") && jpUtils::StringManip::ToLower(argParser.GetOptionValue("-b").values[0]) == "msvc") + { ofs << "\ncmake --build build/ --target ALL_BUILD"; + } + else + { + ofs << "\ncmake --build build/ --target all"; + } + ofs << "\n\nSET BUILD_ERRORLEVEL=!ERRORLEVEL!"; ofs << "\nIF NOT \"!BUILD_ERRORLEVEL!\"==\"0\" ("; ofs << "\n\techo %ESC%[91mBUILD FAILED!%ESC%[0m %BUILD_ERRORLEVEL%";