Skip to content

Commit

Permalink
Set default build type to 'Release' for single-config generators
Browse files Browse the repository at this point in the history
  • Loading branch information
OTheDev committed Mar 3, 2024
1 parent 186c717 commit 3301b97
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ cmake_minimum_required(VERSION 3.15)

project(bi VERSION 0.1)

# For single-configuration generators, set the default build type to Release
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting 'CMAKE_BUILD_TYPE' to 'Release'. Use "
"'-DCMAKE_BUILD_TYPE=Debug' for debug builds")
set(CMAKE_BUILD_TYPE Release)
endif()

# if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# message(STATUS "Clang detected")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
Expand Down
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,37 @@ Configure the build by appending these options to the `cmake` command in step 3:
- `BUILD_SHARED_LIBS`: Build shared libraries (`ON`/`OFF`). Default is `OFF`.
- `BUILD_TESTS`: Build the tests (`ON`/`OFF`). Default is `ON`.

For a **release-optimized build**, set `CMAKE_BUILD_TYPE` to `Release`.
**Release-Optimized or Debug Build**
- **Single-configuration generators**. Set `CMAKE_BUILD_TYPE` to `Release` at
configuration time:

For **development**, enabling the export of compile commands is useful for
tools like linters or editors. To do this, set
`CMAKE_EXPORT_COMPILE_COMMANDS` to `ON`. For example:
```shell
cmake .. -DCMAKE_BUILD_TYPE=Release
```

For single-configuration generators, if `CMAKE_BUILD_TYPE` is not specified,
this library will set `CMAKE_BUILD_TYPE` to `Release` by default. For a debug
build, use `-DCMAKE_BUILD_TYPE=Debug`.

- **Multi-configuration generators** (e.g. Visual Studio). The build type for
these generators is selected at build time, not at configuration time. Use
the `--config Release` option with the `cmake --build` command to specify a
release build:

```shell
cmake --build . --config Release
```

For a debug build, use the `--config Debug` option.

**Development**

```shell
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
```
- Enabling the export of compile commands is useful for tools like linters or
editors. To do this, set `CMAKE_EXPORT_COMPILE_COMMANDS` to `ON`. For example:

```shell
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
```

## Finding and Linking Against the Library Using `find_package()`

Expand Down

0 comments on commit 3301b97

Please sign in to comment.