Skip to content

Commit abfa06e

Browse files
authored
Merge pull request #1 from cpp-best-practices/test_ftxui
make ftxui example work
2 parents e513bb8 + f910e5b commit abfa06e

File tree

8 files changed

+313
-33
lines changed

8 files changed

+313
-33
lines changed

.github/template/template_name

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp_boilerplate_project
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp-best-practices/cpp_boilerplate_project

.github/workflows/template-janitor.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# This workflow should cleanup everything unneeded from the template project
22

33
name: Template Janitor
4+
45
on:
6+
pull_request:
7+
release:
8+
types: [published]
59
push:
10+
tags:
611
branches:
7-
- develop
8-
- main # maybe all to run "tests" on every change?
12+
- main
13+
- develop
914

1015
env:
1116
TEMPLATES_PATH: ".github/template"
@@ -23,7 +28,7 @@ jobs:
2328
run: |
2429
echo "NEW_ORG=${{ github.repository_owner }}" >> $GITHUB_ENV
2530
echo "NEW_PROJECT=${{ github.event.repository.name }}" >> $GITHUB_ENV
26-
echo "NEW_URL=${{ github.repositoryUrl}}" >> $GITHUB_ENV
31+
echo "NEW_URL=${{ github.repositoryUrl }}" >> $GITHUB_ENV
2732
2833
- uses: octokit/[email protected]
2934
id: get_repo_meta
@@ -41,17 +46,17 @@ jobs:
4146
sed -i "s/myproject/${{ github.event.repository.name }}/gi" CMakeLists.txt configured_files/config.hpp.in
4247
4348
# Update URL placeholders for project
44-
sed -i "s/%%myurl%%/${{ github.event.repositoryUrl }}/gi" CMakeLists.txt
49+
sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt
4550
4651
# fill in placeholders of readme and move it into place
4752
sed -i "s/%%myorg%%/${{ env.NEW_ORG }}/g" ${{ env.TEMPLATES_PATH }}/README.md
4853
sed -i "s/%%myproject%%/${{ env.NEW_PROJECT }}/g" ${{ env.TEMPLATES_PATH }}/README.md
49-
sed -i "s/%%description%%/${{ fromJson(steps.get_repo_meta.outputs.data).description }}/g" ${{ env.TEMPLATES_PATH }}/README.md
54+
sed -i "s|%%description%%|${{ fromJson(steps.get_repo_meta.outputs.data).description }}|g" ${{ env.TEMPLATES_PATH }}/README.md
5055
cp ${{ env.TEMPLATES_PATH }}/README.md README.md
5156
5257
- name: Print diff after replacement
5358
run: |
54-
# Exclude the README as that is checked seperatly!
59+
# Exclude the README as that is checked separately!
5560
git diff ':!README.md'
5661
# following should not have any diffs
5762
diff ${{ env.TEMPLATES_PATH }}/README.md README.md
@@ -63,11 +68,35 @@ jobs:
6368
6469
- name: Clean up before commit and push
6570
run: |
66-
rm -rf ${{ env.TEMPLATES_PATH }}
71+
rm -r ${{ env.TEMPLATES_PATH }}
6772
68-
# Can we get that from a variabl?
73+
# Can we get that from a variable?
6974
# Remove this workflow as it has fulfilled its purpose
70-
rm -rf .github/workflows/template-janitor.yml
75+
rm .github/workflows/template-janitor.yml
76+
rm .github/workflows/template-renamer.yml
77+
78+
- name: Setup Cpp
79+
uses: aminya/setup-cpp@v1
80+
with:
81+
compiler: gcc
82+
83+
cmake: true
84+
ninja: false
85+
conan: true
86+
vcpkg: false
87+
ccache: false
88+
clangtidy: false
89+
90+
cppcheck: false
91+
92+
gcovr: false
93+
opencppcoverage: false
94+
95+
96+
- name: Test simple configuration to make sure nothing broke (default compiler,cmake,developer_mode OFF)
97+
run: |
98+
cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=DEBUG -DENABLE_DEVELOPER_MODE:BOOL=OFF -DOPT_ENABLE_COVERAGE:BOOL=OFF
99+
71100
72101
- uses: EndBug/add-and-commit@v4
73102
# only commit and push if we are not a template project anymore!
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# This workflow should cleanup everything unneeded from the template project
2+
3+
name: Template Renamer
4+
5+
on:
6+
pull_request:
7+
release:
8+
types: [published]
9+
push:
10+
tags:
11+
branches:
12+
- main
13+
- develop
14+
15+
env:
16+
TEMPLATES_PATH: ".github/template"
17+
18+
jobs:
19+
20+
template-rename:
21+
name: Renames template when a new name is detected
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Fetch Sources
25+
uses: actions/[email protected]
26+
27+
- name: Get organization and project name
28+
run: |
29+
echo "TEST_RUN=false" >> $GITHUB_ENV
30+
echo "NEW_ORG=${{ github.repository_owner }}" >> $GITHUB_ENV
31+
echo "NEW_PROJECT=${{ github.event.repository.name }}" >> $GITHUB_ENV
32+
echo "NEW_REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV
33+
echo "TEMPLATE_NAME=`cat ${{ env.TEMPLATES_PATH }}/template_name`" >> $GITHUB_ENV
34+
echo "TEMPLATE_REPOSITORY=`cat ${{ env.TEMPLATES_PATH }}/template_repository`" >> $GITHUB_ENV
35+
36+
- uses: octokit/[email protected]
37+
id: get_repo_meta
38+
with:
39+
route: GET /repos/{owner}/{repo}
40+
owner: ${{ env.NEW_ORG }}
41+
repo: ${{ env.NEW_PROJECT }}
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Setup fake test org/project names if project didn't change
46+
if: env.TEMPLATE_NAME == env.NEW_PROJECT
47+
run: |
48+
echo "TEST_RUN=true" >> $GITHUB_ENV
49+
echo "NEW_ORG=${{ github.repository_owner }}" >> $GITHUB_ENV
50+
echo "NEW_PROJECT=TEST_PROJECT" >> $GITHUB_ENV
51+
echo "NEW_REPOSITORY=TEST_REPOSITORY" >> $GITHUB_ENV
52+
53+
54+
# Rename all cpp_starter_project occurrences to current repository and remove this workflow
55+
- name: Update repository to match new template information
56+
run: |
57+
# Update the README and template files to match the new org / repository names
58+
sed -i "s|${{ env.TEMPLATE_REPOSITORY }}|${{ env.NEW_REPOSITORY }}|g" README.md ${{ env.TEMPLATES_PATH }}/template_repository
59+
sed -i "s|${{ env.TEMPLATE_NAME }}|${{ env.NEW_PROJECT }}|g" README.md ${{ env.TEMPLATES_PATH }}/template_name
60+
61+
- name: Print diff after template name replacement
62+
run: |
63+
git diff
64+
65+
- name: Setup Cpp
66+
uses: aminya/setup-cpp@v1
67+
with:
68+
compiler: gcc
69+
70+
cmake: true
71+
ninja: false
72+
conan: true
73+
vcpkg: false
74+
ccache: false
75+
clangtidy: false
76+
77+
cppcheck: false
78+
79+
gcovr: false
80+
opencppcoverage: false
81+
82+
- name: Test simple configuration to make sure nothing broke (default compiler,cmake,developer_mode OFF)
83+
run: |
84+
cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=DEBUG -DENABLE_DEVELOPER_MODE:BOOL=OFF -DOPT_ENABLE_COVERAGE:BOOL=OFF
85+
86+
- uses: EndBug/add-and-commit@v4
87+
# only commit and push if we are a template and project name has changed
88+
if: fromJson(steps.get_repo_meta.outputs.data).is_template == true && env.TEST_RUN == 'false'
89+
with:
90+
author_name: Template Janitor
91+
author_email: [email protected]
92+
message: 'Change Template Name'
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ set(CMAKE_CXX_STANDARD 20)
99
# when compiling with PCH enabled
1010
set(CMAKE_CXX_EXTENSIONS OFF)
1111

12+
include(FetchContent)
13+
14+
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
15+
FetchContent_Declare(ftxui
16+
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
17+
GIT_TAG v2.0.0
18+
)
19+
20+
FetchContent_GetProperties(ftxui)
21+
if(NOT ftxui_POPULATED)
22+
FetchContent_Populate(ftxui)
23+
add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
24+
endif()
25+
26+
27+
1228
# Note: by default ENABLE_DEVELOPER_MODE is True
1329
# This means that all analysis (sanitizers, static analysis)
1430
# is enabled and all warnings are treated as errors
@@ -22,7 +38,6 @@ set(OPT_WARNINGS_AS_ERRORS_DEVELOPER_DEFAULT TRUE)
2238

2339
# Add project_options v0.17.0
2440
# https://github.com/cpp-best-practices/project_options
25-
include(FetchContent)
2641
FetchContent_Declare(_project_options
2742
URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.17.0.zip)
2843
FetchContent_MakeAvailable(_project_options)
@@ -37,7 +52,7 @@ project(
3752
myproject
3853
VERSION 0.0.1
3954
DESCRIPTION ""
40-
HOMEPAGE_URL "%%url%%"
55+
HOMEPAGE_URL "%%myurl%%"
4156
LANGUAGES CXX C)
4257

4358
set(GIT_SHA

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![ci](https://github.com/cpp-best-practices/cpp_boilerplate_project/actions/workflows/ci.yml/badge.svg)](https://github.com/cpp-best-practices/cpp_boilerplate_project/actions/workflows/ci.yml)
44
[![codecov](https://codecov.io/gh/cpp-best-practices/cpp_boilerplate_project/branch/main/graph/badge.svg)](https://codecov.io/gh/cpp-best-practices/cpp_boilerplate_project)
5-
[![Language grade: C++](https://img.shields.io/lgtm/grade/cpp/github/cpp-best-practices/cpp_boilerplate_project)](https://lgtm.com/projects/g/cpp-best-practices/cpp_starter_project/context:cpp)
5+
[![Language grade: C++](https://img.shields.io/lgtm/grade/cpp/github/cpp-best-practices/cpp_boilerplate_project)](https://lgtm.com/projects/g/cpp-best-practices/cpp_boilerplate_project/context:cpp)
66
[![CodeQL](https://github.com/cpp-best-practices/cpp_boilerplate_project/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/cpp-best-practices/cpp_boilerplate_project/actions/workflows/codeql-analysis.yml)
77

88
## About cpp_boilerplate_project
@@ -28,9 +28,9 @@ It requires
2828
* conan
2929
* a compiler
3030

31-
If you want a more complex example project, check out the [cpp_starter_project](https://github.com/cpp-best-practices/cpp_starter_project).
3231

33-
Ths Boilerplate project will merge new features first, then they will be merged (as appropriate) into cpp_starter_project.
32+
This project gets you started with a simple example of using FTXUI, which happens to also be a game
33+
3434

3535
## Getting Started
3636

src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ target_link_libraries(
1212
fmt::fmt
1313
spdlog::spdlog)
1414

15-
target_include_directories(intro PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")
15+
target_link_system_libraries(
16+
intro
17+
PRIVATE
18+
ftxui::screen
19+
ftxui::dom
20+
ftxui::component)
1621

22+
target_include_directories(intro PRIVATE "${CMAKE_BINARY_DIR}/configured_files/include")

0 commit comments

Comments
 (0)