Initial commit

This commit is contained in:
Riley 2025-05-13 23:14:45 +00:00
commit 605a30e2f8
13 changed files with 240 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
build/*
.vscode/*

View file

@ -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
}

View file

@ -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
}
}
]
}

View file

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild"
}

View file

@ -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": []
}
]
}

23
README.md Normal file
View file

@ -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`

20
build.bat Normal file
View file

@ -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

12
build.sh Normal file
View file

@ -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..."

38
conanfile.py Normal file
View file

@ -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()

7
docs/default Normal file
View file

@ -0,0 +1,7 @@
[settings]
os=Windows
arch=x86_64
compiler=gcc
compiler.version=13
compiler.libcxx=libstdc++11
build_type=Release

23
meson.build Normal file
View file

@ -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'))

0
src/include/.gitkeep Normal file
View file

51
src/main.c Normal file
View file

@ -0,0 +1,51 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#elif __linux__ || __APPLE__
#include <unistd.h>
#endif
#include <zlib.h>
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;
}