Adds error checking to the cmake build script (batch only) and color-coded results output

master
Joey Pollack 4 years ago
parent 8d9460fe6c
commit 9056c61902

@ -495,19 +495,49 @@ int main(int argc, char** argv)
std::cout << "\nGenerating build script file: " << build_file.string().c_str(); std::cout << "\nGenerating build script file: " << build_file.string().c_str();
ofs << "@echo off"; ofs << "@echo off";
ofs << "\nREM This script expects to be run from the parent directory"; ofs << "\nSETLOCAL ENABLEDELAYEDEXPANSION";
ofs << "\nREM ex. scripts/build.bat"; ofs << "\nREM This script expects to be run from the parent directory";
ofs << "\n\nIF not exist build/ ("; ofs << "\nREM ex. scripts/build.bat";
ofs << "\n\techo This script needs to be run from the directory above build/";
ofs << "\n\tgoto END"; ofs << "\n\nREM Sets the escape char. see for info: ";
ofs << "\n)"; ofs << "\nREM https://stackoverflow.com/questions/55891318/how-to-echo-with-different-colors-in-the-windows-command-line-inside-a-for-loop";
ofs << "\n\nIF \"%~1\" == \"r\" ("; ofs << "\nfor /F %%a in ('echo prompt $E ^| cmd') do set \"ESC=%%a\"";
ofs << "\n\tcmake --build build/ --target ALL_BUILD --config Release";
ofs << "\n) ELSE ("; ofs << "\n\nIF not exist build/ (";
ofs << "\n\tcmake --build build/ --target ALL_BUILD --config Debug"; ofs << "\n\techo This script needs to be run from the directory above build/";
ofs << "\n)"; ofs << "\n\tgoto END";
ofs << "\n\n:END"; ofs << "\n)";
ofs << "\nset \"RELEASE=\"";
ofs << "\n\nIf \"%~1\" == \"r\" set \"RELEASE=1\"";
ofs << "\n\nIF defined RELEASE (";
ofs << "\ncmake --build build/ --target ALL_BUILD --config Release";
ofs << "\n\nSET BUILD_ERRORLEVEL=!ERRORLEVEL!";
ofs << "\nIF NOT \"!BUILD_ERRORLEVEL!\"==\"0\" (";
ofs << "\n\techo %ESC%[91mBUILD FAILED!%ESC%[0m %BUILD_ERRORLEVEL%";
ofs << "\n\tEXIT /B !BUILD_ERRORLEVEL!";
ofs << "\n)";
ofs << "\n\nxcopy /y test_data\\engine_state.xml build\\Release\\";
ofs << "\n) ELSE (";
ofs << "\ncmake --build build/ --target ALL_BUILD --config Debug";
ofs << "\n\nSET BUILD_ERRORLEVEL=!ERRORLEVEL!";
ofs << "\nIF NOT \"!BUILD_ERRORLEVEL!\"==\"0\" (";
ofs << "\n\techo %ESC%[91mBUILD FAILED!%ESC%[0m %BUILD_ERRORLEVEL%";
ofs << "\n\tEXIT /B !BUILD_ERRORLEVEL!";
ofs << "\n)";
ofs << "\n\n)";
ofs << "\n\necho %ESC%[92mBUILD SUCCEEDED!%ESC%[0m";
ofs << "\n\n:END";
ofs << "\nENDLOCAL ";
ofs.close(); ofs.close();
ofs.clear(); ofs.clear();

Loading…
Cancel
Save