Skip to content

Commit

Permalink
Naming review and build simplification (#28)
Browse files Browse the repository at this point in the history
* more generic names in line with original two way paper

* more succinct cmake presets

* add simpler install docs

* simplify naming and two way type choice

* stack copy is better than mem references

* update docs to be more specific to new build types
  • Loading branch information
agl-alexglopez authored Jul 22, 2024
1 parent 9f7f784 commit 53d3d14
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 165 deletions.
49 changes: 25 additions & 24 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,60 @@
},
"configurePresets": [
{
"name": "gcc-deb",
"name": "default-deb",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"hidden": true,
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_COMPILER": "gcc",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/deb",
"CMAKE_C_FLAGS":
"-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
"CMAKE_C_FLAGS": "-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option"
}
},
{
"name": "gcc-rel",
"name": "default-rel",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_COMPILER": "gcc",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/rel",
"CMAKE_C_FLAGS":
"-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
"CMAKE_C_FLAGS": "-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option"
}
},
{
"name": "gcc-deb",
"inherits": "default-deb",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_C_FLAGS": "-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
}
},
{
"name": "gcc-rel",
"inherits": "default-rel",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_C_FLAGS": "-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
}
},
{
"name": "clang-deb",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"inherits": "default-deb",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_COMPILER": "clang",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/deb",
"CMAKE_C_FLAGS":
"-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-pointer-bool-conversion"
"CMAKE_C_FLAGS": "-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-pointer-bool-conversion"
}
},
{
"name": "clang-rel",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"inherits": "default-rel",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_COMPILER": "clang",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/rel",
"CMAKE_C_FLAGS":
"-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-pointer-bool-conversion"
"CMAKE_C_FLAGS": "-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-pointer-bool-conversion"
}
}
]
Expand Down
97 changes: 38 additions & 59 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,19 @@

## Quick Start

Use the provided defaults, build the library, install the library, include the library.
1. Use the provided defaults
2. Build the library
3. Install the library
4. Include the library.

### Build the library

Use GCC to compile the library.

```zsh
make gcc-rel [OPTIONAL INSTALL PATH]
```

Use Clang to compile the library.
To complete steps 1-3 with one command try the following if your system supports `make`.

```zsh
make clang-rel [OPTIONAL INSTALL PATH]
make str_view [OPTIONAL/INSTALL/PATH]
```

### Install the library
This will use CMake and your default compiler to build and install the library in release mode. By default, this library does not touch your system paths and it is installed in the `install/` directory of this folder. This is best for testing the library out while pointing `cmake` to the install location. Then, deleting the `install/` folder deletes any trace of this library from your system.

By default, this library does not touch your system paths and it is installed in the `install/` directory of this folder. This is best for testing the library out while pointing `cmake` to the install location. Then, deleting the `install/` folder deletes any trace of this library from your system.

```zsh
make install
```
Then, in your `CMakeLists.txt`:

```cmake
Expand All @@ -40,8 +30,7 @@ find_package(str_view)
specify that this library shall be installed to a location CMake recognizes by default. For example, my preferred location is as follows:

```zsh
make gcc-rel ~/.local
make install
make str_view ~/.local
```

Then the installation looks like this.
Expand Down Expand Up @@ -83,6 +72,34 @@ The C code.

## Alternative Builds

You may wish to use a different compiler and toolchain than what your system default specifies. Review the `CMakePrests.json` file for different compilers.

```zsh
make gcc-rel [OPTIONAL/INSTALL/PATH]
make install
```

Use Clang to compile the library.

```zsh
make clang-rel [OPTIONAL/INSTALL/PATH]
make install
```

## Without Make

If your system does not support Makefiles or the `make` command here are the cmake commands one can run that will allow another generator such as `Ninja` to complete building and installation.

```zsh
# Configure the project cmake files.
# Replace this preset with your own if you'd like.
cmake --preset=clang-rel -DCMAKE_INSTALL_PREFIX=[DESIRED/INSTALL/LOCATION]
cmake --build build
cmake --build build --target install
```

## User Presets

If you do not like the default presets, create a `CMakeUserPresets.json` in this folder and place your preferred configuration in that file. Here is my preferred configuration to get you started. I like to use a newer gcc version than the default presets specify.

```json
Expand All @@ -108,8 +125,7 @@ If you do not like the default presets, create a `CMakeUserPresets.json` in this
"CMAKE_C_COMPILER": "gcc-12",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/deb",
"CMAKE_C_FLAGS":
"-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
"CMAKE_C_FLAGS": "-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
}
},
{
Expand All @@ -126,44 +142,7 @@ If you do not like the default presets, create a `CMakeUserPresets.json` in this
"CMAKE_C_COMPILER": "gcc-12",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/rel",
"CMAKE_C_FLAGS":
"-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
}
},
{
"name": "cdeb",
"displayName": "Ninja clang Debug",
"description": "Generated by Ninja with clang base debug preset.",
"generator": "Ninja",
"inherits": [
"clang-deb"
],
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_COMPILER": "clang",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/deb",
"CMAKE_C_FLAGS":
"-g3 -Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-pointer-bool-conversion"
}
},
{
"name": "crel",
"displayName": "Ninja clang Release",
"description": "Generated by Ninja with clang base release preset.",
"generator": "Ninja",
"inherits": [
"clang-rel"
],
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_C_STANDARD": "11",
"CMAKE_C_COMPILER": "clang",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_RUNTIME_OUTPUT_DIRECTORY": "${sourceDir}/build/rel",
"CMAKE_C_FLAGS":
"-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-pointer-bool-conversion"
"CMAKE_C_FLAGS": "-Wall -Wextra -Wfloat-equal -Wtype-limits -Wpointer-arith -Wshadow -Winit-self -fno-diagnostics-show-option -Wno-nonnull-compare -Wno-pointer-bool-conversion"
}
}
]
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: default install build gcc-rel gcc-deb clang-rel clang-deb tests samples gcc-all-deb gcc-all-rel clang-all-deb clang-all-rel test-deb test-rel clean
.PHONY: default install build gcc-rel gcc-deb clang-rel clang-deb tests samples gcc-all-deb gcc-all-rel clang-all-deb clang-all-rel str_view test-deb test-rel clean

MAKE := $(MAKE)
MAKEFLAGS += --no-print-directory
Expand All @@ -16,6 +16,11 @@ default: build
build:
cmake --build $(BUILD_DIR) $(JOBS)

str_view:
cmake --preset=default-rel -DCMAKE_INSTALL_PREFIX=$(PREFIX)
$(MAKE) build
cmake --build $(BUILD_DIR) --target install $(JOBS)

install:
cmake --build $(BUILD_DIR) --target install $(JOBS)

Expand Down
Loading

0 comments on commit 53d3d14

Please sign in to comment.