diff --git a/.cache/clangd/index/CmdArgParser.cpp.CD1E6970180B062F.idx b/.cache/clangd/index/CmdArgParser.cpp.CD1E6970180B062F.idx new file mode 100644 index 0000000..0fbb4ac Binary files /dev/null and b/.cache/clangd/index/CmdArgParser.cpp.CD1E6970180B062F.idx differ diff --git a/.cache/clangd/index/CmdArgParser.h.F9E91371FECEBB93.idx b/.cache/clangd/index/CmdArgParser.h.F9E91371FECEBB93.idx new file mode 100644 index 0000000..daa88af Binary files /dev/null and b/.cache/clangd/index/CmdArgParser.h.F9E91371FECEBB93.idx differ diff --git a/.cache/clangd/index/StringManip.cpp.375296CF04017569.idx b/.cache/clangd/index/StringManip.cpp.375296CF04017569.idx new file mode 100644 index 0000000..cc2c95c Binary files /dev/null and b/.cache/clangd/index/StringManip.cpp.375296CF04017569.idx differ diff --git a/.cache/clangd/index/StringManip.h.0207ED5DF769BE0C.idx b/.cache/clangd/index/StringManip.h.0207ED5DF769BE0C.idx new file mode 100644 index 0000000..9344100 Binary files /dev/null and b/.cache/clangd/index/StringManip.h.0207ED5DF769BE0C.idx differ diff --git a/.cache/clangd/index/main.cpp.546560AA398ABF2E.idx b/.cache/clangd/index/main.cpp.546560AA398ABF2E.idx new file mode 100644 index 0000000..7d17fad Binary files /dev/null and b/.cache/clangd/index/main.cpp.546560AA398ABF2E.idx differ diff --git a/scripts/build.bat b/scripts/build.bat index 3516115..2c2ba53 100644 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -1,17 +1,32 @@ @echo off +SETLOCAL ENABLEDELAYEDEXPANSION REM This script expects to be run from the parent directory REM ex. scripts/build.bat +REM Sets the escape char. see for info: +REM https://stackoverflow.com/questions/55891318/how-to-echo-with-different-colors-in-the-windows-command-line-inside-a-for-loop +for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a" + IF not exist build/ ( - echo This script needs to be run from the directory above build/ - goto END + echo This script needs to be run from the directory above build/ + goto END ) +cmake --build build/ --target all -IF "%~1" == "r" ( - cmake --build build/ --target ALL_BUILD --config Release -) ELSE ( - cmake --build build/ --target ALL_BUILD --config Debug +SET BUILD_ERRORLEVEL=!ERRORLEVEL! +IF NOT "!BUILD_ERRORLEVEL!"=="0" ( + echo %ESC%[91mBUILD FAILED!%ESC%[0m %BUILD_ERRORLEVEL% + EXIT /B !BUILD_ERRORLEVEL! ) -:END \ No newline at end of file +IF not exist build/bin/shaders ( + mkdir build/bin/shaders +) + +REM TODO: Run any extra tasks here + +echo %ESC%[92mBUILD SUCCEEDED!%ESC%[0m + +:END +ENDLOCAL \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..e7d0c34 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,16 @@ +#! /bin/sh +# This script expects to be run from the parent directory +# ex. scripts/build.sh + +#Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' + +echo building project... +cmake --build build/ +if [ $? -eq 0 ]; then + echo "${GREEN}BUILD SUCCESSFUL${NC}" +else + echo "${RED}BUILD FAILED${NC}" +fi diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100755 index 0000000..2dccb48 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,4 @@ + + +rm -r build +mkdir build \ No newline at end of file diff --git a/scripts/cmconfig.bat b/scripts/cmconfig.bat index ea13b17..06b84fb 100644 --- a/scripts/cmconfig.bat +++ b/scripts/cmconfig.bat @@ -1,7 +1,44 @@ @echo off REM This script expects to be run from the parent directory -REM ex. scripts/cmconfig.bat -@echo off +REM ex. scripts/config.bat +REM script options (like -c and -r) must come before any cmake options (EXAMPLE_BASIC, NO_DIAG, etc) + + +set options= +set build_type= + +IF "%1"=="" goto command +goto loop + + +:command +IF "%build_type%"=="" ( + set build_type=-DCMAKE_BUILD_TYPE=Debug + echo Build mode is Debug +) +echo using options %options% +:: cmake -Wno-dev %build_type% %options% -B build/ -S . -G "Visual Studio 17 2022" -A x64 +cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -Wno-dev -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang %build_type% %options% -B build/ -S . -G Ninja +goto exit + +:loop + +IF "%1"=="-c" ( + call scripts\clean.bat + goto loop_condition +) + +IF "%1"=="-r" ( + echo Build mode is release + set build_type=-DCMAKE_BUILD_TYPE=Release + goto loop_condition +) + +set options=%options%-D%1=ON +:loop_condition +shift +IF "%1"=="" goto command +goto loop -cmake -Wno-dev -B build/ -S . -G "Visual Studio 17 2022" -A x64 +:exit diff --git a/scripts/config.sh b/scripts/config.sh new file mode 100755 index 0000000..7023d01 --- /dev/null +++ b/scripts/config.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# This script expects to be run from the parent directory +# ex. scripts/config.sh + +#Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' + +options= +build_type=-DCMAKE_BUILD_TYPE=Debug + +until [ "$1" = "" ] +do + + if [ "$1" = "-r" ] + then + build_type=-DCMAKE_BUILD_TYPE=Release + + elif [ "$1" = "-c" ] + then + rm -r build + mkdir build + else + options="$options -D$1=ON" + fi + + shift +done + + +echo using options: $options +cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang $build_type -Wno-dev $options -S . -B build/ + +if [ $? -eq 0 ]; then + echo "${GREEN}cmake config successful!${NC}" +else + echo "${RED}cmake config failed. Cleaning partial config.${NC}" +fi diff --git a/src/main.cpp b/src/main.cpp index 49279c2..76a14f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -623,10 +623,54 @@ int main(int argc, char** argv) std::cout << "\nGenerating config script file: " << config_file.string().c_str(); - ofs << "#! /bin/sh"; - ofs << "\n# This script expects to be run from the parent directory"; - ofs << "\n# ex. scripts/cmconfig.sh"; - ofs << "\n\ncmake -S . -B build/"; + ofs << "#!/bin/sh\n"; + ofs << "# This script expects to be run from the parent directory\n"; + ofs << "# ex. scripts/config.sh\n"; + ofs << "\n"; + + ofs << "#Colors\n"; + ofs << "RED='\033[0;31m'\n"; + ofs << "GREEN='\033[0;32m'\n"; + ofs << "NC='\033[0m'\n"; + ofs << "\n"; + + ofs << "options=\n"; + ofs << "build_type=-DCMAKE_BUILD_TYPE=Debug\n"; + ofs << "\n"; + + ofs << "until [ \"$1\" = \"\" ]\n"; + ofs << "do\n"; + ofs << "\n"; + + ofs << " if [ \"$1\" = \"-r\" ]\n"; + ofs << " then\n"; + ofs << " build_type=-DCMAKE_BUILD_TYPE=Release\n"; + ofs << "\n"; + + ofs << " elif [ \"$1\" = \"-c\" ]\n"; + ofs << " then\n"; + ofs << " rm -r build\n"; + ofs << " mkdir build\n"; + ofs << " else\n"; + ofs << " options=\"$options -D$1=ON\"\n"; + ofs << " fi\n"; + ofs << "\n"; + + ofs << " shift\n"; + ofs << "done\n"; + + + ofs << " echo using options: $options\n"; + ofs << " cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang $build_type -Wno-dev $options -S . -B build/\n"; + ofs << "\n"; + + ofs << " if [ $? -eq 0 ]; then\n"; + ofs << " echo \"${GREEN}cmake config successful!${NC}\"\n"; + ofs << " else\n"; + ofs << " echo \"${RED}cmake config failed. Cleaning partial config.${NC}\"\n"; + ofs << " fi\n"; + ofs << "\n"; + ofs.close(); ofs.clear(); @@ -641,10 +685,24 @@ int main(int argc, char** argv) std::cout << "\nGenerating build script file: " << build_file.string().c_str(); - ofs << "#! /bin/sh"; - ofs << "\n# This script expects to be run from the parent directory"; - ofs << "\n# ex. scripts/build.sh"; - ofs << "\n\ncmake -C build/"; + ofs << "#! /bin/sh\n"; + ofs << "# This script expects to be run from the parent directory\n"; + ofs << "# ex. scripts/build.sh\n"; + ofs << "\n"; + + ofs << "#Colors\n"; + ofs << "RED='\033[0;31m'\n"; + ofs << "GREEN='\033[0;32m'\n"; + ofs << "NC='\033[0m'\n"; + ofs << "\n"; + + ofs << "echo building project...\n"; + ofs << "cmake --build build/\n"; + ofs << "if [ $? -eq 0 ]; then\n"; + ofs << " echo \"${GREEN}BUILD SUCCESSFUL${NC}\"\n"; + ofs << "else\n"; + ofs << " echo \"${RED}BUILD FAILED${NC}\"\n"; + ofs << "fi\n"; ofs.close(); ofs.clear(); } diff --git a/src/utils/CmdArgParser.cpp b/src/utils/CmdArgParser.cpp index dbd7267..ea64bb2 100644 --- a/src/utils/CmdArgParser.cpp +++ b/src/utils/CmdArgParser.cpp @@ -9,6 +9,7 @@ * Code should work on windows and *nix ******************************************************************************/ + #include "CmdArgParser.h" #include "StringManip.h"