This commit is contained in:
Imbus 2026-01-17 06:13:49 +01:00
commit 2628afadcc
9 changed files with 112 additions and 0 deletions

19
.clang-format Normal file
View file

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

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build

11
CMakeLists.txt Normal file
View file

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

11
app/CMakeLists.txt Normal file
View file

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

17
app/main.c Normal file
View file

@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <add/add.h>
int main(int argc, char **argv) {
if (argc != 3) {
fprintf(stderr, "usage: %s <a> <b>\n", argv[0]);
return 1;
}
int a = atoi(argv[1]);
int b = atoi(argv[2]);
printf("%d\n", add(a, b));
return 0;
}

31
libadd/CMakeLists.txt Normal file
View file

@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(add_static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
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)

View file

@ -0,0 +1,3 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/addTargets.cmake")

14
libadd/include/add/add.h Normal file
View file

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

5
libadd/src/add.c Normal file
View file

@ -0,0 +1,5 @@
#include <add/add.h>
int add(int a, int b) {
return a + b;
}