From fd5958887cc203d648daa5f170e0d886da934da8 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sun, 9 Jul 2023 11:42:44 +0900 Subject: [PATCH] create new project --- .gitignore | 1 + CMakeLists.txt | 13 +++++++++++++ Dockerfile | 10 ++++++++++ cmake/git_hash.cmake | 19 +++++++++++++++++++ core/CMakeLists.txt | 9 +++++++++ core/version.cc | 10 ++++++++++ core/version.hh | 8 ++++++++ docker-compose.yml | 7 +++++++ iface/CMakeLists.txt | 10 ++++++++++ iface/version.cc | 13 +++++++++++++ iface/version.hh | 8 ++++++++ main.cc | 13 +++++++++++++ 12 files changed, 121 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Dockerfile create mode 100644 cmake/git_hash.cmake create mode 100644 core/CMakeLists.txt create mode 100644 core/version.cc create mode 100644 core/version.hh create mode 100644 docker-compose.yml create mode 100644 iface/CMakeLists.txt create mode 100644 iface/version.cc create mode 100644 iface/version.hh create mode 100644 main.cc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..39b5a90 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.20) +project(nf7 C CXX) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include(cmake/git_hash.cmake) + +add_subdirectory(iface) +add_subdirectory(core) + +add_executable(nf7) +target_sources(nf7 PRIVATE main.cc) +target_link_libraries(nf7 PRIVATE nf7_iface nf7_core) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a561e90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.14 + +RUN apk add --no-cache \ + cmake \ + gdb \ + git \ + g++ \ + make + +WORKDIR /repo diff --git a/cmake/git_hash.cmake b/cmake/git_hash.cmake new file mode 100644 index 0000000..71d1459 --- /dev/null +++ b/cmake/git_hash.cmake @@ -0,0 +1,19 @@ +set(dir "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(out "${dir}/git_hash.hh") + +find_program(SH sh REQUIRED) + +make_directory("${dir}") +add_custom_command( + COMMAND ${SH} -c "echo constexpr const char\* GIT_HASH = \\\"`git rev-parse --short HEAD``git diff --quiet && echo \\\*`\\\"\\; > ${out}" + OUTPUT "${out}" + DEPENDS "${PROJECT_SOURCE_DIR}/.git/HEAD" + VERBATIM +) + +add_library(git_hash INTERFACE) +target_sources(git_hash PUBLIC "${out}") +target_include_directories(git_hash INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) + +unset(out) +unset(dir) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt new file mode 100644 index 0000000..b94affd --- /dev/null +++ b/core/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(nf7_core) +target_link_libraries(nf7_core PRIVATE git_hash nf7_iface) + +target_sources(nf7_core + PRIVATE + version.cc + PUBLIC + version.hh +) diff --git a/core/version.cc b/core/version.cc new file mode 100644 index 0000000..73fdc38 --- /dev/null +++ b/core/version.cc @@ -0,0 +1,10 @@ +// No copyright +#include "core/version.hh" + +#include "generated/git_hash.hh" + +namespace nf7::core { + +const char* version() noexcept { return GIT_HASH; } + +} // namespace nf7::core diff --git a/core/version.hh b/core/version.hh new file mode 100644 index 0000000..d2b8d90 --- /dev/null +++ b/core/version.hh @@ -0,0 +1,8 @@ +// No copyright +#pragma once + +namespace nf7::core { + +const char* version() noexcept; + +} // namespace nf7::core diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4c4c804 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3' + +services: + dev: + build: . + volumes: + - ./:/repo/ diff --git a/iface/CMakeLists.txt b/iface/CMakeLists.txt new file mode 100644 index 0000000..65c2c37 --- /dev/null +++ b/iface/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(nf7_iface) +target_include_directories(nf7_iface PUBLIC ${PROJECT_SOURCE_DIR}) +target_link_libraries(nf7_iface PRIVATE git_hash) + +target_sources(nf7_iface + PRIVATE + version.cc + PUBLIC + version.hh +) diff --git a/iface/version.cc b/iface/version.cc new file mode 100644 index 0000000..ce2dbc7 --- /dev/null +++ b/iface/version.cc @@ -0,0 +1,13 @@ +// No copyright +#include "iface/version.hh" + +#include + +#include "generated/git_hash.hh" + + +namespace nf7::iface { + +const char* version() noexcept { return GIT_HASH; } + +} // namespace nf7::iface diff --git a/iface/version.hh b/iface/version.hh new file mode 100644 index 0000000..208cf79 --- /dev/null +++ b/iface/version.hh @@ -0,0 +1,8 @@ +// No copyright +#pragma once + +namespace nf7::iface { + +const char* version() noexcept; + +} // namespace nf7::iface diff --git a/main.cc b/main.cc new file mode 100644 index 0000000..6c7a14b --- /dev/null +++ b/main.cc @@ -0,0 +1,13 @@ +// No copyright + +#include + +#include "iface/version.hh" + +#include "core/version.hh" + + +int main() { + std::cout << "iface version: " << nf7::iface::version() << std::endl; + std::cout << "core version: " << nf7::iface::version() << std::endl; +}