commit 605a30e2f826c61cc8708e0066f3cc6f886ce0d9 Author: Riley Date: Tue May 13 23:14:45 2025 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..367f77e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/* +.vscode/* \ No newline at end of file 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/README.md b/README.md new file mode 100644 index 0000000..6566a11 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Conan C + +This is a Conan / Meson template. It's based on some online tutorials. + +I made this when I wanted to make more C / C++ projects but with a more "pythonic" build system. + +# Setup + +## Linux / Windows + +1. Install CMake +2. Install Meson +3. Install GCC (UCRT MSYS2) + +## Windows +4. Edit `~\.conan2\profiles\default` to match [docs/default](docs/default) + +## Linux +4. If you run linux you can probably figure this out. It should work mostly out of the box. + +## Both Again +5. Run `build.bat` or `build.sh` respectively. +6. Edit your intellisense to read the compile_commands from `${workspaceFolder}/build/meson-src/compile_commands.json` \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..fcce19c --- /dev/null +++ b/build.bat @@ -0,0 +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 -Dbuildtype=%DEBUG% --native-file conan_meson_native.ini .. meson-src --reconfigure +meson compile -C meson-src + +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 new file mode 100644 index 0000000..1d88ab1 --- /dev/null +++ b/build.sh @@ -0,0 +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 -Dbuildtype=$BUILD_TYPE +meson compile -C meson-src +./meson-src/main +read -p "Press enter to continue..." diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..68509d3 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,38 @@ +from conan import ConanFile +from conan.tools.meson import MesonToolchain, Meson +from conan.tools.gnu import PkgConfigDeps + + +class helloConan(ConanFile): + name = "hello" + version = "1.0" + package_type = "application" + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "meson.build", "src/*" + + + + def layout(self): + self.folders.build = "build" + + def requirements(self): + self.requires("zlib/1.2.11") + + def generate(self): + deps = PkgConfigDeps(self) + deps.generate() + tc = MesonToolchain(self) + tc.generate() + + def build(self): + meson = Meson(self) + meson.configure() + meson.build() + + def package(self): + meson = Meson(self) + meson.install() diff --git a/docs/default b/docs/default new file mode 100644 index 0000000..bd29125 --- /dev/null +++ b/docs/default @@ -0,0 +1,7 @@ +[settings] +os=Windows +arch=x86_64 +compiler=gcc +compiler.version=13 +compiler.libcxx=libstdc++11 +build_type=Release \ No newline at end of file diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..bcff0c1 --- /dev/null +++ b/meson.build @@ -0,0 +1,23 @@ +project('tutorial', 'c') + +CC = meson.get_compiler('c') +target_name = 'main' + + +zlib = dependency('zlib', version : '1.2.11', static: true, required: true) + + +files = files('src/main.c') + +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/include/.gitkeep b/src/include/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..4bd0dfb --- /dev/null +++ b/src/main.c @@ -0,0 +1,51 @@ +#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 " + "manage their packages and dependencies across platforms and build systems."}; + char buffer_out [256] = {0}; + + z_stream defstream; + defstream.zalloc = Z_NULL; + defstream.zfree = Z_NULL; + defstream.opaque = Z_NULL; + defstream.avail_in = (uInt) strlen(buffer_in); + defstream.next_in = (Bytef *) buffer_in; + defstream.avail_out = (uInt) sizeof(buffer_out); + defstream.next_out = (Bytef *) buffer_out; + + deflateInit(&defstream, Z_BEST_COMPRESSION); + 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)); + + printf("ZLIB VERSION: %s\n", zlibVersion()); + + return EXIT_SUCCESS; +} \ No newline at end of file