Skip to content

Commit 2139ecd

Browse files
authored
Make fetch contentable (#27)
* Better namespacing of functions * Make template more fetchable * Make sure dependencies file is updated
1 parent 5bf4f34 commit 2139ecd

24 files changed

+64
-108
lines changed

.github/template/template_name

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ftxui_template
1+
cmake_template
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cpp-best-practices/ftxui_template
1+
cpp-best-practices/cmake_template

.github/workflows/template-janitor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
- name: Insert new org and project
7575
run: |
7676
# rename the CMake project to match the github project
77-
find src include test fuzz_test -type f -exec sed -i "s/myproject/${{ env.NEW_SAFE_PROJECT }}/gi" CMakeLists.txt ProjectOptions.cmake .github/workflows/ci.yml .github/workflows/codeql-analysis.yml configured_files/config.hpp.in {} +
77+
find src include test fuzz_test cmake -type f -exec sed -i "s/myproject/${{ env.NEW_SAFE_PROJECT }}/gi" CMakeLists.txt Dependencies.cmake ProjectOptions.cmake .github/workflows/ci.yml .github/workflows/codeql-analysis.yml configured_files/config.hpp.in {} +
7878
7979
# Update URL placeholders for project
8080
sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ project(
2525
include(cmake/PreventInSourceBuilds.cmake)
2626
include(ProjectOptions.cmake)
2727

28-
setup_options()
2928

30-
global_options()
29+
myproject_setup_options()
30+
31+
myproject_global_options()
3132
include(Dependencies.cmake)
32-
setup_dependencies()
33+
myproject_setup_dependencies()
3334

34-
local_options()
35+
myproject_local_options()
3536

3637
# don't know if this should be set globally from here or not...
3738
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
@@ -97,7 +98,7 @@ include(cmake/PackageProject.cmake)
9798

9899
# Add other targets that you want installed here, by default we just package the one executable
99100
# we know we want to ship
100-
package_project(
101+
myproject_package_project(
101102
TARGETS
102103
intro
103104
myproject_options

Dependencies.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include(cmake/CPM.cmake)
33
# Done as a function so that updates to variables like
44
# CMAKE_CXX_FLAGS don't propagate out to other
55
# targets
6-
function(setup_dependencies)
6+
function(myproject_setup_dependencies)
77

88
# For each dependency, see if it's
99
# already been provided to us by a parent project
@@ -35,4 +35,9 @@ function(setup_dependencies)
3535
if(NOT TARGET ftxui::screen)
3636
cpmaddpackage("gh:ArthurSonzogni/FTXUI#e23dbc7473654024852ede60e2121276c5aab660")
3737
endif()
38+
39+
if(NOT TARGET tools::tools)
40+
cpmaddpackage("gh:lefticus/tools#update_build_system")
41+
endif()
42+
3843
endfunction()

ProjectOptions.cmake

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include(CMakeDependentOption)
44
include(CheckCXXCompilerFlag)
55

66

7-
macro(setup_options)
7+
macro(myproject_setup_options)
88
option(myproject_ENABLE_HARDENING "Enable hardening" ON)
99
option(myproject_ENABLE_COVERAGE "Enable coverage reporting" OFF)
1010
cmake_dependent_option(
@@ -27,7 +27,7 @@ macro(setup_options)
2727
set(SUPPORTS_ASAN ON)
2828
endif()
2929

30-
check_libfuzzer_support(LIBFUZZER_SUPPORTED)
30+
myproject_check_libfuzzer_support(LIBFUZZER_SUPPORTED)
3131
option(myproject_BUILD_FUZZ_TESTS "Enable fuzz testing executable" ${LIBFUZZER_SUPPORTED})
3232

3333

@@ -80,27 +80,29 @@ macro(setup_options)
8080
endif()
8181
endmacro()
8282

83-
macro(global_options)
83+
macro(myproject_global_options)
8484
if(myproject_ENABLE_IPO)
8585
include(cmake/InterproceduralOptimization.cmake)
86-
enable_ipo()
86+
myproject_enable_ipo()
8787
endif()
8888

8989
if(myproject_ENABLE_HARDENING AND myproject_ENABLE_GLOBAL_HARDENING)
9090
include(cmake/Hardening.cmake)
9191
set(ENABLE_UBSAN_MINIMAL_RUNTIME NOT myproject_ENABLE_SANITIZER_UNDEFINED)
92-
enable_hardening(myproject_options ON ${ENABLE_UBSAN_MINIMAL_RUNTIME})
92+
myproject_enable_hardening(myproject_options ON ${ENABLE_UBSAN_MINIMAL_RUNTIME})
9393
endif()
9494
endmacro()
9595

96-
macro(local_options)
97-
include(cmake/StandardProjectSettings.cmake)
96+
macro(myproject_local_options)
97+
if (PROJECT_IS_TOP_LEVEL)
98+
include(cmake/StandardProjectSettings.cmake)
99+
endif()
98100

99101
add_library(myproject_warnings INTERFACE)
100102
add_library(myproject_options INTERFACE)
101103

102104
include(cmake/CompilerWarnings.cmake)
103-
set_project_warnings(
105+
myproject_set_project_warnings(
104106
myproject_warnings
105107
${myproject_WARNINGS_AS_ERRORS}
106108
""
@@ -114,7 +116,7 @@ macro(local_options)
114116
endif()
115117

116118
include(cmake/Sanitizers.cmake)
117-
enable_sanitizers(
119+
myproject_enable_sanitizers(
118120
myproject_options
119121
${myproject_ENABLE_SANITIZER_ADDRESS}
120122
${myproject_ENABLE_SANITIZER_LEAK}
@@ -135,22 +137,22 @@ macro(local_options)
135137

136138
if(myproject_ENABLE_CACHE)
137139
include(cmake/Cache.cmake)
138-
enable_cache()
140+
myproject_enable_cache()
139141
endif()
140142

141143
include(cmake/StaticAnalyzers.cmake)
142144
if(myproject_ENABLE_CLANG_TIDY)
143-
enable_clang_tidy(myproject_options ${myproject_WARNINGS_AS_ERRORS})
145+
myproject_enable_clang_tidy(myproject_options ${myproject_WARNINGS_AS_ERRORS})
144146
endif()
145147

146148
if(myproject_ENABLE_CPPCHECK)
147-
enable_cppcheck(${myproject_WARNINGS_AS_ERRORS} "" # override cppcheck options
149+
myproject_enable_cppcheck(${myproject_WARNINGS_AS_ERRORS} "" # override cppcheck options
148150
)
149151
endif()
150152

151153
if(myproject_ENABLE_COVERAGE)
152154
include(cmake/Tests.cmake)
153-
enable_coverage(myproject_options)
155+
myproject_enable_coverage(myproject_options)
154156
endif()
155157

156158
if(myproject_WARNINGS_AS_ERRORS)
@@ -164,7 +166,7 @@ macro(local_options)
164166
if(myproject_ENABLE_HARDENING AND NOT myproject_ENABLE_GLOBAL_HARDENING)
165167
include(cmake/Hardening.cmake)
166168
set(ENABLE_UBSAN_MINIMAL_RUNTIME NOT myproject_ENABLE_SANITIZER_UNDEFINED)
167-
enable_hardening(myproject_options OFF ${ENABLE_UBSAN_MINIMAL_RUNTIME})
169+
myproject_enable_hardening(myproject_options OFF ${ENABLE_UBSAN_MINIMAL_RUNTIME})
168170
endif()
169171

170172
endmacro()

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# ftxui_template
1+
# cmake_template
22

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

8-
## About ftxui_template
8+
## About cmake_template
99

1010
**NOTE** This is undergoing a major overhaul on a new branch currently.
1111

@@ -38,7 +38,7 @@ This project gets you started with a simple example of using FTXUI, which happen
3838

3939
### Use the Github template
4040
First, click the green `Use this template` button near the top of this page.
41-
This will take you to Github's ['Generate Repository'](https://github.com/cpp-best-practices/ftxui_template/generate) page.
41+
This will take you to Github's ['Generate Repository'](https://github.com/cpp-best-practices/cmake_template/generate) page.
4242
Fill in a repository name and short description, and click 'Create repository from template'.
4343
This will allow you to create a new repository in your Github account,
4444
prepopulated with the contents of this project.

cmake/Cache.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Enable cache if available
2-
function(enable_cache)
2+
function(myproject_enable_cache)
33
set(CACHE_OPTION
44
"ccache"
55
CACHE STRING "Compiler cache to be used")

cmake/CompilerWarnings.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
44

55
function(
6-
set_project_warnings
6+
myproject_set_project_warnings
77
project_name
88
WARNINGS_AS_ERRORS
99
MSVC_WARNINGS

cmake/Cuda.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# target_link_libraries(main_cuda PRIVATE project_options project_warnings)
88
# target_link_cuda(main_cuda)
99
#
10-
macro(target_link_cuda target)
10+
macro(myproject_target_link_cuda target)
1111
# optional named CUDA_WARNINGS
1212
set(oneValueArgs CUDA_WARNINGS)
1313
cmake_parse_arguments(

0 commit comments

Comments
 (0)