Skip to content

Commit 10da89c

Browse files
committed
Init Simple Conan_CMake Example
1 parent 6f1db2d commit 10da89c

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(compressor C)
3+
4+
find_package(ZLIB REQUIRED)
5+
6+
add_executable(${PROJECT_NAME} src/main.c)
7+
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[project]
2+
description = "A simple project showing how to use conan with CPPython"
3+
name = "cppython-conan-cmake-simple"
4+
version = "1.0.0"
5+
6+
license = {text = "MIT"}
7+
8+
authors = [
9+
{name = "Synodic Software", email = "contact@synodic.software"},
10+
]
11+
12+
requires-python = ">=3.13"
13+
14+
dependencies = [
15+
"cppython>=0.1.0",
16+
]
17+
18+
[tool.cppython]
19+
generator-name = "cmake"
20+
provider-name = "conan"
21+
22+
install-path = "install"
23+
24+
dependencies = [
25+
"zlib>=1.2.11",
26+
]
27+
28+
[tool.cppython.generator]
29+
30+
[tool.cppython.provider]
31+
32+
[tool.pdm]
33+
distribution = false
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
#include <zlib.h>
6+
7+
int main(void) {
8+
char buffer_in [256] = {"Conan is a MIT-licensed, Open Source package manager for C and C++ development, "
9+
"allowing development teams to easily and efficiently manage their packages and "
10+
"dependencies across platforms and build systems."};
11+
char buffer_out [256] = {0};
12+
13+
z_stream defstream;
14+
defstream.zalloc = Z_NULL;
15+
defstream.zfree = Z_NULL;
16+
defstream.opaque = Z_NULL;
17+
defstream.avail_in = (uInt) strlen(buffer_in);
18+
defstream.next_in = (Bytef *) buffer_in;
19+
defstream.avail_out = (uInt) sizeof(buffer_out);
20+
defstream.next_out = (Bytef *) buffer_out;
21+
22+
deflateInit(&defstream, Z_BEST_COMPRESSION);
23+
deflate(&defstream, Z_FINISH);
24+
deflateEnd(&defstream);
25+
26+
printf("Uncompressed size is: %lu\n", strlen(buffer_in));
27+
printf("Compressed size is: %lu\n", defstream.total_out);
28+
29+
printf("ZLIB VERSION: %s\n", zlibVersion());
30+
31+
return EXIT_SUCCESS;
32+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""TODO"""
2+
3+
import subprocess
4+
5+
from typer.testing import CliRunner
6+
7+
from cppython.console.entry import app
8+
9+
pytest_plugins = ['tests.fixtures.example']
10+
11+
12+
class TestVcpkgCMake:
13+
"""Test project variation of vcpkg and CMake"""
14+
15+
@staticmethod
16+
def test_simple(example_runner: CliRunner) -> None:
17+
"""Simple project"""
18+
result = example_runner.invoke(
19+
app,
20+
[
21+
'install',
22+
],
23+
)
24+
25+
assert result.exit_code == 0, result.output
26+
27+
# Run the CMake configuration command
28+
cmake_result = subprocess.run(['cmake', '--preset=default'], capture_output=True, text=True, check=False)
29+
30+
assert cmake_result.returncode == 0, f'CMake configuration failed: {cmake_result.stderr}'
31+
32+
# Run the CMake build command
33+
build_result = subprocess.run(['cmake', '--build', 'build'], capture_output=True, text=True, check=False)
34+
35+
assert build_result.returncode == 0, f'CMake build failed: {build_result.stderr}'
36+
assert 'Build finished successfully' in build_result.stdout, 'CMake build did not finish successfully'
37+
38+
# Execute the built program and verify the output
39+
program_result = subprocess.run(['build/HelloWorld'], capture_output=True, text=True, check=False)
40+
41+
assert program_result.returncode == 0, f'Program execution failed: {program_result.stderr}'
42+
43+
assert 'Hello, World!' in program_result.stdout, 'Program output did not match expected output'

0 commit comments

Comments
 (0)