diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index db76fe7..92a7bf6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,3 +44,11 @@ jobs: - name: Run tests run: | pytest -v + + - name: Configure CMake + run: | + cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX + + - name: Build with CMake + working-directory: build + run: cmake --build . --parallel 8 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b97b9c2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.28) +set(CMAKE_CXX_EXTENSIONS OFF) + + +project(git2cpp CXX) + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) +endif() +message(STATUS "🔧 C++ standard: ${CMAKE_CXX_STANDARD}") +set(CMAKE_CXX_STANDARD_REQUIRED ON) + + +set(GIT2CPP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) + +# Versionning +# =========== +file(STRINGS "${GIT2CPP_SOURCE_DIR}/version.hpp" git2cpp_version_defines + REGEX "#define GIT2CPP_VERSION_(MAJOR|MINOR|PATCH)") + +foreach(ver ${git2cpp_version_defines}) + if(ver MATCHES "#define GIT2CPP_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+);$") + set(PROJECT_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") + endif() +endforeach() + +set(CMAKE_PROJECT_VERSION + ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) + +message(STATUS "Building git2cpp v${CMAKE_PROJECT_VERSION}") + +# Dependencies +# ============ + +find_package(libgit2) +# CLI11 is a single header, not packaged for cmake + +# Build +# ===== + +set(GIT2CPP_SRC + ${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.cpp + ${GIT2CPP_SOURCE_DIR}/subcommand/init_subcommand.hpp + ${GIT2CPP_SOURCE_DIR}/subcommand/status_subcommand.cpp + ${GIT2CPP_SOURCE_DIR}/subcommand/status_subcommand.hpp + ${GIT2CPP_SOURCE_DIR}/utils/common.cpp + ${GIT2CPP_SOURCE_DIR}/utils/common.hpp + ${GIT2CPP_SOURCE_DIR}/utils/git_exception.cpp + ${GIT2CPP_SOURCE_DIR}/utils/git_exception.hpp + ${GIT2CPP_SOURCE_DIR}/wrapper/refs_wrapper.cpp + ${GIT2CPP_SOURCE_DIR}/wrapper/refs_wrapper.hpp + ${GIT2CPP_SOURCE_DIR}/wrapper/repository_wrapper.cpp + ${GIT2CPP_SOURCE_DIR}/wrapper/repository_wrapper.hpp + ${GIT2CPP_SOURCE_DIR}/wrapper/status_wrapper.cpp + ${GIT2CPP_SOURCE_DIR}/wrapper/status_wrapper.hpp + ${GIT2CPP_SOURCE_DIR}/main.cpp + ${GIT2CPP_SOURCE_DIR}/version.hpp +) + +add_executable(git2cpp ${GIT2CPP_SRC}) +target_link_libraries(git2cpp PRIVATE libgit2::libgit2package) + diff --git a/dev-environment.yml b/dev-environment.yml index 539afc5..80a86dd 100644 --- a/dev-environment.yml +++ b/dev-environment.yml @@ -8,3 +8,5 @@ dependencies: - pkg-config - python - pytest + # Missing dependency from libgit2 + - zlib diff --git a/src/main.cpp b/src/main.cpp index 4cd34b7..f5ce04a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ #include // For version number only #include -#include "src/utils/git_exception.hpp" +#include "utils/git_exception.hpp" #include "version.hpp" #include "subcommand/init_subcommand.hpp" #include "subcommand/status_subcommand.hpp" diff --git a/src/subcommand/init_subcommand.cpp b/src/subcommand/init_subcommand.cpp index 2581c3c..79d6807 100644 --- a/src/subcommand/init_subcommand.cpp +++ b/src/subcommand/init_subcommand.cpp @@ -1,6 +1,6 @@ // #include #include "init_subcommand.hpp" -#include "src/wrapper/repository_wrapper.hpp" +#include "../wrapper/repository_wrapper.hpp" init_subcommand::init_subcommand(const libgit2_object&, CLI::App& app) {