Skip to content

Commit 9464d2f

Browse files
authored
Added cmake build (#14)
1 parent eab10dd commit 9464d2f

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ jobs:
4444
- name: Run tests
4545
run: |
4646
pytest -v
47+
48+
- name: Configure CMake
49+
run: |
50+
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
51+
52+
- name: Build with CMake
53+
working-directory: build
54+
run: cmake --build . --parallel 8

CMakeLists.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
set(CMAKE_CXX_EXTENSIONS OFF)
3+
4+
5+
project(git2cpp CXX)
6+
7+
if(NOT CMAKE_CXX_STANDARD)
8+
set(CMAKE_CXX_STANDARD 20)
9+
endif()
10+
message(STATUS "🔧 C++ standard: ${CMAKE_CXX_STANDARD}")
11+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
12+
13+
14+
set(GIT2CPP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
15+
16+
# Versionning
17+
# ===========
18+
file(STRINGS "${GIT2CPP_SOURCE_DIR}/version.hpp" git2cpp_version_defines
19+
REGEX "#define GIT2CPP_VERSION_(MAJOR|MINOR|PATCH)")
20+
21+
foreach(ver ${git2cpp_version_defines})
22+
if(ver MATCHES "#define GIT2CPP_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+);$")
23+
set(PROJECT_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
24+
endif()
25+
endforeach()
26+
27+
set(CMAKE_PROJECT_VERSION
28+
${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
29+
30+
message(STATUS "Building git2cpp v${CMAKE_PROJECT_VERSION}")
31+
32+
# Dependencies
33+
# ============
34+
35+
find_package(libgit2)
36+
# CLI11 is a single header, not packaged for cmake
37+
38+
# Build
39+
# =====
40+
41+
set(GIT2CPP_SRC
42+
${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.cpp
43+
${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.hpp
44+
${GIT2CPP_SOURCE_DIR}/subcommand/status_subcommand.cpp
45+
${GIT2CPP_SOURCE_DIR}/subcommand/status_subcommand.hpp
46+
${GIT2CPP_SOURCE_DIR}/utils/common.cpp
47+
${GIT2CPP_SOURCE_DIR}/utils/common.hpp
48+
${GIT2CPP_SOURCE_DIR}/utils/git_exception.cpp
49+
${GIT2CPP_SOURCE_DIR}/utils/git_exception.hpp
50+
${GIT2CPP_SOURCE_DIR}/wrapper/refs_wrapper.cpp
51+
${GIT2CPP_SOURCE_DIR}/wrapper/refs_wrapper.hpp
52+
${GIT2CPP_SOURCE_DIR}/wrapper/repository_wrapper.cpp
53+
${GIT2CPP_SOURCE_DIR}/wrapper/repository_wrapper.hpp
54+
${GIT2CPP_SOURCE_DIR}/wrapper/status_wrapper.cpp
55+
${GIT2CPP_SOURCE_DIR}/wrapper/status_wrapper.hpp
56+
${GIT2CPP_SOURCE_DIR}/main.cpp
57+
${GIT2CPP_SOURCE_DIR}/version.hpp
58+
)
59+
60+
add_executable(git2cpp ${GIT2CPP_SRC})
61+
target_link_libraries(git2cpp PRIVATE libgit2::libgit2package)
62+

dev-environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ dependencies:
88
- pkg-config
99
- python
1010
- pytest
11+
# Missing dependency from libgit2
12+
- zlib

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <git2.h> // For version number only
33
#include <iostream>
44

5-
#include "src/utils/git_exception.hpp"
5+
#include "utils/git_exception.hpp"
66
#include "version.hpp"
77
#include "subcommand/init_subcommand.hpp"
88
#include "subcommand/status_subcommand.hpp"

src/subcommand/init_subcommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// #include <filesystem>
22
#include "init_subcommand.hpp"
3-
#include "src/wrapper/repository_wrapper.hpp"
3+
#include "../wrapper/repository_wrapper.hpp"
44

55
init_subcommand::init_subcommand(const libgit2_object&, CLI::App& app)
66
{

0 commit comments

Comments
 (0)