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..2a57bf9 --- /dev/null +++ b/.vscode-example/launch.json @@ -0,0 +1,23 @@ +{ + // 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", + "logging": { + "engineLogging": true, + "trace": true, + "traceResponse": true + } + + } + ] + +} 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 855fbcd..bcff0c1 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,23 @@ project('tutorial', 'c') CC = meson.get_compiler('c') +target_name = 'main' + zlib = dependency('zlib', version : '1.2.11', static: true, required: true) -target_name = 'main' files = files('src/main.c') -executable(target_name, files, dependencies: [zlib], include_directories: include_directories('src/include')) \ No newline at end of file +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: 'c') + add_project_link_arguments('-fsanitize=address', language: 'c') + endif + add_project_arguments('-DDEBUG', language: 'c') +endif + + +executable(target_name, files, dependencies: [zlib], include_directories: include_directories('src/include')) + + diff --git a/src/main.c b/src/main.c index 0abb1b5..4bd0dfb 100644 --- a/src/main.c +++ b/src/main.c @@ -1,9 +1,22 @@ #include #include #include +#ifdef _WIN32 +#include +#elif __linux__ || __APPLE__ +#include +#endif #include +void sleep_ms(int milliseconds) { +#ifdef _WIN32 + Sleep(milliseconds); +#elif __linux__ || __APPLE__ + usleep(milliseconds * 1000); // Convert milliseconds to microseconds +#endif +} + int main(void) { char buffer_in [256] = {"Conan is a MIT-licensed, Open Source package manager for C and C++ development " "for C and C++ development, allowing development teams to easily and efficiently " @@ -23,6 +36,12 @@ int main(void) { deflate(&defstream, Z_FINISH); deflateEnd(&defstream); + unsigned long long compressed_size = sizeof(buffer_out) - defstream.avail_out; + + int x = 1-1; + + + printf("Uncompressed size is: %lu\n", strlen(buffer_in)); printf("Compressed size is: %lu\n", strlen(buffer_out));