Skip to content

Commit 7c9120d

Browse files
authored
Merge branch 'main' into cuda
2 parents c9add8d + 3123014 commit 7c9120d

10 files changed

Lines changed: 335 additions & 127 deletions

.cmake-format.yaml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
format:
2+
line_width: 120
3+
tab_size: 2
4+
max_pargs_hwrap: 3
5+
separate_ctrl_name_with_space: false
6+
separate_fn_name_with_space: false
7+
dangle_parens: false
8+
line_ending: unix
9+
markup:
10+
bullet_char: "*"
11+
enum_char: .
12+
enable_markup: false
113
parse:
214
additional_commands:
315
project_options:
416
pargs:
5-
nargs: '*'
17+
nargs: "*"
618
flags: []
719
spelling: project_options
820
kwargs:
@@ -12,7 +24,7 @@ parse:
1224
CONAN_OPTIONS: +
1325
catch_discover_tests:
1426
pargs:
15-
nargs: '*'
27+
nargs: "*"
1628
flags: []
1729
kwargs:
1830
OUTPUT_DIR: 1
@@ -22,15 +34,15 @@ parse:
2234
TEST_PREFIX: 1
2335
conan_add_remote:
2436
pargs:
25-
nargs: '*'
37+
nargs: "*"
2638
flags: []
2739
kwargs:
2840
INDEX: 1
2941
NAME: 1
3042
URL: 1
3143
conan_cmake_install:
3244
pargs:
33-
nargs: '*'
45+
nargs: "*"
3446
flags: []
3547
kwargs:
3648
BUILD: +
@@ -56,7 +68,7 @@ parse:
5668
SETTINGS_HOST: +
5769
cpmaddpackage:
5870
pargs:
59-
nargs: '*'
71+
nargs: "*"
6072
flags: []
6173
spelling: CPMAddPackage
6274
kwargs: &id001
@@ -85,19 +97,19 @@ parse:
8597
OPTIONS: +
8698
cpmfindpackage:
8799
pargs:
88-
nargs: '*'
100+
nargs: "*"
89101
flags: []
90102
spelling: CPMFindPackage
91103
kwargs: *id001
92104
cpmdeclarepackage:
93105
pargs:
94-
nargs: '*'
106+
nargs: "*"
95107
flags: []
96108
spelling: CPMDeclarePackage
97109
kwargs: *id001
98110
packageproject:
99111
pargs:
100-
nargs: '*'
112+
nargs: "*"
101113
flags: []
102114
spelling: packageProject
103115
kwargs:
@@ -121,15 +133,3 @@ parse:
121133
cpmgetpackageversion:
122134
pargs: 2
123135
spelling: CPMGetPackageVersion
124-
format:
125-
line_width: 120
126-
tab_size: 2
127-
max_pargs_hwrap: 3
128-
separate_ctrl_name_with_space: false
129-
separate_fn_name_with_space: false
130-
dangle_parens: false
131-
line_ending: unix
132-
markup:
133-
bullet_char: '*'
134-
enum_char: .
135-
enable_markup: false

README.md

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ cmake_minimum_required(VERSION 3.16)
1515
# You can later set fine-grained standards for each target using `target_compile_features`
1616
# set(CMAKE_CXX_STANDARD 17)
1717
18-
# Add project_options v0.13.1
18+
# Add project_options v0.14.2
1919
# https://github.com/cpp-best-practices/project_options
2020
include(FetchContent)
21-
FetchContent_Declare(_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.13.1.zip)
21+
FetchContent_Declare(_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.14.2.zip)
2222
FetchContent_MakeAvailable(_project_options)
2323
include(${_project_options_SOURCE_DIR}/Index.cmake)
2424
@@ -27,7 +27,7 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
2727
# run_vcpkg()
2828
2929
# Set the project name and language
30-
project(myproject LANGUAGES CXX)
30+
project(myproject LANGUAGES CXX C)
3131
3232
# Initialize project_options variable related to this project
3333
# This overwrites `project_options` and sets `project_warnings`
@@ -36,25 +36,27 @@ project_options(
3636
ENABLE_CACHE
3737
ENABLE_CPPCHECK
3838
ENABLE_CLANG_TIDY
39-
# WARNINGS_AS_ERRORS
4039
# ENABLE_CONAN
4140
# ENABLE_IPO
42-
# ENABLE_INCLUDE_WHAT_YOU_USE
43-
# ENABLE_COVERAGE
44-
# ENABLE_PCH
45-
# PCH_HEADERS
4641
# ENABLE_DOXYGEN
47-
# ENABLE_USER_LINKER
48-
# ENABLE_BUILD_WITH_TIME_TRACE
49-
# ENABLE_UNITY
42+
# ENABLE_COVERAGE
43+
# WARNINGS_AS_ERRORS
5044
# ENABLE_SANITIZER_ADDRESS
5145
# ENABLE_SANITIZER_LEAK
5246
# ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
5347
# ENABLE_SANITIZER_THREAD
5448
# ENABLE_SANITIZER_MEMORY
49+
# ENABLE_INCLUDE_WHAT_YOU_USE
50+
# ENABLE_PCH
51+
# PCH_HEADERS
52+
# ENABLE_USER_LINKER
53+
# ENABLE_BUILD_WITH_TIME_TRACE
54+
# ENABLE_UNITY
5555
# CONAN_OPTIONS
5656
)
57+
```
5758

59+
```cmake
5860
# add your executables, libraries, etc. here:
5961
6062
add_executable(myprogram main.cpp)
@@ -74,27 +76,28 @@ target_link_system_libraries(
7476

7577
It accepts the following named flags:
7678

77-
- `WARNINGS_AS_ERRORS`: Treat the warnings as errors
79+
- `ENABLE_CACHE`: Enable cache if available
7880
- `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck
7981
- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy
82+
- `ENABLE_CONAN`: Use Conan for dependency management
8083
- `ENABLE_IPO`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
81-
- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use
8284
- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang
83-
- `ENABLE_CACHE`: Enable cache if available
84-
- `ENABLE_PCH`: Enable Precompiled Headers
85-
- `ENABLE_CONAN`: Use Conan for dependency management
8685
- `ENABLE_DOXYGEN`: Enable Doxygen doc builds of source
87-
- `ENABLE_USER_LINKER`: Enable a specific linker if available
88-
- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang
89-
- `ENABLE_UNITY`: Enable Unity builds of projects
86+
- `WARNINGS_AS_ERRORS`: Treat the warnings as errors
9087
- `ENABLE_SANITIZER_ADDRESS`: Enable address sanitizer
9188
- `ENABLE_SANITIZER_LEAK`: Enable leak sanitizer
9289
- `ENABLE_SANITIZER_UNDEFINED_BEHAVIOR`: Enable undefined behavior sanitizer
9390
- `ENABLE_SANITIZER_THREAD`: Enable thread sanitizer
9491
- `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer
92+
- `ENABLE_PCH`: Enable Precompiled Headers
93+
- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use
94+
- `ENABLE_USER_LINKER`: Enable a specific linker if available
95+
- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang
96+
- `ENABLE_UNITY`: Enable Unity builds of projects
9597

96-
It gets the following named parameters (each accepting multiple values):
98+
It gets the following named parameters that can have different values in front of them:
9799

100+
- `DOXYGEN_THEME`: the name of the Doxygen theme to use. Supported themes: `awesome-sidebar` (default), `awesome` and `original`.
98101
- `PCH_HEADERS`: the list of the headers to precompile
99102
- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings
100103
- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings
@@ -113,7 +116,7 @@ Named String:
113116
- `VCPKG_DIR`: (Defaults to `~/vcpkg`). You can provide the vcpkg installation directory using this optional parameter.
114117
If the directory does not exist, it will automatically install vcpkg in this directory.
115118

116-
- `VCPKG_URL`: (Defaults to `https://github.com/microsoft/vcpkg.git`). This option allows setting URL of the vcpkg repository. By default, the official vcpkg repository is used.
119+
- `VCPKG_URL`: (Defaults to `https://github.com/microsoft/vcpkg.git`). This option allows setting the URL of the vcpkg repository. By default, the official vcpkg repository is used.
117120

118121
## `target_link_system_libraries` function
119122

@@ -134,14 +137,28 @@ target_link_libraries(main_cuda PRIVATE project_options project_warnings)
134137
target_link_cuda(main_cuda)
135138
```
136139

137-
## Changing the project_options parameters dynamically
140+
## Changing the project_options dynamically
141+
142+
During the test and development, it can be useful to change options on the fly. For example, to enable sanitizers when running tests. You can include `DynamicOptions.cmake`, which imports the `dynamic_project_options` function.
143+
144+
`dynamic_project_options` provides a recommended set of defaults (all static analysis and runtime analysis enabled for platforms where that is possible) while also providing a high-level option `ENABLE_DEVELOPER_MODE` (defaulted to `ON`) which can be turned off for easy use by non-developers.
138145

139-
It might be useful to change the test and development options on the fly (e.g., to enable sanitizers when running tests). To do this, you can include the `GlobalOptions.cmake`, which adds global options for the arguments of `project_options` function.
146+
The goal of the `dynamic_project_options` is to give a safe and well-analyzed environment to the developer by default while simultaneously making it easy for a user of the project to compile while not having to worry about clang-tidy, sanitizers, cppcheck, etc.
140147

141-
⚠️ It is highly recommended to keep the build declarative and reproducible by using the function arguments as explained above. The user of your code should not need to pass any special flags to build the library for normal usage. Please do not use this for anything other than test and development.
148+
The defaults presented to the user can be modified with
149+
150+
- `set(<featurename>_DEFAULT value)` - for user and developer builds
151+
- `set(<featurename>_USER_DEFAULT value)` - for user builds
152+
- `set(<featureoptionname>_DEVELOPER_DEFAULT value)` - for developer builds
153+
154+
If you need to fix a setting for the sake of a command-line configuration, you can use:
155+
156+
```shell
157+
cmake -DOPT_<featurename>:BOOL=value
158+
```
142159

143160
<details>
144-
<summary>Click to show the example:</summary>
161+
<summary> 👉 Click to show the example:</summary>
145162

146163
```cmake
147164
cmake_minimum_required(VERSION 3.16)
@@ -152,61 +169,37 @@ cmake_minimum_required(VERSION 3.16)
152169
# You can later set fine-grained standards for each target using `target_compile_features`
153170
# set(CMAKE_CXX_STANDARD 17)
154171
155-
# Add project_options v0.13.1
172+
# Add project_options v0.14.2
156173
# https://github.com/cpp-best-practices/project_options
157174
include(FetchContent)
158-
FetchContent_Declare(_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.13.1.zip)
175+
FetchContent_Declare(_project_options URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.14.2.zip)
159176
FetchContent_MakeAvailable(_project_options)
160177
include(${_project_options_SOURCE_DIR}/Index.cmake)
161178
162-
# ❗ Add global CMake options
163-
include(${_project_options_SOURCE_DIR}/src/GlobalOptions.cmake)
179+
# ❗ Add dynamic CMake options
180+
include(${_project_options_SOURCE_DIR}/src/DynamicOptions.cmake)
164181
165182
# uncomment to enable vcpkg:
166183
# # Setup vcpkg - should be called before defining project()
167184
# run_vcpkg()
168185
169186
# Set the project name and language
170-
project(myproject LANGUAGES CXX)
171-
172-
# ❗ enable sanitizers if running the tests
173-
option(FEATURE_TESTS "Enable the tests" OFF)
174-
if(FEATURE_TESTS)
175-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
176-
set(ENABLE_SANITIZER_ADDRESS OFF)
177-
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR OFF)
178-
else()
179-
set(ENABLE_SANITIZER_ADDRESS "ENABLE_SANITIZER_ADDRESS")
180-
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "ENABLE_SANITIZER_UNDEFINED_BEHAVIOR")
181-
endif()
182-
endif()
187+
project(myproject LANGUAGES CXX C)
188+
189+
# Set PCH to be on by default for all non-Developer Mode Builds
190+
# (this is just intended as an example of what is possible)
191+
set(ENABLE_PCH_USER_DEFAULT ON)
183192
184193
# Initialize project_options variable related to this project
185194
# This overwrites `project_options` and sets `project_warnings`
186195
# uncomment the options to enable them:
187-
project_options(
188-
ENABLE_CACHE
189-
ENABLE_CPPCHECK
190-
ENABLE_CLANG_TIDY
191-
# WARNINGS_AS_ERRORS
192-
# ENABLE_CONAN
193-
# ENABLE_IPO
194-
# ENABLE_INCLUDE_WHAT_YOU_USE
195-
# ENABLE_COVERAGE
196-
# ENABLE_PCH
197-
# PCH_HEADERS
198-
# ENABLE_DOXYGEN
199-
# ENABLE_IPO
200-
# ENABLE_USER_LINKER
201-
# ENABLE_BUILD_WITH_TIME_TRACE
202-
# ENABLE_UNITY
203-
# ❗ Now, the address and undefined behavior sanitizers are enabled through CMake options
204-
${ENABLE_SANITIZER_ADDRESS}
205-
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
206-
# ENABLE_SANITIZER_LEAK
207-
# ENABLE_SANITIZER_THREAD
208-
# ENABLE_SANITIZER_MEMORY
196+
dynamic_project_options(
197+
# set PCH headers you want enabled. Format can be slow, so this might be helpful
198+
PCH_HEADERS <vector> <string> <fmt/format.h>
209199
)
200+
```
201+
202+
```cmake
210203
# add your executables, libraries, etc. here:
211204
212205
add_executable(myprogram main.cpp)

src/Doxygen.cmake

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,50 @@
11
# Enable doxygen doc builds of source
2-
function(enable_doxygen)
2+
function(enable_doxygen DOXYGEN_THEME)
3+
# If not specified, use the top readme file as the first page
4+
if((NOT DOXYGEN_USE_MDFILE_AS_MAINPAGE) AND EXISTS "${PROJECT_SOURCE_DIR}/README.md")
5+
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${PROJECT_SOURCE_DIR}/README.md")
6+
endif()
7+
8+
# set better defaults for doxygen
39
set(DOXYGEN_CALLER_GRAPH YES)
410
set(DOXYGEN_CALL_GRAPH YES)
511
set(DOXYGEN_EXTRACT_ALL YES)
6-
find_package(Doxygen REQUIRED dot)
7-
doxygen_add_docs(doxygen-docs ${PROJECT_SOURCE_DIR})
12+
set(DOXYGEN_GENERATE_TREEVIEW YES)
13+
# svg files are much smaller than jpeg and png, and yet they have higher quality
14+
set(DOXYGEN_DOT_IMAGE_FORMAT svg)
15+
set(DOXYGEN_DOT_TRANSPARENT YES)
16+
17+
# If not specified, exclude the vcpkg files and the files CMake downloads under _deps (like project_options)
18+
if(NOT DOXYGEN_EXCLUDE_PATTERNS)
19+
set(DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/*" "${CMAKE_CURRENT_BINARY_DIR}/_deps/*")
20+
endif()
21+
22+
if("${DOXYGEN_THEME}" STREQUAL "")
23+
set(DOXYGEN_THEME "awesome-sidebar")
24+
endif()
25+
26+
if("${DOXYGEN_THEME}" STREQUAL "awesome" OR "${DOXYGEN_THEME}" STREQUAL "awesome-sidebar")
27+
# use a modern doxygen theme
28+
# https://github.com/jothepro/doxygen-awesome-css v1.6.1
29+
FetchContent_Declare(_doxygen_theme
30+
URL https://github.com/jothepro/doxygen-awesome-css/archive/refs/tags/v1.6.1.zip)
31+
FetchContent_MakeAvailable(_doxygen_theme)
32+
if("${DOXYGEN_THEME}" STREQUAL "awesome" OR "${DOXYGEN_THEME}" STREQUAL "awesome-sidebar")
33+
set(DOXYGEN_HTML_EXTRA_STYLESHEET "${_doxygen_theme_SOURCE_DIR}/doxygen-awesome.css")
34+
endif()
35+
if("${DOXYGEN_THEME}" STREQUAL "awesome-sidebar")
36+
set(DOXYGEN_HTML_EXTRA_STYLESHEET ${DOXYGEN_HTML_EXTRA_STYLESHEET}
37+
"${_doxygen_theme_SOURCE_DIR}/doxygen-awesome-sidebar-only.css")
38+
endif()
39+
else()
40+
# use the original doxygen theme
41+
endif()
42+
43+
# find doxygen and dot if available
44+
find_package(Doxygen REQUIRED OPTIONAL_COMPONENTS dot)
45+
46+
# add doxygen-docs target
47+
message(STATUS "Adding `doxygen-docs` target that builds the documentation.")
48+
doxygen_add_docs(doxygen-docs ALL ${PROJECT_SOURCE_DIR}
49+
COMMENT "Generating documentation - entry file: ${CMAKE_CURRENT_BINARY_DIR}/html/index.html")
850
endfunction()

0 commit comments

Comments
 (0)