Skip to content

Commit

Permalink
Add cmake workflow for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
imwints committed Dec 5, 2023
1 parent e35538f commit 97b35d9
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 23 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cmake-freebsd.yml
@@ -0,0 +1,40 @@
name: FreeBSD CMake

on:
push:
branches: main
tags-ignore: '*.*'
paths:
- '.github/workflows/cmake-freebsd.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/freebsd/*pp'
pull_request:
branches: main
paths:
- '.github/workflows/cmake-freebsd.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/freebsd/*pp'

jobs:
cmake_build_on_freebsd:
runs-on: ubuntu-22.04
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4

- name: Compile
uses: vmactions/freebsd-vm@v1
with:
release: '14.0'
usesh: true
prepare: pkg install -y cmake ninja
run: |
CXX=clang++ cmake -B build -G Ninja -DBTOP_STATIC=ON
cmake --build build --verbose
40 changes: 40 additions & 0 deletions .github/workflows/cmake-linux.yml
@@ -0,0 +1,40 @@
name: Linux CMake

on:
push:
branches: main
tags-ignore: '*.*'
paths:
- '.github/workflows/cmake-linux.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/linux/*pp'
pull_request:
branches: main
paths:
- '.github/workflows/cmake-linux.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/linux/*pp'

jobs:
cmake_build_on_linux:
runs-on: ubuntu-latest
container: alpine:edge
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4

- name: Install build tools
run: apk add --no-cache --update clang cmake lld ninja

- name: Configure
run: CXX=clang++ LDFLAGS=-fuse-ld=lld cmake -B build -G Ninja -DBTOP_STATIC=ON

- name: Compile
run: cmake --build build --verbose

47 changes: 47 additions & 0 deletions .github/workflows/cmake-macos.yml
@@ -0,0 +1,47 @@
name: macOS CMake

on:
push:
branches: main
tags-ignore: '*.*'
paths:
- '.github/workflows/cmake-macos.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/osx/*pp'
pull_request:
branches: main
paths:
- '.github/workflows/cmake-macos.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/osx/*pp'

jobs:
cmake_build_on_macos:
runs-on: macos-latest
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4

- name: Install build tools
run: |
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
brew update --quiet
brew install --force --overwrite cmake llvm@17 ninja
- name: Configure
run: |
export LLVM_PREFIX="$(brew --prefix llvm)"
export CXX="$LLVM_PREFIX/bin/clang++"
export CPPFLAGS="-I$LLVM_PREFIX/include"
export LDFLAGS="-L$LLVM_PREFIX/lib -L$LLVM_PREFIX/lib/c++ -Wl,-rpath,$LLVM_PREFIX/lib/c++ -fuse-ld=$LLVM_PREFIX/bin/ld64.lld"
cmake -B build -G Ninja
- name: Compile
run: cmake --build build --verbose

15 changes: 0 additions & 15 deletions .github/workflows/continuous-build-freebsd.yml
Expand Up @@ -58,18 +58,3 @@ jobs:
path: 'bin/*'
if-no-files-found: error

build-freebsd-cmake:
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v4

- name: Compile
uses: vmactions/freebsd-vm@v1
with:
release: '14.0'
usesh: true
prepare: pkg install -y cmake git ninja
run: |
CXX=clang++ cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBTOP_STATIC=ON
cmake --build build
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -70,8 +70,8 @@ else()
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is not supported")
endif()

check_include_file_cxx(ranges CXX_HAS_RANGES)
if(NOT CXX_HAS_RANGES)
check_include_file_cxx(ranges CXX_HAVE_RANGES)
if(NOT CXX_HAVE_RANGES)
message(FATAL_ERROR "The compiler doesn't support <ranges>")
endif()

Expand Down
108 changes: 102 additions & 6 deletions README.md
Expand Up @@ -450,7 +450,6 @@ Also needs a UTF8 locale and a font that covers:
```

</details>

<details>

<summary>
Expand Down Expand Up @@ -526,14 +525,22 @@ Also needs a UTF8 locale and a font that covers:
## Compilation macOS OSX
Needs GCC 10 or higher, (GCC 11 or above strongly recommended for better CPU efficiency in the compiled binary).
Needs GCC 10 / Clang 16 (or higher).
GCC 12 needed for macOS Ventura. If you get linker errors on Ventura you'll need to upgrade your command line tools (Version 14.0) is bugged.
With GCC, version 12 (or better) is needed for macOS Ventura. If you get linker errors on Ventura you'll need to upgrade your command line tools (Version 14.0) is bugged.

The makefile also needs GNU coreutils and `sed`.

Install and use Homebrew or MacPorts package managers for easy dependency installation

<details>

<summary>

### With Make

</summary>

1. **Install dependencies (example for Homebrew)**

```bash
Expand Down Expand Up @@ -612,9 +619,99 @@ Also needs a UTF8 locale and a font that covers:
gmake help
```

</details>
<details>

<summary>

### With CMake (Community maintained)

</summary>

1. **Install build dependencies**

Requires Clang / GCC, CMake, Ninja and Git

_**Note**: Since btop uses C++ 20 features the compiler choice is important._

With LLVM:
```bash
brew update --quiet
brew install llvm@17 ninja
```

With GCC:
```bash
brew update --quiet
brew install gcc@13
2. **Clone the repository**
```bash
git clone https://github.com/aristocratos/btop.git && cd btop
```
3. **Compile**
FreeBSD 14 and later:
```bash
# Configure
cmake -B build -G Ninja
# Build
cmake --build build
```
FreeBSD 13:
```bash
# Configure
CXX=g++13 cmake -B build -G Ninja
# Build
cmake --build build
```
This will automatically build a release version of btop.
Some useful options to pass to the configure step:
| Configure flag | Description |
|---------------------------------|-------------------------------------------------------------------------|
| `-DBTOP_STATIC=<ON\|OFF>` | Enables static linking (OFF by default) |
| `-DBTOP_LTO=<ON\|OFF>` | Enables link time optimization (ON by default) |
| `-DBTOP_USE_MOLD=<ON\|OFF>` | Use mold to link btop (OFF by default) |
| `-DBTOP_PEDANTIC=<ON\|OFF>` | Compile with additional warnings (OFF by default) |
| `-DBTOP_WERROR=<ON\|OFF>` | Compile with warnings as errors (OFF by default) |
| `-DCMAKE_INSTALL_PREFIX=<path>` | The installation prefix ('/usr/local' by default) |
_**Note:** Static linking does not work with GCC._
To force a compiler, run `CXX=<compiler> cmake -B build -G Ninja`
4. **Install**
```bash
cmake --install build
```
May require root privileges
5. **Uninstall**
CMake doesn't generate an uninstall target by default. To remove installed files, run
```
cat build/install_manifest.txt | xargs rm -irv
```
6. **Cleanup build directory**
```bash
cmake --build build -t clean
```
</details>
## Compilation FreeBSD
Needs GCC 10 or higher, (GCC 11 or above strongly recommended for better CPU efficiency in the compiled binary).
Needs GCC 10 / Clang 16 (or higher).
Note that GNU make (`gmake`) is required to compile on FreeBSD.
Expand Down Expand Up @@ -706,7 +803,6 @@ Also needs a UTF8 locale and a font that covers:
```
</details>

<details>
<summary>
Expand Down Expand Up @@ -735,7 +831,7 @@ Also needs a UTF8 locale and a font that covers:
```bash
git clone https://github.com/aristocratos/btop.git && cd btop
``````
```
3. **Compile**
Expand Down

0 comments on commit 97b35d9

Please sign in to comment.