Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,13 +45,14 @@ 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
env:
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
asset_path: ./${{ steps.package.outputs.deb }}
asset_name: ${{ steps.package.outputs.deb }}
asset_content_type: application/vnd.debian.binary-package
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.build
.cache
compile_commands.json
147 changes: 95 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
1 change: 0 additions & 1 deletion lib.h → include/lib.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once

int version();

File renamed without changes.
4 changes: 2 additions & 2 deletions main.cpp → src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "lib.h"

#include <iostream>

#include <lib.h>

int main(int, char **) {
std::cout << "Version: " << version() << std::endl;
std::cout << "Hello, world!" << std::endl;
Expand Down
7 changes: 7 additions & 0 deletions tests/gtest_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gtest/gtest.h>

#include <lib.h>

TEST(version_test, basic_assertion) {
EXPECT_GT(version(), 0);
}
2 changes: 1 addition & 1 deletion test_version.cpp → tests/test_version.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE test_version

#include "lib.h"
#include <lib.h>

#include <boost/test/unit_test.hpp>

Expand Down
Loading