Skip to content

Commit 2ce8d66

Browse files
committed
Consumer Example
1 parent c9a47a3 commit 2ce8d66

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(mathutils VERSION 1.0.0 LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
find_package(fmt REQUIRED)
9+
10+
# Create the library
11+
add_library(mathutils src/mathutils.cpp)
12+
13+
# Set up include directories
14+
target_include_directories(mathutils
15+
PUBLIC
16+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
17+
$<INSTALL_INTERFACE:include>
18+
)
19+
20+
# Link dependencies
21+
target_link_libraries(mathutils PUBLIC fmt::fmt)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
namespace mathutils
4+
{
5+
/**
6+
* Add two numbers and return the result with formatted output
7+
* @param a First number
8+
* @param b Second number
9+
* @return Sum of a and b
10+
*/
11+
double add(double a, double b);
12+
13+
/**
14+
* Multiply two numbers and return the result with formatted output
15+
* @param a First number
16+
* @param b Second number
17+
* @return Product of a and b
18+
*/
19+
double multiply(double a, double b);
20+
21+
/**
22+
* Print a formatted calculation result
23+
* @param operation The operation performed
24+
* @param a First operand
25+
* @param b Second operand
26+
* @param result The result of the operation
27+
*/
28+
void print_result(const char *operation, double a, double b, double result);
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[project]
2+
description = "A simple C++ library example using conan with CPPython"
3+
name = "mathutils"
4+
version = "1.0.0"
5+
6+
license = { text = "MIT" }
7+
8+
authors = [{ name = "Synodic Software", email = "contact@synodic.software" }]
9+
10+
requires-python = ">=3.13"
11+
12+
dependencies = ["cppython[conan, cmake, git]>=0.9.0"]
13+
14+
15+
[tool.cppython]
16+
install-path = "install"
17+
18+
dependencies = ["fmt>=11.2.0"]
19+
20+
[tool.cppython.generators.cmake]
21+
22+
[tool.cppython.providers.conan]
23+
24+
[tool.pdm]
25+
distribution = false
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "mathutils/mathutils.h"
2+
#include <fmt/core.h>
3+
#include <fmt/color.h>
4+
5+
namespace mathutils
6+
{
7+
double add(double a, double b)
8+
{
9+
double result = a + b;
10+
print_result("addition", a, b, result);
11+
return result;
12+
}
13+
14+
double multiply(double a, double b)
15+
{
16+
double result = a * b;
17+
print_result("multiplication", a, b, result);
18+
return result;
19+
}
20+
21+
void print_result(const char *operation, double a, double b, double result)
22+
{
23+
fmt::print(fg(fmt::terminal_color::green),
24+
"MathUtils {}: {} + {} = {}\n",
25+
operation, a, b, result);
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(MathUtilsConsumer LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
find_package(mathutils REQUIRED)
9+
10+
add_executable(consumer main.cpp)
11+
target_link_libraries(consumer PRIVATE mathutils::mathutils)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <mathutils/mathutils.h>
2+
3+
int main()
4+
{
5+
// Test the mathutils library
6+
double result1 = mathutils::add(5.0, 3.0);
7+
double result2 = mathutils::multiply(4.0, 2.5);
8+
9+
return 0;
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[project]
2+
description = "A test consumer for the mathutils library"
3+
name = "mathutils-consumer"
4+
version = "1.0.0"
5+
6+
license = { text = "MIT" }
7+
8+
authors = [{ name = "Synodic Software", email = "contact@synodic.software" }]
9+
10+
requires-python = ">=3.13"
11+
12+
dependencies = ["cppython[conan, cmake, git]>=0.9.0"]
13+
14+
15+
[tool.cppython]
16+
install-path = "install"
17+
18+
dependencies = ["mathutils==1.0.0"]
19+
20+
[tool.cppython.generators.cmake]
21+
22+
[tool.cppython.providers.conan]
23+
24+
[tool.pdm]
25+
distribution = false

0 commit comments

Comments
 (0)