From 2628afadcc0e5fa007351805a557fca69eb08d53 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 17 Jan 2026 06:13:49 +0100 Subject: [PATCH] Initial --- .clang-format | 19 +++++++++++++++++++ .gitignore | 1 + CMakeLists.txt | 11 +++++++++++ app/CMakeLists.txt | 11 +++++++++++ app/main.c | 17 +++++++++++++++++ libadd/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ libadd/addConfig.cmake.in | 3 +++ libadd/include/add/add.h | 14 ++++++++++++++ libadd/src/add.c | 5 +++++ 9 files changed, 112 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 app/CMakeLists.txt create mode 100644 app/main.c create mode 100644 libadd/CMakeLists.txt create mode 100644 libadd/addConfig.cmake.in create mode 100644 libadd/include/add/add.h create mode 100644 libadd/src/add.c diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7030cd1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,19 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ColumnLimit: 120 +AllowShortLoopsOnASingleLine: true +AllowShortFunctionsOnASingleLine: false +AlwaysBreakTemplateDeclarations: true +BreakConstructorInitializers: BeforeComma +AlignConsecutiveDeclarations: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: true +AllowShortCaseLabelsOnASingleLine: true +SeparateDefinitionBlocks: Always diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8f0d8ce --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) + +project(add_project + VERSION 1.0.0 + LANGUAGES C +) + +include(GNUInstallDirs) + +add_subdirectory(libadd) +add_subdirectory(app) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt new file mode 100644 index 0000000..1e43704 --- /dev/null +++ b/app/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(add_app + main.c +) + +target_link_libraries(add_app + PRIVATE add::add +) + +install(TARGETS add_app + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/app/main.c b/app/main.c new file mode 100644 index 0000000..ece80bb --- /dev/null +++ b/app/main.c @@ -0,0 +1,17 @@ +#include +#include + +#include + +int main(int argc, char **argv) { + if (argc != 3) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + int a = atoi(argv[1]); + int b = atoi(argv[2]); + + printf("%d\n", add(a, b)); + return 0; +} diff --git a/libadd/CMakeLists.txt b/libadd/CMakeLists.txt new file mode 100644 index 0000000..dc27b8f --- /dev/null +++ b/libadd/CMakeLists.txt @@ -0,0 +1,31 @@ +add_library(add_shared SHARED + src/add.c +) + +add_library(add_static STATIC + src/add.c +) + +target_include_directories(add_shared + PUBLIC + $ + $ +) + +target_include_directories(add_static + PUBLIC + $ + $ +) + +set_target_properties(add_shared PROPERTIES + OUTPUT_NAME add + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +) + +set_target_properties(add_static PROPERTIES + OUTPUT_NAME add +) + +add_library(add::add ALIAS add_shared) diff --git a/libadd/addConfig.cmake.in b/libadd/addConfig.cmake.in new file mode 100644 index 0000000..c1cffb7 --- /dev/null +++ b/libadd/addConfig.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/addTargets.cmake") diff --git a/libadd/include/add/add.h b/libadd/include/add/add.h new file mode 100644 index 0000000..88e6119 --- /dev/null +++ b/libadd/include/add/add.h @@ -0,0 +1,14 @@ +#ifndef ADD_ADD_H +#define ADD_ADD_H + +#ifdef __cplusplus +extern "C" { +#endif + +int add(int a, int b); + +#ifdef __cplusplus +} +#endif + +#endif /* ADD_ADD_H */ diff --git a/libadd/src/add.c b/libadd/src/add.c new file mode 100644 index 0000000..6e28d05 --- /dev/null +++ b/libadd/src/add.c @@ -0,0 +1,5 @@ +#include + +int add(int a, int b) { + return a + b; +}