Skip to content

Commit

Permalink
CMake Refactor (#72)
Browse files Browse the repository at this point in the history
* refactor(cmake): use cpm, package-project

* refactor: include structure

* refactor(tests): modernize cmake, adjust to header changes

* refactor: remove external

* refactor: move `data` -> `assets`

* refactor(cmake): update tooling

* feat(tests): setup environment

* feat(python): refactor cmake

* fix(python): adapt new include structure

* refactor: add python sub-directpry

* refactor: default switches, dependencies

* feat: use scikit-build

* fix: formatting

* refactor(cmake-format): ignore comments

* feat(cmake/python): dynamic link against vtk-python libs

* fix(tests): logger

* fix: odr

* feat(python-bindings): add windows path

* Revert "Temporarily use legacy ViennaRay in GitHub actions"

This reverts commit 45c5393.

* fix: merge

* fix: format

* fix: format mismatch

* fix: examples

* feat: update application

* fix(python): includes

* fix: format

* fix: format

* feat: update workflows

* refactor(python): use rpath on macos

* chore: update gitignore

* fix(workflow): setup action

* fix(workflows): typo

* fix(workflow/python): venv on windows

* refactor(workflows): test python module

* refactor(workflows): naming

* fix(workflows/python): always upload artifact

* refactor(workflows): use config switch

* fix(openmp): parallel for should use signed type

* fix(openmp): use plain int

* Revert "fix(openmp): use plain int"

This reverts commit 604e856.

* Revert "fix(openmp): parallel for should use signed type"

This reverts commit a5330e4.

* refactor(workflow): add openmp flags

* feat: install required dependencies

* refactor(msvc): set openmp flags from cmake

* fix: format [skip ci]

* fix(msvc): enable bigobj

* refactor(workflow): print doc, add caching

* refactor(workflows): caching

* refactor(python): format init py

* refactor(cmake/bindings): use macro

* chore: update gitignore

* fix(workflows): typo

* fix: format

* fix(workflows): python cache key

* feat: add lookup dirs setting [skip ci]

* fix: format

* docs: update readme

* refactor(workflows): remove superfluous args [skip ci]

* fix(python): windows vtk path

* fix(windows): vtk dll paths

* fix: only install libs when required

* chore(deps): bump dependencies

* chore(deps): bump dependencies

* fix: install path

* fix: missing comma

* fix: soname version behavior

* fix: format

* fix(cmake/python): lib folder naming

* fix(cmake/python): add `viennaps.libs` to rpath

* fix(python): vtk path

* refactor(cmake/python):  lib folder conditions

* fix(macos): enable rpath at top level

* fix(rpath): use `@loader_path` on macos

* refactor(cmake): only enable macos rpath in bindings

* fix(tests, examples): setup tbb env

* fix: target name

* fix(cmake): install vtk on macos as well

* chore(deps): bump viennaray

* fix(cmake/python): also use build path

* This is useful when VTK is not installed through the package manager but by other means

* refactor(examples): don't accumulate all binaries in same directory

* chore: manual merge

* fix: formatting

* docs(examples): update readme

* fix: win32 conditional

* Update gitignore and readme

* Add most recent tags dependencies

---------

Co-authored-by: Tobias Reiter <t.reiter1@live.de>
  • Loading branch information
Curve and tobre1 authored Mar 22, 2024
1 parent 5c09768 commit 1af21bd
Show file tree
Hide file tree
Showing 161 changed files with 1,290 additions and 2,349 deletions.
6 changes: 6 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include: ["cmake/.cpm-format"]
format:
line_width: 100

markup:
enable_markup: false
26 changes: 0 additions & 26 deletions .github/actions/cache-check/action.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/actions/cache-delete/action.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 🏗️ Setup Environment
description: Install Dependencies & Deploy Workarounds

inputs:
container:
required: true
description: Build container used

install-vtk:
required: true
description: Wether or not to install VTK as a system dependency

runs:
using: "composite"

steps:
- name: 🩹 Enable Long Paths
shell: bash
if: ${{ inputs.container == 'windows-latest' }}
run: git config --system core.longpaths true

- name: 📋 Install Dependencies
shell: bash
if: ${{ inputs.container == 'ubuntu-latest' }}
run: dnf install -y make automake gcc gcc-c++ kernel-devel cmake git python3 python3-pip python3-devel

- name: 📋 Install OpenMP
shell: bash
if: ${{ inputs.container == 'macos-latest' }}
run: |
brew reinstall --build-from-source --formula ./.github/homebrew/libomp.rb
- name: 📋 Install VTK
shell: bash
if: ${{ inputs.install-vtk == 'true' }}
run: dnf install -y vtk vtk-devel
83 changes: 83 additions & 0 deletions .github/homebrew/libomp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# SPDX-License-Identifier: BSD-2-Clause

class Libomp < Formula
desc "LLVM's OpenMP runtime library"
homepage "https://openmp.llvm.org/"
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/openmp-15.0.7.src.tar.xz"
sha256 "3f168d38e7a37b928dcb94b33ce947f75d81eef6fa6a4f9d16b6dc5511c07358"
license "MIT"

livecheck do
url :stable
regex(/^llvmorg[._-]v?(\d+(?:\.\d+)+)$/i)
end

bottle do
sha256 cellar: :any, arm64_ventura: "8c5c7b912a075e598fb7ae10f2999853343b2662061d92040b1a584cbb3ba7d2"
sha256 cellar: :any, arm64_monterey: "1b1aad07e8677744cdaa264419fade98bd1a852894c77d01985053a96b7d1c7d"
sha256 cellar: :any, arm64_big_sur: "00e04fbe9783ad7751eaa6d2edda92dfbff85131777255a74e364f3217a7a2df"
sha256 cellar: :any, ventura: "762c461db6af3cf78983b1eb58aee62699652b96237abf79469c8ac034b2156b"
sha256 cellar: :any, monterey: "0b944a6bbe8955e7900882b94f1b0b09030d5791191dc5b0c8b3d5d0895f4b12"
sha256 cellar: :any, big_sur: "f92e5b31f86c22c0fe875b50e050c19a89993b36106a9ad2737230ae2cb68069"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d2a16a906c029e8405a11924837417ad1008d41bb1877399f494cb872a179f01"
end

# Ref: https://github.com/Homebrew/homebrew-core/issues/112107
keg_only "it can override GCC headers and result in broken builds"

depends_on "cmake" => :build
depends_on "lit" => :build
uses_from_macos "llvm" => :build

resource "cmake" do
url "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/cmake-15.0.7.src.tar.xz"
sha256 "8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea"
end

def install
(buildpath/"src").install buildpath.children
(buildpath/"cmake").install resource("cmake")

# Disable LIBOMP_INSTALL_ALIASES, otherwise the library is installed as
# libgomp alias which can conflict with GCC's libgomp.
args = ["-DLIBOMP_INSTALL_ALIASES=OFF"]
args << "-DOPENMP_ENABLE_LIBOMPTARGET=OFF" if OS.linux?

# Build universal binary
ENV.permit_arch_flags
ENV.runtime_cpu_detection
args << "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64"

system "cmake", "-S", "src", "-B", "build/shared", *std_cmake_args, *args
system "cmake", "--build", "build/shared"
system "cmake", "--install", "build/shared"

system "cmake", "-S", "src", "-B", "build/static",
"-DLIBOMP_ENABLE_SHARED=OFF",
*std_cmake_args, *args
system "cmake", "--build", "build/static"
system "cmake", "--install", "build/static"
end

test do
(testpath/"test.cpp").write <<~EOS
#include <omp.h>
#include <array>
int main (int argc, char** argv) {
std::array<size_t,2> arr = {0,0};
#pragma omp parallel num_threads(2)
{
size_t tid = omp_get_thread_num();
arr.at(tid) = tid + 1;
}
if(arr.at(0) == 1 && arr.at(1) == 2)
return 0;
else
return 1;
}
EOS
system ENV.cxx, "-Werror", "-Xpreprocessor", "-fopenmp", "test.cpp", "-std=c++11",
"-I#{include}", "-L#{lib}", "-lomp", "-o", "test"
system "./test"
end
end
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 🧪 Run Tests

on:
push:
pull_request:
workflow_dispatch:

jobs:
test:
strategy:
fail-fast: false

matrix:
config:
- Debug
- Release
os:
- macos-latest
- ubuntu-latest
- windows-latest

vtk-system: [true, false]

exclude:
- os: macos-latest
vtk-system: true

- os: windows-latest
vtk-system: true

runs-on: ${{ matrix.os }}
container: ${{ matrix.os == 'ubuntu-latest' && 'fedora:38' || null }}

name: '🧪 Test on ${{ matrix.os }} ["${{ matrix.config }}", VTK: "${{ matrix.vtk-system }}"]'

steps:
- name: 📥 Checkout
uses: actions/checkout@v3

- name: 🖥️ Setup Environment
uses: ./.github/actions/setup
with:
container: ${{ matrix.os }}
install-vtk: ${{ matrix.vtk-system }}

- name: 🦥 Cache Dependencies
uses: actions/cache@v3
with:
key: test-${{ matrix.os }}-${{ matrix.config }}-${{ matrix.vtk-system }}
path: build

- name: 🏗️ Compile
run: cmake -DVIENNAPS_BUILD_TESTS=ON -B build && cmake --build build --config ${{ matrix.config }}

- name: 🧪 Test
run: ctest -E "Benchmark|Performance" -C ${{ matrix.config }} --test-dir build
30 changes: 0 additions & 30 deletions .github/workflows/check_source.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 🔍 Check Formatting

on:
push:
pull_request:
workflow_dispatch:

jobs:
check-coding-style:
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout
uses: actions/checkout@v3

- name: 📋 Install Dependencies
run: pip install -U cmakelang

- name: 🏗️ Format
run: ./format-project.sh

- name: 🔍 Check changes
run: |
if [[ $(git diff-index --name-only --exit-code HEAD) ]]; then
git diff
exit -1
fi
Loading

0 comments on commit 1af21bd

Please sign in to comment.