diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f63ec18d..df3fa784c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,23 +1,40 @@ -name: 'C++ CI' +name: "C++ CI" on: push: branches: - master - feature/github_actions + - tasks/* jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 with: submodules: true - - run: sudo apt-get update && sudo apt-get install libboost-test-dev -y - - run: cmake . -DPATCH_VERSION=${{ github.run_number }} -DWITH_BOOST_TEST=ON - - run: cmake --build . - - run: cmake --build . --target test - - run: cmake --build . --target package + + - name: Prepare Build Environment + run: sudo apt-get update && sudo apt-get install libboost-test-dev -y + + - name: Configure CMake + run: cmake . -DPATCH_VERSION=${{ github.run_number }} -DWITH_BOOST_TEST=ON + + - name: Build + run: cmake --build . + + - name: Test + run: cmake --build . --target test + + - name: Package + run: cmake --build . --target package + + - name: Get Package Filename + id: package + run: echo "deb=$(find . -name '*.deb' -exec basename {} \; | tail -n 1)" >> $GITHUB_OUTPUT + - name: Create Release id: create_release uses: actions/create-release@v1 @@ -28,6 +45,7 @@ jobs: release_name: Release ${{ github.run_number }} draft: false prerelease: false + - name: Upload Release Asset id: upload-release-asset uses: actions/upload-release-asset@v1 @@ -35,6 +53,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./helloworld-0.0.${{ github.run_number }}-Linux.deb - asset_name: helloworld-0.0.${{ github.run_number }}-Linux.deb - asset_content_type: application/vnd.debian.binary-package \ No newline at end of file + asset_path: ./${{ steps.package.outputs.deb }} + asset_name: ${{ steps.package.outputs.deb }} + asset_content_type: application/vnd.debian.binary-package diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..abbd0c712 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +.build +.cache +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b57fe738..4894a00c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,86 +1,129 @@ cmake_minimum_required(VERSION 3.12) set(PATCH_VERSION "1" CACHE INTERNAL "Patch version") -set(PROJECT_VESRION 0.0.${PATCH_VERSION}) +set(PROJECT_VESRION "0.0.${PATCH_VERSION}") -project(helloworld VERSION ${PROJECT_VESRION}) +project("task_01" VERSION ${PROJECT_VESRION}) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_POLICY_VERSION_MINIMUM 3.12) + +set(TASK_CLI "helloworld") +set(TASK_LIB "version") option(WITH_BOOST_TEST "Whether to build Boost test" ON) +option(WITH_GOOGLE_TEST "Whether to build Google test" ON) -configure_file(version.h.in version.h) +add_executable(${TASK_CLI} "src/main.cpp") +add_library(${TASK_LIB} "lib/lib.cpp") -add_executable(helloworld_cli main.cpp) -add_library(helloworld lib.cpp) +configure_file("${PROJECT_SOURCE_DIR}/version.h.in" + "${PROJECT_BINARY_DIR}/version.h" +) -set_target_properties(helloworld_cli helloworld PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON +set_target_properties(${TASK_CLI} ${TASK_LIB} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON ) -target_include_directories(helloworld - PRIVATE "${CMAKE_BINARY_DIR}" +target_include_directories(${TASK_LIB} + PUBLIC "include" ) -target_link_libraries(helloworld_cli PRIVATE - helloworld +target_include_directories(${TASK_LIB} + PRIVATE "${CMAKE_BINARY_DIR}" ) -if(WITH_BOOST_TEST) - find_package(Boost COMPONENTS unit_test_framework REQUIRED) - add_executable(test_version test_version.cpp) +target_link_libraries(${TASK_CLI} + PRIVATE ${TASK_LIB} +) - set_target_properties(test_version PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - ) +if (WITH_BOOST_TEST) + set(TASK_TEST "test_version") - set_target_properties(test_version PROPERTIES - COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK - INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR} - ) + find_package(Boost COMPONENTS unit_test_framework REQUIRED) + add_executable(${TASK_TEST} "tests/test_version.cpp") - target_link_libraries(test_version - ${Boost_LIBRARIES} - helloworld - ) + set_target_properties(${TASK_TEST} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + ) + + set_target_properties(${TASK_TEST} PROPERTIES + COMPILE_DEFINITIONS BOOST_TEST_DYN_LINK + INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR} + ) + + target_link_libraries(${TASK_TEST} + ${Boost_LIBRARIES} + ${TASK_LIB} + ) +endif() + +if (WITH_GOOGLE_TEST) + include(FetchContent) + + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings + if (MSVC) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + endif() + FetchContent_MakeAvailable(googletest) + + set(TASK_GTEST "gtest_version") + add_executable(${TASK_GTEST} "tests/gtest_version.cpp") + + target_link_libraries(${TASK_GTEST} + GTest::gtest_main + ${TASK_LIB} + ) endif() if (MSVC) - target_compile_options(helloworld_cli PRIVATE - /W4 + target_compile_options(${TASK_CLI} PRIVATE + /W4 + ) + target_compile_options(${TASK_LIB} PRIVATE + /W4 + ) + if(WITH_BOOST_TEST) + target_compile_options(${TASK_TEST} PRIVATE + /W4 ) - target_compile_options(helloworld PRIVATE - /W4 - ) - if(WITH_BOOST_TEST) - target_compile_options(test_version PRIVATE - /W4 - ) - endif() + endif() else () - target_compile_options(helloworld_cli PRIVATE - -Wall -Wextra -pedantic -Werror - ) - target_compile_options(helloworld PRIVATE - -Wall -Wextra -pedantic -Werror + target_compile_options(${TASK_CLI} PRIVATE + -Wall -Wextra -pedantic -Werror + ) + target_compile_options(${TASK_LIB} PRIVATE + -Wall -Wextra -pedantic -Werror + ) + if(WITH_BOOST_TEST) + target_compile_options(${TASK_TEST} PRIVATE + -Wall -Wextra -pedantic -Werror ) - if(WITH_BOOST_TEST) - target_compile_options(test_version PRIVATE - -Wall -Wextra -pedantic -Werror - ) - endif() + endif() endif() -install(TARGETS helloworld_cli RUNTIME DESTINATION bin) +install(TARGETS ${TASK_CLI} RUNTIME DESTINATION bin) set(CPACK_GENERATOR DEB) set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") -set(CPACK_PACKAGE_CONTACT example@example.com) +set(CPACK_PACKAGE_CONTACT "https://t.me/plushcube") include(CPack) -if(WITH_BOOST_TEST) - enable_testing() - add_test(test_version test_version) +if (WITH_BOOST_TEST) + enable_testing() + add_test(${TASK_TEST} "test_version") +endif() + +if (WITH_GOOGLE_TEST) + enable_testing() + include(GoogleTest) + gtest_discover_tests("gtest_version") endif() diff --git a/lib.h b/include/lib.h similarity index 96% rename from lib.h rename to include/lib.h index f802c701e..8e9dab9a9 100644 --- a/lib.h +++ b/include/lib.h @@ -1,4 +1,3 @@ #pragma once int version(); - diff --git a/lib.cpp b/lib/lib.cpp similarity index 100% rename from lib.cpp rename to lib/lib.cpp diff --git a/main.cpp b/src/main.cpp similarity index 90% rename from main.cpp rename to src/main.cpp index 18861d612..580ce6103 100644 --- a/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ -#include "lib.h" - #include +#include + int main(int, char **) { std::cout << "Version: " << version() << std::endl; std::cout << "Hello, world!" << std::endl; diff --git a/tests/gtest_version.cpp b/tests/gtest_version.cpp new file mode 100644 index 000000000..ea612b3d2 --- /dev/null +++ b/tests/gtest_version.cpp @@ -0,0 +1,7 @@ +#include + +#include + +TEST(version_test, basic_assertion) { + EXPECT_GT(version(), 0); +} diff --git a/test_version.cpp b/tests/test_version.cpp similarity index 92% rename from test_version.cpp rename to tests/test_version.cpp index 2e95b86c5..b5e56b0f9 100644 --- a/test_version.cpp +++ b/tests/test_version.cpp @@ -1,6 +1,6 @@ #define BOOST_TEST_MODULE test_version -#include "lib.h" +#include #include