This commit is contained in:
Arti Zirk 2021-07-12 17:22:42 +03:00
commit 84844eeab2
9 changed files with 77 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

19
CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(Hello VERSION 1.0)
# add a lib
add_subdirectory(alib)
add_executable(Hello main.c)
target_link_libraries(Hello PUBLIC alib)
# Version number thing
configure_file(config.h.in config.h)
target_include_directories(Hello PUBLIC
${PROJECT_BINARY_DIR}
)
install(TARGETS Hello DESTINATION bin)
install(FILES ${PROJECT_BINARY_DIR}/config.h DESTINATION include)

23
CMakePresets.json Normal file
View File

@ -0,0 +1,23 @@
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 10,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default"
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
]
}

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# build
Use preset from `CMakePresets.json`
cmake -S . --preset=default
And then build
cmake --build build/default

7
alib/CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
add_library(alib calc.c)
target_include_directories(alib
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)
install(TARGETS alib DESTINATION lib)
install(FILES calc.h DESTINATION include)

5
alib/calc.c Normal file
View File

@ -0,0 +1,5 @@
#include "calc.h"
int docalc() {
return 2;
}

1
alib/calc.h Normal file
View File

@ -0,0 +1 @@
int docalc();

3
config.h.in Normal file
View File

@ -0,0 +1,3 @@
// the configured options and settings for Hello
#define Hello_VERSION_MAJOR @Hello_VERSION_MAJOR@
#define Hello_VERSION_MINOR @Hello_VERSION_MINOR@

9
main.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdio.h>
#include "config.h"
#include "calc.h"
int main() {
printf("Version: %d.%d\n", Hello_VERSION_MAJOR, Hello_VERSION_MINOR);
printf("Hello World; %d\n", docalc());
return 0;
}