From c3cbbda2a0e18d8913c33b9ac9e4a2876e3ca5af Mon Sep 17 00:00:00 2001 From: Riley Date: Fri, 9 May 2025 21:01:36 -0500 Subject: [PATCH] add debug mode support --- .vscode-example/c_cpp_properties.json | 26 ++++++++++++++++++++++++++ .vscode-example/launch.json | 16 ++++++++++++++++ .vscode-example/settings.json | 3 +++ .vscode-example/tasks.json | 12 ++++++++++++ build.bat | 19 +++++++++++++++++-- build.sh | 11 +++++++++-- meson.build | 11 +++++++++-- 7 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 .vscode-example/c_cpp_properties.json create mode 100644 .vscode-example/launch.json create mode 100644 .vscode-example/settings.json create mode 100644 .vscode-example/tasks.json diff --git a/.vscode-example/c_cpp_properties.json b/.vscode-example/c_cpp_properties.json new file mode 100644 index 0000000..1ab03f7 --- /dev/null +++ b/.vscode-example/c_cpp_properties.json @@ -0,0 +1,26 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.22621.0", + "compilerPath": "cl.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "windows-msvc-x64", + "configurationProvider": "mesonbuild.mesonbuild", + "compileCommands": [ + "${workspaceFolder}/build/meson-src/compile_commands.json" + ], + "mergeConfigurations": true + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode-example/launch.json b/.vscode-example/launch.json new file mode 100644 index 0000000..678e61b --- /dev/null +++ b/.vscode-example/launch.json @@ -0,0 +1,16 @@ +{ + // 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": [ + { + "cwd": "${workspaceRoot}", + "type": "cppvsdbg", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/build/meson-src/main.exe", + "preLaunchTask": "build" + } + ] +} \ No newline at end of file diff --git a/.vscode-example/settings.json b/.vscode-example/settings.json new file mode 100644 index 0000000..b528881 --- /dev/null +++ b/.vscode-example/settings.json @@ -0,0 +1,3 @@ +{ + "C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild" +} \ No newline at end of file diff --git a/.vscode-example/tasks.json b/.vscode-example/tasks.json new file mode 100644 index 0000000..2c70dab --- /dev/null +++ b/.vscode-example/tasks.json @@ -0,0 +1,12 @@ +// filepath: c:\Users\Riley\OneDrive\Documents\Code\C\Conan-C\.vscode\tasks.json +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "${workspaceFolder}/build.bat debug", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/build.bat b/build.bat index bfda0ec..fcce19c 100644 --- a/build.bat +++ b/build.bat @@ -1,5 +1,20 @@ +@echo off +setlocal enabledelayedexpansion + +set DEBUG=release +if "%1" == "debug" set DEBUG=debug + conan install . --output-folder=build --build=missing cd build -meson setup --native-file conan_meson_native.ini .. meson-src + +meson setup -Dbuildtype=%DEBUG% --native-file conan_meson_native.ini .. meson-src --reconfigure meson compile -C meson-src -meson-src\main.exe \ No newline at end of file + +REM Only run the executable if it exists +if exist meson-src\main.exe ( + meson-src\main.exe +) else ( + echo "Executable not found. Build might have failed." +) + +pause \ No newline at end of file diff --git a/build.sh b/build.sh index ea02ffc..1d88ab1 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,12 @@ +if [ "$1" = "debug" ]; then + BUILD_TYPE=debug +else + BUILD_TYPE=release +fi + conan install . --output-folder=build --build=missing cd build -meson setup --native-file conan_meson_native.ini .. meson-src +meson setup --native-file conan_meson_native.ini .. meson-src -Dbuildtype=$BUILD_TYPE meson compile -C meson-src -./meson-src/main \ No newline at end of file +./meson-src/main +read -p "Press enter to continue..." diff --git a/meson.build b/meson.build index d1928ff..2f9faba 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,18 @@ project('tutorial', 'cpp') CC = meson.get_compiler('cpp') +target_name = 'main' zlib = dependency('zlib', version : '1.2.11', static: true, required: true) -target_name = 'main' - files = files('src/main.cpp') +if get_option('buildtype') == 'debug' + if CC.has_argument('-fsanitize=address') and CC.has_link_argument('-fsanitize=address') + add_project_arguments('-fsanitize=address', '-fno-omit-frame-pointer', language: 'cpp') + add_project_link_arguments('-fsanitize=address', language: 'cpp') + endif + add_project_arguments('-DDEBUG', language: 'cpp') +endif + executable(target_name, files, dependencies: [zlib], include_directories: include_directories('src/include')) \ No newline at end of file