From 34e8e7421a5efc83c8fcbfb6c004b5d836652197 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Mon, 12 Aug 2024 17:48:52 +0200 Subject: [PATCH] up build windows --- .gitignore | 9 +++- .vscode/c_cpp_properties.json | 21 -------- .vscode/launch.json | 60 ---------------------- .vscode/tasks.json | 32 ------------ build.cpp | 16 +++--- build.hpp | 96 +++++++++++++++++++++++++---------- src/canvas/Tree.cpp | 6 +-- 7 files changed, 86 insertions(+), 154 deletions(-) delete mode 100644 .vscode/c_cpp_properties.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 22c7d9a..a206d9b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,11 @@ obj/ raylib/ build treender -.vscode/settings.json \ No newline at end of file +.vscode/ +*.exe +*.pdb +*.lib +.vs/ +*.sln +*.vcxproj* +Console*/ \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 6793f7b..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/inc", - "${workspaceFolder}/raylib/src" - ], - "defines": [ - "GRAPHICS_API_OPENGL_33", - "PLATFORM_DESKTOP", - "_GNU_SOURCE" - ], - "compilerPath": "/usr/bin/gcc", - "cStandard": "c23", - "cppStandard": "gnu++23", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 3ec753d..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Debug", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/treender", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } - ], - "preLaunchTask": "build-deb" - }, - { - "name": "Debug builder", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/build", - "args": [ - "build" - ], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - }, - { - "description": "Set Disassembly Flavor to Intel", - "text": "-gdb-set disassembly-flavor intel", - "ignoreFailures": true - } - ], - "preLaunchTask": "build-builder" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index d2d30bf..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "type": "shell", - "command": "./build", - "args": [ - "run" - ] - }, - { - "label": "build-deb", - "type": "shell", - "command": "./build", - "args": [ - "build" - ] - }, - { - "label": "build-builder", - "type": "shell", - "command": "g++", - "args": [ - "build.cpp", - "-ggdb", - "-o", - "build" - ] - } - ] -} \ No newline at end of file diff --git a/build.cpp b/build.cpp index 833b101..29e1292 100644 --- a/build.cpp +++ b/build.cpp @@ -1,15 +1,14 @@ - -#ifdef _WIN32 #define EXT_LINK -#endif - #define EXT_INC #include "build.hpp" #include #ifdef _WIN32 -std::vector LINK = {"-lopengl32", "-lkernel32", "-luser32", "-lshell32","-lwinmm","-lgdi32"}; +std::vector LINK = {"-lopengl32", "-lkernel32", "-luser32", "-lshell32", "-lwinmm", "-lgdi32"}; +#else +std::vector LINK = {}; #endif + std::vector RAYINCLUDE = {"-Iraylib/src", "-Iraylib/src/external/glfw/include", "-Iraylib/src/external/glfw/deps/mingw"}; std::filesystem::path RAYLIB_DIR = "raylib"; @@ -48,7 +47,7 @@ void compile_raylib_dir() { command[src_loc] = src.string(); command[obj_loc] = out.string(); - nob_cmd_run_sync(command); + run_command(command); } } } @@ -84,7 +83,7 @@ int main(int argc, char const *argv[]) if (!std::filesystem::is_directory(RAYLIB_DIR)) { command = {"git", "clone", "--depth", "1", "--branch", "5.0", "https://github.com/raysan5/raylib.git"}; - nob_cmd_run_sync(command); + run_command(command); std::filesystem::remove_all("raylib/.git"); } @@ -110,8 +109,7 @@ int main(int argc, char const *argv[]) if (run) { - command = {"./" + BUILD_FILE.string()}; - nob_cmd_run_sync(command); + run_main(); } return 0; } diff --git a/build.hpp b/build.hpp index 39859ac..04b6b85 100644 --- a/build.hpp +++ b/build.hpp @@ -7,10 +7,12 @@ #include #include +// #define EXT_ARGS // #define EXT_LINK // #define EXT_INC // #define EXT_OBJ -// #define NO_Werror +// #define Werror +// #define Wextra std::filesystem::path OBJ_DIR = "obj"; std::filesystem::path INC_DIR = "inc"; @@ -89,7 +91,7 @@ void print_command(std::vector &arguments) printf("\n"); } -bool nob_cmd_run_sync(std::vector &arguments) +bool run_command(std::vector &arguments) { print_command(arguments); std::string command = ""; @@ -115,46 +117,58 @@ bool check_if_rebuild(const std::filesystem::path &org_path, const std::filesyst return file_time_one > file_time_two; } +bool try_remove(std::filesystem::path path) +{ + try + { + std::filesystem::remove("old_build"); + return true; + } + catch (const std::exception &e) + { + } + return false; +} + bool rebuild_my_self(std::filesystem::path src_path, int argc, const char **exec_path) { std::filesystem::path exec = exec_path[0]; + try_remove("old_build"); + if (!check_if_rebuild(src_path, exec) && !check_if_rebuild(__FILE__, exec)) return false; -#ifndef _WIN32 + std::filesystem::rename(exec, "old_build"); + std::vector input; for (int i = 0; i < argc; ++i) input.push_back(exec_path[i]); - std::vector comand = {cpp_compiler, src_path.string(), "-o", exec_path[0], "-g"}; - if (!nob_cmd_run_sync(comand)) - return false; - - if (!nob_cmd_run_sync(input)) + std::vector comand = {cpp_compiler, src_path.string(), "-o", exec_path[0], "-ggdb"}; + if (!run_command(comand)) return false; printf("rebuild\n"); -#else - pick_color(Color::red); - printf("rebuild me\n"); - pick_color(Color::white); -#endif + + if (!run_command(input)) + return false; + return true; } -struct nob_directory +struct all_in_directory { std::vector files; std::vector dirs; }; -nob_directory get_all_files_in_dir(std::filesystem::path directory_path) +all_in_directory get_all_files_in_dir(std::filesystem::path directory_path) { namespace fs = std::filesystem; - nob_directory dir; + all_in_directory dir; if (!fs::is_directory(directory_path)) return dir; @@ -223,8 +237,8 @@ int compile_src_dir(std::vector ext_inc) int compile_src_dir() #endif { - nob_directory src_dir = get_all_files_in_dir(SRC_DIR); - nob_directory obj_dir; + all_in_directory src_dir = get_all_files_in_dir(SRC_DIR); + all_in_directory obj_dir; for (auto &&i : src_dir.dirs) { @@ -232,7 +246,7 @@ int compile_src_dir() } std::unordered_set modified_heders; - nob_directory inc_dir = get_all_files_in_dir(INC_DIR); + all_in_directory inc_dir = get_all_files_in_dir(INC_DIR); for (size_t i = 0; i < inc_dir.files.size(); i++) { @@ -260,7 +274,10 @@ int compile_src_dir() command.push_back("-I" + INC_DIR.string()); command.push_back("-std=c++23"); command.push_back("-Wall"); -#ifndef NO_Werror +#ifdef Wextra + command.push_back("-Wextra"); +#endif +#ifdef Werror command.push_back("-Werror"); #endif @@ -292,7 +309,7 @@ int compile_src_dir() { command[src_loc] = i.string(); command[obj_loc] = out.string(); - if (!nob_cmd_run_sync(command)) + if (!run_command(command)) return -1; build = 1; @@ -302,12 +319,12 @@ int compile_src_dir() } #if defined(EXT_LINK) -void compile_obj_dir(std::vector ext_link) +bool compile_obj_dir(std::vector ext_link) #else -void compile_obj_dir() +bool compile_obj_dir() #endif { - nob_directory obj_dir = get_all_files_in_dir(OBJ_DIR); + all_in_directory obj_dir = get_all_files_in_dir(OBJ_DIR); command.clear(); command.push_back(cpp_compiler); @@ -324,7 +341,7 @@ void compile_obj_dir() command.insert(command.end(), ext_link.begin(), ext_link.end()); #endif - nob_cmd_run_sync(command); + return run_command(command); } #if defined(EXT_OBJ) && defined(EXT_INC) @@ -337,7 +354,7 @@ void build_as_one(std::vector ext_inc) void build_as_one() #endif { - nob_directory src_dir = get_all_files_in_dir(SRC_DIR); + all_in_directory src_dir = get_all_files_in_dir(SRC_DIR); command.clear(); command.push_back(cpp_compiler); @@ -352,7 +369,10 @@ void build_as_one() command.push_back("-I" + INC_DIR.string()); command.push_back("-std=c++23"); command.push_back("-Wall"); -#ifndef NO_Werror +#ifdef Wextra + command.push_back("-Wextra"); +#endif +#ifdef Werror command.push_back("-Werror"); #endif for (auto &&i : src_dir.files) @@ -363,5 +383,25 @@ void build_as_one() #ifdef EXT_OBJ command.insert(command.end(), ext_obj.begin(), ext_obj.end()); #endif - nob_cmd_run_sync(command); + run_command(command); +} + +#ifdef EXT_ARGS +bool run_main(std::vector ext_args) +#else +bool run_main() +#endif +{ + command.clear(); +#ifndef _WIN32 + command.push_back("./" + BUILD_FILE.string()); +#else + command.push_back(BUILD_FILE.string()); +#endif + +#ifdef EXT_ARGS + command.insert(command.end(), ext_args.begin(), ext_args.end()); +#endif + + return run_command(command); } \ No newline at end of file diff --git a/src/canvas/Tree.cpp b/src/canvas/Tree.cpp index 279e2c4..e17a28c 100644 --- a/src/canvas/Tree.cpp +++ b/src/canvas/Tree.cpp @@ -60,13 +60,13 @@ void Tree::drawBranch() for (size_t i = 0; i < branches[arg.dep].numOfBranches; i++) { float newAngle = arg.angleDeg - 90 + (degres * (i + 1)); - draw_calls.push_back((DrawArgs){next, newAngle, arg.lenghth * next_len, arg.dep + 1}); + draw_calls.push_back({ next, newAngle, arg.lenghth * next_len, arg.dep + 1 }); } } void Tree::drawTree() { - draw_calls.push_back((DrawArgs){start, 0, (float)size / 4, 1}); + draw_calls.push_back({start, 0, (float)size / 4, 1}); while (!draw_calls.empty()) { @@ -82,7 +82,7 @@ void Tree::generateBranches() uint8_t r = GetRandomValue(0, 255); uint8_t g = GetRandomValue(0, 255); uint8_t b = GetRandomValue(0, 255); - branches[i].color = (Color){r, g, b, 255}; + branches[i].color = {r, g, b, 255}; branches[i].numOfBranches = GetRandomValue(1, 3);