Skip to content

Commit

Permalink
docs: readme formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 1, 2022
1 parent bf33860 commit c5032f7
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include(${_project_options_SOURCE_DIR}/Index.cmake)
# run_vcpkg()
# Set the project name and language
project(myproject LANGUAGES CXX)
project(myproject LANGUAGES CXX C)
# Initialize project_options variable related to this project
# This overwrites `project_options` and sets `project_warnings`
Expand All @@ -36,25 +36,27 @@ project_options(
ENABLE_CACHE
ENABLE_CPPCHECK
ENABLE_CLANG_TIDY
# WARNINGS_AS_ERRORS
# ENABLE_CONAN
# ENABLE_IPO
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_COVERAGE
# ENABLE_PCH
# PCH_HEADERS
# ENABLE_DOXYGEN
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
# ENABLE_COVERAGE
# WARNINGS_AS_ERRORS
# ENABLE_SANITIZER_ADDRESS
# ENABLE_SANITIZER_LEAK
# ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_PCH
# PCH_HEADERS
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
# ENABLE_UNITY
# CONAN_OPTIONS
)
```

```cmake
# add your executables, libraries, etc. here:
add_executable(myprogram main.cpp)
Expand All @@ -74,24 +76,24 @@ target_link_system_libraries(

It accepts the following named flags:

- `WARNINGS_AS_ERRORS`: Treat the warnings as errors
- `ENABLE_CACHE`: Enable cache if available
- `ENABLE_CPPCHECK`: Enable static analysis with Cppcheck
- `ENABLE_CLANG_TIDY`: Enable static analysis with clang-tidy
- `ENABLE_CONAN`: Use Conan for dependency management
- `ENABLE_IPO`: Enable Interprocedural Optimization (Link Time Optimization, LTO) in the release build
- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use
- `ENABLE_COVERAGE`: Enable coverage reporting for gcc/clang
- `ENABLE_CACHE`: Enable cache if available
- `ENABLE_PCH`: Enable Precompiled Headers
- `ENABLE_CONAN`: Use Conan for dependency management
- `ENABLE_DOXYGEN`: Enable Doxygen doc builds of source
- `ENABLE_USER_LINKER`: Enable a specific linker if available
- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang
- `ENABLE_UNITY`: Enable Unity builds of projects
- `WARNINGS_AS_ERRORS`: Treat the warnings as errors
- `ENABLE_SANITIZER_ADDRESS`: Enable address sanitizer
- `ENABLE_SANITIZER_LEAK`: Enable leak sanitizer
- `ENABLE_SANITIZER_UNDEFINED_BEHAVIOR`: Enable undefined behavior sanitizer
- `ENABLE_SANITIZER_THREAD`: Enable thread sanitizer
- `ENABLE_SANITIZER_MEMORY`: Enable memory sanitizer
- `ENABLE_PCH`: Enable Precompiled Headers
- `ENABLE_INCLUDE_WHAT_YOU_USE`: Enable static analysis with include-what-you-use
- `ENABLE_USER_LINKER`: Enable a specific linker if available
- `ENABLE_BUILD_WITH_TIME_TRACE`: Enable `-ftime-trace` to generate time tracing `.json` files on clang
- `ENABLE_UNITY`: Enable Unity builds of projects

It gets the following named parameters that can have different values in front of them:

Expand All @@ -113,7 +115,7 @@ Named String:
- `VCPKG_DIR`: (Defaults to `~/vcpkg`). You can provide the vcpkg installation directory using this optional parameter.
If the directory does not exist, it will automatically install vcpkg in this directory.

- `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.
- `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.

## `target_link_system_libraries` function

Expand All @@ -123,28 +125,28 @@ A very useful function that accepts the same arguments as `target_link_libraries

Similar to `target_include_directories`, but it suppresses the warnings. It is useful if you want to include some external directories directly.

## Changing the project_options parameters dynamically
## Changing the project_options dynamically

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 `DynamicOptions.cmake`, which adds `dynamic_project_options`. `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.
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.

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.
`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.

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.

The defaults presented to the user can be modified with

* `set(<featurename>_DEFAULT value)` - for user and developer builds
* `set(<featurename>_USER_DEFAULT value)` - for user builds
* `set(<featureoptionname>_DEVELOPER_DEFAULT value)` - for developer builds
- `set(<featurename>_DEFAULT value)` - for user and developer builds
- `set(<featurename>_USER_DEFAULT value)` - for user builds
- `set(<featureoptionname>_DEVELOPER_DEFAULT value)` - for developer builds

If you need to fix a setting for the sake of a command-line configuration, you can use:

```
```shell
cmake -DOPT_<featurename>:BOOL=value
```



<details>
<summary>Click to show the example:</summary>
<summary> 👉 Click to show the example:</summary>

```cmake
cmake_minimum_required(VERSION 3.16)
Expand All @@ -170,7 +172,7 @@ include(${_project_options_SOURCE_DIR}/src/DynamicOptions.cmake)
# run_vcpkg()
# Set the project name and language
project(myproject LANGUAGES CXX)
project(myproject LANGUAGES CXX C)
# Set PCH to be on by default for all non-Developer Mode Builds
# (this is just intended as an example of what is possible)
Expand All @@ -183,6 +185,9 @@ dynamic_project_options(
# set PCH headers you want enabled. Format can be slow, so this might be helpful
PCH_HEADERS <vector> <string> <fmt/format.h>
)
```

```cmake
# add your executables, libraries, etc. here:
add_executable(myprogram main.cpp)
Expand Down

0 comments on commit c5032f7

Please sign in to comment.