Skip to content

Commit

Permalink
CMake Refactor (#42)
Browse files Browse the repository at this point in the history
* refactor: cmake & workflows

* fix: add tbb if not found

* refactor(actions): install tbb

* refactor(cmake): disable tbb strict

* fix(ci/windows): install tbb

* refactor(ci/test): update cmake command

* fix: format

* refactor(actions): skip long paths

* fix(workflows): name

* fix(windows): setup environment

* fix(deps): tbb post-install script

* fix: format

* refactor(ci): more aggressive caching

* refactor: reduce "export_all_symbols" scope to ViennaRay

* fix(deps): local TBB name

* docs(readme): update local installation

* refactor: only setup embree/tbb when required

* docs(readme): add code-block
  • Loading branch information
Curve authored Mar 1, 2024
1 parent 214ae69 commit 0cc162d
Show file tree
Hide file tree
Showing 60 changed files with 538 additions and 658 deletions.
3 changes: 3 additions & 0 deletions .cmake-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include: ["cmake/.cpm-format"]
format:
line_width: 100
23 changes: 23 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 🏗️ Setup Environment
description: Install Dependencies & Deploy Workarounds

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

runs:
using: "composite"

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

- name: 📋 Install OpenMP
shell: bash
if: ${{ inputs.container == 'macos-latest' }}
run: |
brew reinstall --build-from-source --formula ./.github/homebrew/libomp.rb
brew install tbb
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
49 changes: 0 additions & 49 deletions .github/workflows/linux_test.yml

This file was deleted.

57 changes: 0 additions & 57 deletions .github/workflows/macos_test.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 🧪 Run Tests

on:
push:
pull_request:
workflow_dispatch:

jobs:
test:
strategy:
fail-fast: false

matrix:
config: [Release, Debug]
os: [ubuntu-latest, windows-latest, macos-latest]

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

name: '🧪 Test on ${{ matrix.os }} [Config: "${{ matrix.config }}"]'

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

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

- name: 🦥 Cache Dependencies
uses: actions/cache@v3
with:
key: ${{ matrix.os }}-${{ matrix.config }}-cache
path: |
deps-cache
- name: 🦥 Cache Build
uses: actions/cache@v3
with:
key: ${{ matrix.os }}-${{ matrix.config }}-build-cache
path: |
build
- name: 🏗️ Compile
run: cmake -B build -DCPM_SOURCE_CACHE=deps-cache -DVIENNARAY_BUILD_TESTS=ON && cmake --build build --config ${{ matrix.config }}

- name: 🧪 Test
run: ctest -C ${{ matrix.config }} --test-dir build
37 changes: 0 additions & 37 deletions .github/workflows/windows_test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dependencies*
.vs
CMakeSettings.json
docs/doxygen/*.txt
!docs/doxygen/doxygen_template.txt
!docs/doxygen/doxygen_template.txt
Loading

0 comments on commit 0cc162d

Please sign in to comment.