From cc64fe176a26896aaf9f20e33d6c79eff50ed898 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 15 Nov 2024 19:56:30 +0800 Subject: [PATCH 01/46] enable emscripten build with tbb enabled --- CMakeLists.txt | 28 +++++++++++++++++++++++++--- bindings/wasm/bindings.cpp | 26 ++++++++++++++++++++++++++ bindings/wasm/bindings.js | 3 +++ test/test_main.cpp | 21 +++++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 281ff20e1..2fdad7299 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,15 +129,37 @@ endif() if(EMSCRIPTEN) message("Building for Emscripten") + string( + APPEND + CMAKE_EXE_LINKER_FLAGS + # note: the memory limit is set to 4GB because we have test cases that + # cannot run with 2GB of memory when run in parallel. + "-sALLOW_MEMORY_GROWTH=1 -sALLOW_TABLE_GROWTH=1 -sMAXIMUM_MEMORY=4294967296 " + ) + if(MANIFOLD_PAR) + set(CMAKE_THREAD_LIBS_INIT "-pthread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") + string( + APPEND + CMAKE_EXE_LINKER_FLAGS + # notes: + # 1. PTHREAD_POOL_SIZE is set to 4 for OK-ish performance, in general we + # are not getting too much speedup for very large number of cores, and a + # lot of CPUs now have 4 cores... + # 2. mimalloc is needed for good performance + # 3. The default stack size apparently causes problem when parallelization + # is enabled. + "-sPTHREAD_POOL_SIZE=4 -pthread -sMALLOC=mimalloc -sSTACK_SIZE=10MB " + ) + endif() if(MANIFOLD_EXCEPTIONS) list(APPEND MANIFOLD_FLAGS -fexceptions) string( APPEND CMAKE_EXE_LINKER_FLAGS - "-sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0 " + "-fexceptions -sDISABLE_EXCEPTION_CATCHING=0 " ) - else() - string(APPEND CMAKE_EXE_LINKER_FLAGS "-sALLOW_MEMORY_GROWTH=1 ") endif() set(MANIFOLD_PYBIND OFF) set(BUILD_SHARED_LIBS OFF) diff --git a/bindings/wasm/bindings.cpp b/bindings/wasm/bindings.cpp index c48fcfd30..55376c6b9 100644 --- a/bindings/wasm/bindings.cpp +++ b/bindings/wasm/bindings.cpp @@ -22,6 +22,29 @@ #include "manifold/manifold.h" #include "manifold/polygon.h" +#if (MANIFOLD_PAR == 1) +#include + +#include +#endif + +void initTBB() { +#if (MANIFOLD_PAR == 1) + int num_threads = tbb::this_task_arena::max_concurrency(); + std::atomic barrier{num_threads}; + tbb::parallel_for( + 0, num_threads, + [&barrier](int) { + barrier--; + while (barrier > 0) { + // Send browser thread to event loop + std::this_thread::yield(); + } + }, + tbb::static_partitioner{}); +#endif +} + using namespace emscripten; using namespace manifold; @@ -195,4 +218,7 @@ EMSCRIPTEN_BINDINGS(whatever) { function("setCircularSegments", &Quality::SetCircularSegments); function("getCircularSegments", &Quality::GetCircularSegments); function("resetToCircularDefaults", &Quality::ResetToDefaults); + + // https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations + function("initTBB", &initTBB); } diff --git a/bindings/wasm/bindings.js b/bindings/wasm/bindings.js index b03b745f9..9ccaaedf6 100644 --- a/bindings/wasm/bindings.js +++ b/bindings/wasm/bindings.js @@ -17,6 +17,9 @@ Module.setup = function() { if (_ManifoldInitialized) return; _ManifoldInitialized = true; + // warmup tbb for emscripten, according to + // https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations + Module.initTBB(); // conversion utilities function toVec(vec, list, f = x => x) { diff --git a/test/test_main.cpp b/test/test_main.cpp index 79728e40b..250a76133 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -25,6 +25,10 @@ #define FrameMarkEnd(x) #endif +#if (MANIFOLD_PAR == 1) +#include +#endif + using namespace manifold; Options options; @@ -42,6 +46,23 @@ void print_usage() { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + // warmup tbb for emscripten, according to + // https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations +#if defined(__EMSCRIPTEN__) && (MANIFOLD_PAR == 1) + int num_threads = tbb::this_task_arena::max_concurrency(); + std::atomic barrier{num_threads}; + tbb::parallel_for( + 0, num_threads, + [&barrier](int) { + barrier--; + while (barrier > 0) { + // Send browser thread to event loop + std::this_thread::yield(); + } + }, + tbb::static_partitioner{}); +#endif + const char* name = "test setup"; FrameMarkStart(name); From 595b633f320ee4807746910c80fd06f310755887 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 15 Nov 2024 19:57:02 +0800 Subject: [PATCH 02/46] nix: fix emscripten build, add tbb build --- .github/workflows/manifold.yml | 9 +- flake.lock | 56 ++++-- flake.nix | 315 +++++++++++++++++++-------------- 3 files changed, 236 insertions(+), 144 deletions(-) diff --git a/.github/workflows/manifold.yml b/.github/workflows/manifold.yml index 7473f8b38..66ba999a5 100644 --- a/.github/workflows/manifold.yml +++ b/.github/workflows/manifold.yml @@ -240,13 +240,12 @@ jobs: timeout-minutes: 30 strategy: matrix: - # variant: [none, tbb, js] - # disabling js variant for now - variant: [none, tbb] + variant: [none, tbb, js, js-tbb] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v22 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - run: nix build -L '.?submodules=1#manifold-${{matrix.variant}}' build_nix_python: @@ -254,5 +253,5 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v22 + - uses: DeterminateSystems/nix-installer-action@main - run: nix build -L '.?submodules=1#manifold3d' diff --git a/flake.lock b/flake.lock index f6676b347..da17620ff 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "clipper2-src": { "flake": false, "locked": { - "lastModified": 1715688111, - "narHash": "sha256-iy2QV8IVEEIPijWIpzIQtqIQeTU4bfiH41pC0X6m72U=", + "lastModified": 1728932753, + "narHash": "sha256-m/uKGB3BHFRk0wrd71+/oURqxIR1/qQngm77No41la0=", "owner": "AngusJohnson", "repo": "Clipper2", - "rev": "ff378668baae3570e9d8070aa9eb339bdd5a6aba", + "rev": "ed98928c66707988d4eb2c49a31c41380a08931c", "type": "github" }, "original": { @@ -21,11 +21,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -34,6 +34,23 @@ "type": "github" } }, + "gersemi-src": { + "flake": false, + "locked": { + "lastModified": 1729957417, + "narHash": "sha256-t9W27lwNKRFAraynAGEawFb1qCW9/b3RCm/jeb9zJXg=", + "owner": "BlankSpruce", + "repo": "gersemi", + "rev": "27f279333ec3308f9910d53fe4dd69d622e4bc55", + "type": "github" + }, + "original": { + "owner": "BlankSpruce", + "ref": "0.17.0", + "repo": "gersemi", + "type": "github" + } + }, "gtest-src": { "flake": false, "locked": { @@ -53,11 +70,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726937504, - "narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=", + "lastModified": 1731139594, + "narHash": "sha256-IigrKK3vYRpUu+HEjPL/phrfh7Ox881er1UEsZvw9Q4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9357f4f23713673f310988025d9dc261c20e70c6", + "rev": "76612b17c0ce71689921ca12d9ffdc9c23ce40b2", "type": "github" }, "original": { @@ -66,12 +83,31 @@ "type": "indirect" } }, + "onetbb-src": { + "flake": false, + "locked": { + "lastModified": 1730395391, + "narHash": "sha256-XOlC1+rf65oEGKDba9N561NuFo1YJhn3Q1CTGtvkn7A=", + "owner": "oneapi-src", + "repo": "oneTBB", + "rev": "0c0ff192a2304e114bc9e6557582dfba101360ff", + "type": "github" + }, + "original": { + "owner": "oneapi-src", + "ref": "v2022.0.0", + "repo": "oneTBB", + "type": "github" + } + }, "root": { "inputs": { "clipper2-src": "clipper2-src", "flake-utils": "flake-utils", + "gersemi-src": "gersemi-src", "gtest-src": "gtest-src", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "onetbb-src": "onetbb-src" } }, "systems": { diff --git a/flake.nix b/flake.nix index 2a1a8a5e9..0628a9c2d 100644 --- a/flake.nix +++ b/flake.nix @@ -9,141 +9,198 @@ url = "github:AngusJohnson/Clipper2"; flake = false; }; - outputs = { self, nixpkgs, flake-utils, gtest-src, clipper2-src }: + inputs.onetbb-src = { + url = "github:oneapi-src/oneTBB/v2022.0.0"; + flake = false; + }; + inputs.gersemi-src = { + url = "github:BlankSpruce/gersemi/0.17.0"; + flake = false; + }; + outputs = + { self + , nixpkgs + , flake-utils + , gtest-src + , clipper2-src + , onetbb-src + , gersemi-src + }: flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - inherit system; - config.allowUnfree = true; - }; - clipper2 = pkgs.clipper2.overrideAttrs (_: _: { - version = "14052024"; - src = clipper2-src; - }); - manifold = - { parallel-backend ? "none" - , doCheck ? true - , build-tools ? [ ] - , ... - }: pkgs.stdenv.mkDerivation { - inherit doCheck; - pname = "manifold-${parallel-backend}"; - version = "2.5.1"; - src = self; - nativeBuildInputs = (with pkgs; [ - cmake - ninja - (python3.withPackages - (ps: with ps; [ nanobind trimesh pytest ])) - gtest - pkg-config - ]) ++ build-tools; - buildInputs = with pkgs; [ - clipper2 - assimp - ]; - cmakeFlags = [ - "-DMANIFOLD_CBIND=ON" - "-DMANIFOLD_EXPORT=ON" - "-DBUILD_SHARED_LIBS=ON" - "-DMANIFOLD_PAR=${pkgs.lib.strings.toUpper parallel-backend}" - ]; - checkPhase = '' - cd test - ./manifold_test - cd ../ - ''; - }; - parallelBackends = [ - { parallel-backend = "none"; } - { - parallel-backend = "tbb"; - build-tools = with pkgs; [ tbb pkg-config ]; - } + let + manifold-version = "2.5.1"; + pkgs = import nixpkgs { + inherit system; + overlays = [ + (final: prev: { + clipper2 = prev.clipper2.overrideAttrs (_: { + version = clipper2-src.rev; + src = clipper2-src; + }); + # https://github.com/NixOS/nixpkgs/pull/343743#issuecomment-2424163602 + binaryen = + let + testsuite = final.fetchFromGitHub { + owner = "WebAssembly"; + repo = "testsuite"; + rev = "e05365077e13a1d86ffe77acfb1a835b7aa78422"; + hash = "sha256-yvZ5AZTPUA6nsD3xpFC0VLthiu2CxVto66RTXBXXeJM="; + }; + in + prev.binaryen.overrideAttrs (_: rec { + version = "119"; + src = pkgs.fetchFromGitHub { + owner = "WebAssembly"; + repo = "binaryen"; + rev = "version_${version}"; + hash = "sha256-JYXtN3CW4qm/nnjGRvv3GxQ0x9O9wHtNYQLqHIYTTOA="; + }; + preConfigure = '' + if [ $doCheck -eq 1 ]; then + sed -i '/googletest/d' third_party/CMakeLists.txt + rmdir test/spec/testsuite + ln -s ${testsuite} test/spec/testsuite + else + cmakeFlagsArray=($cmakeFlagsArray -DBUILD_TESTS=0) + fi + ''; + }); + }) ]; - in - { - packages = (builtins.listToAttrs - (map - (x: { - name = "manifold-" + x.parallel-backend; - value = manifold x; - }) - parallelBackends)) // { - manifold-js = pkgs.buildEmscriptenPackage { - name = "manifold-js"; - version = "2.5.1"; - src = self; - nativeBuildInputs = (with pkgs; [ cmake python39 ]); - buildInputs = [ pkgs.nodejs ]; - configurePhase = '' - cp -r ${clipper2-src} clipper2 - chmod -R +w clipper2 - mkdir -p .emscriptencache - export EM_CACHE=$(pwd)/.emscriptencache - mkdir build - cd build - emcmake cmake -DCMAKE_BUILD_TYPE=Release \ - -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest-src} \ - -DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 .. - ''; - buildPhase = '' - emmake make -j''${NIX_BUILD_CORES} - ''; - checkPhase = '' - cd test - node manifold_test.js - cd ../ - ''; - installPhase = '' - mkdir -p $out - cp {extras,wasm}/*.js $out/ - cp {extras,wasm}/*.wasm $out/ - ''; - }; - # but how should we make it work with other python versions? - manifold3d = with pkgs.python3Packages; buildPythonPackage { - pname = "manifold3d"; - version = "2.5.1"; - src = self; - propagatedBuildInputs = [ - numpy - ]; - buildInputs = with pkgs; [ - tbb - clipper2 - ]; - nativeBuildInputs = with pkgs; [ - cmake - ninja - setuptools - scikit-build-core - pyproject-metadata - pathspec - pkg-config - ]; - checkInputs = [ - nanobind - trimesh - pytest - ]; - format = "pyproject"; - dontUseCmakeConfigure = true; - doCheck = true; - checkPhase = '' - python3 bindings/python/examples/run_all.py - python3 -m pytest - ''; - }; - }; - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ + }; + onetbb = pkgs.tbb_2021_11.overrideAttrs (_: { + version = onetbb-src.rev; + src = onetbb-src; + }); + gersemi = with pkgs.python3Packages; buildPythonPackage { + pname = "gersemi"; + version = "0.17.0"; + src = gersemi-src; + propagatedBuildInputs = [ + appdirs + lark + pyyaml + ]; + doCheck = true; + }; + manifold = + { parallel ? true }: pkgs.stdenv.mkDerivation { + pname = "manifold-${if parallel then "tbb" else "none"}"; + version = manifold-version; + src = self; + nativeBuildInputs = (with pkgs; [ cmake - tbb + ninja + (python3.withPackages + (ps: with ps; [ nanobind trimesh pytest ])) gtest + ]) ++ (if parallel then [ onetbb ] else [ ]); + buildInputs = with pkgs; [ + clipper2 + assimp ]; + cmakeFlags = [ + "-DMANIFOLD_CBIND=ON" + "-DMANIFOLD_EXPORT=ON" + "-DBUILD_SHARED_LIBS=ON" + "-DMANIFOLD_PAR=${if parallel then "ON" else "OFF"}" + ]; + checkPhase = '' + cd test + ./manifold_test + cd ../ + ''; }; - } + manifold-emscripten = { parallel }: pkgs.buildEmscriptenPackage { + name = "manifold-js"; + version = manifold-version; + src = self; + nativeBuildInputs = (with pkgs; [ cmake python39 ]); + buildInputs = [ pkgs.nodejs ]; + configurePhase = '' + cp -r ${clipper2-src} clipper2 + chmod -R +w clipper2 + mkdir -p .emscriptencache + export EM_CACHE=$(pwd)/.emscriptencache + mkdir build + cd build + emcmake cmake -DCMAKE_BUILD_TYPE=Release \ + -DMANIFOLD_PAR=${if parallel then "ON" else "OFF"} \ + -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest-src} \ + -DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 \ + ${if parallel then "-DFETCHCONTENT_SOURCE_DIR_TBB=${onetbb-src}" else ""} .. + ''; + buildPhase = '' + emmake make -j''${NIX_BUILD_CORES} + ''; + checkPhase = '' + cd test + node manifold_test.js + cd ../ + ''; + installPhase = '' + mkdir -p $out + cp {extras,wasm}/*.js $out/ + cp {extras,wasm}/*.wasm $out/ + ''; + }; + in + { + packages = { + manifold-tbb = manifold { }; + manifold-none = manifold { parallel = false; }; + manifold-js = manifold-emscripten { parallel = false; }; + manifold-js-tbb = manifold-emscripten { parallel = true; }; + # but how should we make it work with other python versions? + manifold3d = with pkgs.python3Packages; buildPythonPackage { + pname = "manifold3d"; + version = manifold-version; + src = self; + propagatedBuildInputs = [ numpy ]; + buildInputs = [ onetbb clipper2 ]; + nativeBuildInputs = with pkgs; [ + cmake + ninja + setuptools + scikit-build-core + pyproject-metadata + pathspec + ]; + checkInputs = [ nanobind trimesh pytest ]; + format = "pyproject"; + dontUseCmakeConfigure = true; + doCheck = true; + checkPhase = '' + python3 bindings/python/examples/run_all.py + python3 -m pytest + ''; + }; + }; + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + (python3.withPackages (ps: with ps; [ + # test dependencies + trimesh + numpy + pytest + + # formatting tools + gersemi + black + ])) + + ninja + cmake + onetbb + gtest + assimp + + # useful tools + clang-tools_18 + clang_18 + ]; + }; + } ); } From 7032c4bfff3a917c963d5dd81268fa3b8b6a54b3 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 15 Nov 2024 20:23:25 +0800 Subject: [PATCH 03/46] browser --- bindings/wasm/examples/README.md | 5 +++++ bindings/wasm/examples/vite.config.js | 6 ++++++ bindings/wasm/fixup.sh | 3 +++ flake.nix | 3 +-- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 bindings/wasm/fixup.sh diff --git a/bindings/wasm/examples/README.md b/bindings/wasm/examples/README.md index d394e45c9..da5146ebb 100644 --- a/bindings/wasm/examples/README.md +++ b/bindings/wasm/examples/README.md @@ -43,3 +43,8 @@ To use the manifoldCAD.org editor (`npm run dev`), you'll likely have to set discussion of the [issue#328](https://github.com/elalish/manifold/issues/328#issuecomment-1473847102) of this repository. + +## Fixing Vite Static Worker Option Error + +Run `fixup.sh` in `bindings/wasm`. + diff --git a/bindings/wasm/examples/vite.config.js b/bindings/wasm/examples/vite.config.js index b5e5fadd1..9676c2d75 100644 --- a/bindings/wasm/examples/vite.config.js +++ b/bindings/wasm/examples/vite.config.js @@ -7,6 +7,12 @@ export default defineConfig({ worker: { format: 'es', }, + server: { + headers: { + 'Cross-Origin-Embedder-Policy': 'require-corp', + 'Cross-Origin-Opener-Policy': 'same-origin', + }, + }, build: { target: 'esnext', sourcemap: true, diff --git a/bindings/wasm/fixup.sh b/bindings/wasm/fixup.sh new file mode 100644 index 000000000..6cab53f94 --- /dev/null +++ b/bindings/wasm/fixup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +sed -i 's/var workerOptions={type:"module",workerData:"em-pthread",name:"em-pthread"};//g' ./examples/built/manifold.js +sed -i 's/workerOptions/{type:"module",workerData:"em-pthread",name:"em-pthread"}/g' ./examples/built/manifold.js diff --git a/flake.nix b/flake.nix index 0628a9c2d..bcce0278d 100644 --- a/flake.nix +++ b/flake.nix @@ -141,8 +141,7 @@ ''; installPhase = '' mkdir -p $out - cp {extras,wasm}/*.js $out/ - cp {extras,wasm}/*.wasm $out/ + cp bindings/wasm/manifold.* $out/ ''; }; in From 568ebbf628eff6f40519da6b71c61e2cc7874c0f Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 15 Nov 2024 20:26:34 +0800 Subject: [PATCH 04/46] fix python build --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index bcce0278d..4a15eb402 100644 --- a/flake.nix +++ b/flake.nix @@ -157,7 +157,7 @@ version = manifold-version; src = self; propagatedBuildInputs = [ numpy ]; - buildInputs = [ onetbb clipper2 ]; + buildInputs = [ onetbb pkgs.clipper2 ]; nativeBuildInputs = with pkgs; [ cmake ninja From 8e71a37f388d87bc000c73210f01c75914e84f95 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 15 Nov 2024 23:53:10 +0800 Subject: [PATCH 05/46] minor --- bindings/wasm/fixup.sh | 0 flake.nix | 2 ++ 2 files changed, 2 insertions(+) mode change 100644 => 100755 bindings/wasm/fixup.sh diff --git a/bindings/wasm/fixup.sh b/bindings/wasm/fixup.sh old mode 100644 new mode 100755 diff --git a/flake.nix b/flake.nix index 4a15eb402..594a04385 100644 --- a/flake.nix +++ b/flake.nix @@ -194,10 +194,12 @@ onetbb gtest assimp + clipper2 # useful tools clang-tools_18 clang_18 + tracy ]; }; } From ae78dd162297998d7be7370814e8a5ee784ccdb5 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 00:35:16 +0800 Subject: [PATCH 06/46] no parallel sdf for js --- bindings/wasm/helpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/wasm/helpers.cpp b/bindings/wasm/helpers.cpp index 66bf70b9e..c9104017a 100644 --- a/bindings/wasm/helpers.cpp +++ b/bindings/wasm/helpers.cpp @@ -208,7 +208,7 @@ Manifold SetProperties(Manifold& manifold, int numProp, uintptr_t funcPtr) { Manifold LevelSet(uintptr_t funcPtr, Box bounds, double edgeLength, double level, double tolerance) { double (*f)(const vec3&) = reinterpret_cast(funcPtr); - return Manifold::LevelSet(f, bounds, edgeLength, level, tolerance); + return Manifold::LevelSet(f, bounds, edgeLength, level, tolerance, false); } std::vector Split(Manifold& a, Manifold& b) { From e5960b2b350e05aca798c46dbca79a0889e92c09 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 00:42:53 +0800 Subject: [PATCH 07/46] disable test for emscripten-tbb --- flake.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 594a04385..f37f57ff8 100644 --- a/flake.nix +++ b/flake.nix @@ -112,7 +112,7 @@ cd ../ ''; }; - manifold-emscripten = { parallel }: pkgs.buildEmscriptenPackage { + manifold-emscripten = { parallel, doCheck ? true }: pkgs.buildEmscriptenPackage { name = "manifold-js"; version = manifold-version; src = self; @@ -134,11 +134,11 @@ buildPhase = '' emmake make -j''${NIX_BUILD_CORES} ''; - checkPhase = '' + checkPhase = if doCheck then '' cd test node manifold_test.js cd ../ - ''; + '' else ""; installPhase = '' mkdir -p $out cp bindings/wasm/manifold.* $out/ @@ -150,7 +150,11 @@ manifold-tbb = manifold { }; manifold-none = manifold { parallel = false; }; manifold-js = manifold-emscripten { parallel = false; }; - manifold-js-tbb = manifold-emscripten { parallel = true; }; + # disable check for now + manifold-js-tbb = manifold-emscripten { + parallel = true; + doCheck = false; + }; # but how should we make it work with other python versions? manifold3d = with pkgs.python3Packages; buildPythonPackage { pname = "manifold3d"; From 162ca3c873717422723cee5bfa51f1bb7e56c648 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 16:07:41 +0800 Subject: [PATCH 08/46] add cache for nix python build --- .github/workflows/manifold.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/manifold.yml b/.github/workflows/manifold.yml index 1ff02a0ba..352c3b6fd 100644 --- a/.github/workflows/manifold.yml +++ b/.github/workflows/manifold.yml @@ -237,18 +237,11 @@ jobs: timeout-minutes: 30 strategy: matrix: - variant: [none, tbb, js, js-tbb] + variant: [manifold-none, manifold-tbb, manifold-js, manifold-js-tbb, manifold3d] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main - - run: nix build -L '.?submodules=1#manifold-${{matrix.variant}}' + - run: nix build -L '.?submodules=1#${{matrix.variant}}' - build_nix_python: - timeout-minutes: 30 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: DeterminateSystems/nix-installer-action@main - - run: nix build -L '.?submodules=1#manifold3d' From b3bed73c769eb5322e0636697912d7e1f265e442 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 22:21:15 +0800 Subject: [PATCH 09/46] cmake changes --- CMakeLists.txt | 283 ++++-------------- bindings/c/CMakeLists.txt | 22 +- bindings/python/CMakeLists.txt | 16 +- bindings/wasm/CMakeLists.txt | 16 +- cmake/info.cmake | 63 ++++ manifold.pc.in => cmake/manifold.pc.in | 0 .../manifoldConfig.cmake.in | 0 cmake/manifoldDeps.cmake | 140 +++++++++ extras/CMakeLists.txt | 5 - samples/CMakeLists.txt | 1 - src/CMakeLists.txt | 128 ++++---- test/CMakeLists.txt | 28 -- 12 files changed, 338 insertions(+), 364 deletions(-) create mode 100644 cmake/info.cmake rename manifold.pc.in => cmake/manifold.pc.in (100%) rename manifoldConfig.cmake.in => cmake/manifoldConfig.cmake.in (100%) create mode 100644 cmake/manifoldDeps.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 268a4d3a4..f6a2fde0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_VERBOSE_MAKEFILE ON) +include(GNUInstallDirs) +include(CMakeDependentOption) + # Define Manifold version set(MANIFOLD_VERSION_MAJOR 2) set(MANIFOLD_VERSION_MINOR 5) @@ -31,20 +34,6 @@ set( "${MANIFOLD_VERSION_MAJOR}.${MANIFOLD_VERSION_MINOR}.${MANIFOLD_VERSION_PATCH}" ) -# Correct MANIFOLD_PAR values to on/off (previous NONE/TBB values should still -# work this way) -if(DEFINED MANIFOLD_PAR) - if( - "${MANIFOLD_PAR}" STREQUAL "" - OR "${MANIFOLD_PAR}" STREQUAL "NONE" - OR "${MANIFOLD_PAR}" STREQUAL "OFF" - ) - set(MANIFOLD_PAR OFF) - else() - set(MANIFOLD_PAR ON) - endif() -endif() - # Primary user facing options option(MANIFOLD_CROSS_SECTION "Build CrossSection for 2D support" ON) option(MANIFOLD_DEBUG "Enable debug tracing/timing" OFF) @@ -57,12 +46,12 @@ option(MANIFOLD_EXPORT "Build mesh export (via assimp) utility library" OFF) option(MANIFOLD_PAR "Enable Parallel backend" OFF) option( MANIFOLD_OPTIMIZED - "Force Optimized build, even with debugging enabled" + "Force optimized build, even with debugging enabled" OFF ) option(MANIFOLD_TEST "Enable testing suite" ON) -option(BUILD_SHARED_LIBS "Build shared library" ON) -include(CMakeDependentOption) +option(MANIFOLD_PYBIND "Build python bindings" OFF) +# MANIFOLD_CBIND is only available when MANIFOLD_CROSS_SECTION is enabled cmake_dependent_option( MANIFOLD_CBIND "Build C (FFI) bindings" @@ -70,7 +59,7 @@ cmake_dependent_option( "MANIFOLD_CROSS_SECTION" OFF ) -option(MANIFOLD_PYBIND "Build python bindings" OFF) +# MANIFOLD_JSBIND is only available when building with Emscripten cmake_dependent_option( MANIFOLD_JSBIND "Build js binding" @@ -79,25 +68,21 @@ cmake_dependent_option( OFF ) +# default to Release build +option(CMAKE_BUILD_TYPE "Build type" Release) +# default to building shared library +option(BUILD_SHARED_LIBS "Build shared library" ON) # Set some option values in the CMake cache -if(NOT MANIFOLD_FLAGS) - set(MANIFOLD_FLAGS "") -endif() set(MANIFOLD_FLAGS "" CACHE STRING "Manifold compiler flags") # Development options option(TRACY_ENABLE "Use tracy profiling" OFF) option(TRACY_MEMORY_USAGE "Track memory allocation with tracy (expensive)" OFF) +option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF) mark_as_advanced(TRACY_ENABLE) mark_as_advanced(TRACY_MEMORY_USAGE) - -# fuzztest is a rather large dependency -option(MANIFOLD_FUZZ "Enable fuzzing tests" OFF) mark_as_advanced(MANIFOLD_FUZZ) -# Define some paths for CMake -include(GNUInstallDirs) - # Always build position independent code for relocatability set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -111,34 +96,23 @@ if(MANIFOLD_FUZZ) # enable fuzztest fuzzing mode set(FUZZTEST_FUZZING_MODE ON) # address sanitizer required - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + add_compile_options("-fsanitize=address") endif() if(TRACY_ENABLE) option(CMAKE_BUILD_TYPE "Build type" RelWithDebInfo) - if(TRACY_MEMORY_USAGE) - list(APPEND MANIFOLD_FLAGS -DTRACY_MEMORY_USAGE) - endif() - if(NOT MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer") - endif() -else() - option(CMAKE_BUILD_TYPE "Build type" Release) endif() if(EMSCRIPTEN) message("Building for Emscripten") + add_link_options("-s ALLOW_MEMORY_GROWTH=1") if(MANIFOLD_DEBUG) list(APPEND MANIFOLD_FLAGS -fexceptions) - string( - APPEND - CMAKE_EXE_LINKER_FLAGS - "-sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0 " - ) - else() - string(APPEND CMAKE_EXE_LINKER_FLAGS "-sALLOW_MEMORY_GROWTH=1 ") + add_link_options("-fexceptions") + add_link_options("-s DISABLE_EXCEPTION_CATCHING=0") endif() set(MANIFOLD_PYBIND OFF) + set(MANIFOLD_CBIND OFF) set(BUILD_SHARED_LIBS OFF) endif() @@ -153,23 +127,13 @@ endif() if(MSVC) list(APPEND MANIFOLD_FLAGS /DNOMINMAX /bigobj) else() - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - list(APPEND WARNING_FLAGS -Wall -Wno-unknown-warning-option -Wno-unused) - else() - list( - APPEND - WARNING_FLAGS - -Wall - -Wno-unknown-warning-option - -Wno-unused - -Wno-shorten-64-to-32 - ) - endif() + list(APPEND WARNING_FLAGS -Wall -Wno-unknown-warning-option -Wno-unused -Wno-shorten-64-to-32) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") list(APPEND WARNING_FLAGS -Wno-format) endif() - else() + elseif(PROJECT_IS_TOP_LEVEL) + # only do -Werror if we are the top level project list(APPEND WARNING_FLAGS -Werror) endif() list(APPEND MANIFOLD_FLAGS ${WARNING_FLAGS}) @@ -180,19 +144,20 @@ else() ) list(APPEND MANIFOLD_FLAGS -O3) endif() -endif() - -if(CODE_COVERAGE AND NOT MSVC) - list( - APPEND - COVERAGE_FLAGS - -coverage - -fno-inline-small-functions - -fkeep-inline-functions - -fkeep-static-functions - ) - list(APPEND MANIFOLD_FLAGS ${COVERAGE_FLAGS}) - add_link_options("-coverage") + if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + list(APPEND MANIFOLD_FLAGS -fno-omit-frame-pointer) + endif() + if(CODE_COVERAGE) + list( + APPEND + MANIFOLD_FLAGS + -coverage + -fno-inline-small-functions + -fkeep-inline-functions + -fkeep-static-functions + ) + add_link_options("-coverage") + endif() endif() # RPath settings @@ -210,100 +175,7 @@ if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) endif("${isSystemDir}" STREQUAL "-1") -# Dependencies -include(FetchContent) - -function(logmissingdep PKG) - if(NOT MANIFOLD_DOWNLOADS) - if(ARGC EQUAL 3) - set(MSG "${ARGV2} enabled, but ${PKG} was not found ") - string(APPEND MSG "and dependency downloading is disabled. ") - else() - set(MSG "${PKG} not found, and dependency downloading disabled. ") - endif() - string(APPEND MSG "Please install ${PKG} and reconfigure.\n") - message(FATAL_ERROR ${MSG}) - endif() -endfunction() - -# If we're building parallel, we need the requisite libraries -if(MANIFOLD_PAR) - find_package(Threads REQUIRED) - find_package(TBB QUIET) - find_package(PkgConfig QUIET) - if(NOT TBB_FOUND AND PKG_CONFIG_FOUND) - pkg_check_modules(TBB tbb) - endif() - if(NOT TBB_FOUND) - logmissingdep("TBB" , "Parallel mode") - message(STATUS "TBB not found, downloading from source") - set(TBB_TEST OFF CACHE INTERNAL "" FORCE) - set(TBB_STRICT OFF CACHE INTERNAL "" FORCE) - FetchContent_Declare( - TBB - GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git - GIT_TAG v2021.11.0 - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(TBB) - set_property(DIRECTORY ${tbb_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES) - # note: we do want to install tbb to the user machine when built from - # source - if(NOT EMSCRIPTEN) - install(TARGETS tbb) - endif() - endif() -endif() - -# If we're building cross_section, we need Clipper2 -if(MANIFOLD_CROSS_SECTION) - find_package(Clipper2 QUIET) - if(NOT Clipper2_FOUND AND PKG_CONFIG_FOUND) - pkg_check_modules(Clipper2 Clipper2) - endif() - if(Clipper2_FOUND) - add_library(Clipper2 SHARED IMPORTED) - set_property( - TARGET Clipper2 - PROPERTY IMPORTED_LOCATION ${Clipper2_LINK_LIBRARIES} - ) - if(WIN32) - set_property( - TARGET Clipper2 - PROPERTY IMPORTED_IMPLIB ${Clipper2_LINK_LIBRARIES} - ) - endif() - target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) - else() - logmissingdep("Clipper2" , "cross_section") - message(STATUS "clipper2 not found, downloading from source") - set(CLIPPER2_UTILS OFF) - set(CLIPPER2_EXAMPLES OFF) - set(CLIPPER2_TESTS OFF) - set( - CLIPPER2_USINGZ - "OFF" - CACHE STRING - "Preempt cache default of USINGZ (we only use 2d)" - ) - FetchContent_Declare( - Clipper2 - GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git - GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba - GIT_PROGRESS TRUE - SOURCE_SUBDIR CPP - ) - FetchContent_MakeAvailable(Clipper2) - if(NOT EMSCRIPTEN) - install(TARGETS Clipper2) - endif() - endif() -endif() - -# If we're supporting mesh I/O, we need assimp -if(MANIFOLD_EXPORT) - find_package(assimp REQUIRED) -endif() +include(${PROJECT_SOURCE_DIR}/cmake/manifoldDeps.cmake) add_subdirectory(src) add_subdirectory(bindings) @@ -311,55 +183,7 @@ add_subdirectory(samples) add_subdirectory(test) add_subdirectory(extras) -# configuration summary, idea from openscad -# https://github.com/openscad/openscad/blob/master/cmake/Modules/info.cmake -message(STATUS "====================================") -message(STATUS "Manifold Build Configuration Summary") -message(STATUS "====================================") -message(STATUS " ") -if(MXECROSS) - message(STATUS "Environment: MXE") -elseif(APPLE) - message(STATUS "Environment: macOS") -elseif(WIN32) - if(MINGW) - message(STATUS "Environment: msys2") - else() - message(STATUS "Environment: Windows") - endif() -elseif(LINUX) - message(STATUS "Environment: Linux") -elseif(UNIX) - message(STATUS "Environment: Unknown Unix") -else() - message(STATUS "Environment: Unknown") -endif() -message(STATUS " ") -message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") -message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") -message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") -message(STATUS "CPACK_CMAKE_GENERATOR: ${CPACK_CMAKE_GENERATOR}") -message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") -message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") -message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") -message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") -if(APPLE) - message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") - message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") -endif() -message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") -message(STATUS " ") -message(STATUS "MANIFOLD_PAR: ${MANIFOLD_PAR}") -message(STATUS "MANIFOLD_CROSS_SECTION: ${MANIFOLD_CROSS_SECTION}") -message(STATUS "MANIFOLD_EXPORT: ${MANIFOLD_EXPORT}") -message(STATUS "MANIFOLD_TEST: ${MANIFOLD_TEST}") -message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}") -message(STATUS "MANIFOLD_DEBUG: ${MANIFOLD_DEBUG}") -message(STATUS "MANIFOLD_CBIND: ${MANIFOLD_CBIND}") -message(STATUS "MANIFOLD_PYBIND: ${MANIFOLD_PYBIND}") -message(STATUS "MANIFOLD_JSBIND: ${MANIFOLD_JSBIND}") -message(STATUS "MANIFOLD_FLAGS: ${MANIFOLD_FLAGS}") -message(STATUS " ") +include(${PROJECT_SOURCE_DIR}/cmake/info.cmake) # If it's an EMSCRIPTEN build, we're done if(EMSCRIPTEN) @@ -368,13 +192,13 @@ endif() # CMake exports configure_file( - manifoldConfig.cmake.in + cmake/manifoldConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/manifoldConfig.cmake @ONLY ) include(CMakePackageConfigHelpers) write_basic_package_version_file( - ${CMAKE_BINARY_DIR}/cmake/manifoldConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/manifoldConfigVersion.cmake VERSION ${MANIFOLD_VERSION} COMPATIBILITY SameMajorVersion ) @@ -398,23 +222,20 @@ install( # install public headers set( MANIFOLD_PUBLIC_HDRS - include/manifold/common.h - include/manifold/iters.h - include/manifold/linalg.h - include/manifold/manifold.h - include/manifold/optional_assert.h - include/manifold/parallel.h - include/manifold/polygon.h - include/manifold/vec_view.h + common.h + iters.h + linalg.h + manifold.h + optional_assert.h + parallel.h + polygon.h + vec_view.h + $<$: + cross_section.h> + $<$: + meshIO.h> ) - -if(MANIFOLD_CROSS_SECTION) - list(APPEND MANIFOLD_PUBLIC_HDRS include/manifold/cross_section.h) -endif() - -if(MANIFOLD_EXPORT) - list(APPEND MANIFOLD_PUBLIC_HDRS include/manifold/meshIO.h) -endif() +list(TRANSFORM MANIFOLD_PUBLIC_HDRS PREPEND include/manifold/) install( FILES ${MANIFOLD_PUBLIC_HDRS} @@ -425,7 +246,7 @@ install( if(MANIFOLD_CROSS_SECTION) set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2") endif() -configure_file(manifold.pc.in ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc @ONLY) +configure_file(cmake/manifold.pc.in ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 6c65476c4..9bd481003 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -1,4 +1,17 @@ -# this is a shared library for FFI bindings +# Copyright 2024 The Manifold Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -7,13 +20,15 @@ include_directories( add_library( manifoldc - SHARED manifoldc.cpp conv.cpp box.cpp cross.cpp rect.cpp ) +add_library(manifold::manifoldc ALIAS manifoldc) +set_property(TARGET manifoldc PROPERTY VERSION "${MANIFOLD_VERSION}") +set_property(TARGET manifoldc PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) if(MSVC) set_target_properties(manifoldc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) @@ -38,10 +53,9 @@ target_include_directories( manifoldc PUBLIC $ - $ + $ ) target_compile_options(manifoldc PRIVATE ${MANIFOLD_FLAGS}) -target_compile_features(manifoldc PRIVATE cxx_std_17) install(TARGETS manifoldc EXPORT manifoldTargets) install( diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 4dd16ad15..4bfe513e7 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -16,8 +16,6 @@ if(NOT MANIFOLD_PYBIND) return() endif() -project(python) - if(Python_VERSION VERSION_LESS 3.12) find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) else() @@ -46,8 +44,8 @@ if(NB_VERSION VERSION_GREATER_EQUAL 2.0.0) ) find_package(nanobind CONFIG REQUIRED) else() - message(STATUS "nanobind not found, downloading from source") include(FetchContent) + logmissingdep("nanobind" , "MANIFOLD_PYBIND") FetchContent_Declare( nanobind GIT_REPOSITORY https://github.com/wjakob/nanobind.git @@ -91,12 +89,12 @@ message(Python_EXECUTABLE = ${Python_EXECUTABLE}) # ideally we should generate a dependency file from python... set( DOCSTRING_DEPS - ${CMAKE_SOURCE_DIR}/src/manifold.cpp - ${CMAKE_SOURCE_DIR}/src/constructors.cpp - ${CMAKE_SOURCE_DIR}/src/sort.cpp - ${CMAKE_SOURCE_DIR}/src/cross_section/cross_section.cpp - ${CMAKE_SOURCE_DIR}/src/polygon.cpp - ${CMAKE_SOURCE_DIR}/include/manifold/common.h + ${PROJECT_SOURCE_DIR}/src/manifold.cpp + ${PROJECT_SOURCE_DIR}/src/constructors.cpp + ${PROJECT_SOURCE_DIR}/src/sort.cpp + ${PROJECT_SOURCE_DIR}/src/cross_section/cross_section.cpp + ${PROJECT_SOURCE_DIR}/src/polygon.cpp + ${PROJECT_SOURCE_DIR}/include/manifold/common.h ${CMAKE_CURRENT_SOURCE_DIR}/gen_docs.py ${CMAKE_CURRENT_SOURCE_DIR}/docstring_override.txt ) diff --git a/bindings/wasm/CMakeLists.txt b/bindings/wasm/CMakeLists.txt index e2431082d..8f8a9ba3a 100644 --- a/bindings/wasm/CMakeLists.txt +++ b/bindings/wasm/CMakeLists.txt @@ -46,28 +46,18 @@ add_custom_target( DEPENDS manifoldjs ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts ) -# copy WASM build back here for publishing to npm add_custom_command( TARGET js_deps POST_BUILD + # copy WASM build back here for publishing to npm COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/manifold.* ${CMAKE_CURRENT_SOURCE_DIR} -) - -# copy WASM build and TS declarations for Vite to package into ManifoldCAD.org -add_custom_command( - TARGET js_deps - POST_BUILD + # copy WASM build and TS declarations for Vite to package into ManifoldCAD.org COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold* ${CMAKE_CURRENT_SOURCE_DIR}/examples/built/ -) - -# copy TS declarations to public so they can be accessed by our editor -add_custom_command( - TARGET js_deps - POST_BUILD + # copy TS declarations to public so they can be accessed by our editor COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/manifold*.d.ts ${CMAKE_CURRENT_SOURCE_DIR}/examples/public/ diff --git a/cmake/info.cmake b/cmake/info.cmake new file mode 100644 index 000000000..85ee1c0bd --- /dev/null +++ b/cmake/info.cmake @@ -0,0 +1,63 @@ +# Copyright 2024 The Manifold Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# configuration summary, idea from openscad +# https://github.com/openscad/openscad/blob/master/cmake/Modules/info.cmake +message(STATUS "====================================") +message(STATUS "Manifold Build Configuration Summary") +message(STATUS "====================================") +message(STATUS " ") +if(MXECROSS) + message(STATUS "Environment: MXE") +elseif(APPLE) + message(STATUS "Environment: macOS") +elseif(WIN32) + if(MINGW) + message(STATUS "Environment: msys2") + else() + message(STATUS "Environment: Windows") + endif() +elseif(LINUX) + message(STATUS "Environment: Linux") +elseif(UNIX) + message(STATUS "Environment: Unknown Unix") +else() + message(STATUS "Environment: Unknown") +endif() +message(STATUS " ") +message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") +message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") +message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") +message(STATUS "CPACK_CMAKE_GENERATOR: ${CPACK_CMAKE_GENERATOR}") +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") +message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") +message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") +if(APPLE) + message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") + message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") +endif() +message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") +message(STATUS " ") +message(STATUS "MANIFOLD_PAR: ${MANIFOLD_PAR}") +message(STATUS "MANIFOLD_CROSS_SECTION: ${MANIFOLD_CROSS_SECTION}") +message(STATUS "MANIFOLD_EXPORT: ${MANIFOLD_EXPORT}") +message(STATUS "MANIFOLD_TEST: ${MANIFOLD_TEST}") +message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}") +message(STATUS "MANIFOLD_DEBUG: ${MANIFOLD_DEBUG}") +message(STATUS "MANIFOLD_CBIND: ${MANIFOLD_CBIND}") +message(STATUS "MANIFOLD_PYBIND: ${MANIFOLD_PYBIND}") +message(STATUS "MANIFOLD_JSBIND: ${MANIFOLD_JSBIND}") +message(STATUS "MANIFOLD_FLAGS: ${MANIFOLD_FLAGS}") +message(STATUS " ") diff --git a/manifold.pc.in b/cmake/manifold.pc.in similarity index 100% rename from manifold.pc.in rename to cmake/manifold.pc.in diff --git a/manifoldConfig.cmake.in b/cmake/manifoldConfig.cmake.in similarity index 100% rename from manifoldConfig.cmake.in rename to cmake/manifoldConfig.cmake.in diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake new file mode 100644 index 000000000..e259690b4 --- /dev/null +++ b/cmake/manifoldDeps.cmake @@ -0,0 +1,140 @@ +# Copyright 2024 The Manifold Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +include(FetchContent) + +function(logmissingdep PKG) + # if this is already in FETCHCONTENT_SOURCE_DIR_X, we don't have to + # download... + if(DEFINED FETCHCONTENT_SOURCE_DIR_${PKG}) + return() + endif() + if(NOT MANIFOLD_DOWNLOADS) + if(ARGC EQUAL 3) + set(MSG "${ARGV2} enabled, but ${PKG} was not found ") + string(APPEND MSG "and dependency downloading is disabled. ") + else() + set(MSG "${PKG} not found, and dependency downloading disabled. ") + endif() + string(APPEND MSG "Please install ${PKG} and reconfigure.\n") + message(FATAL_ERROR ${MSG}) + else() + message(STATUS "${PKG} not found, downloading from source") + endif() +endfunction() + +# If we're building parallel, we need the requisite libraries +if(MANIFOLD_PAR) + find_package(Threads REQUIRED) + find_package(TBB QUIET) + find_package(PkgConfig QUIET) + if(NOT TBB_FOUND AND PKG_CONFIG_FOUND) + pkg_check_modules(TBB tbb) + endif() + if(NOT TBB_FOUND) + logmissingdep("TBB" , "Parallel mode") + set(TBB_TEST OFF CACHE INTERNAL BOOL FORCE) + set(TBB_STRICT OFF CACHE INTERNAL BOOL FORCE) + FetchContent_Declare( + TBB + GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git + GIT_TAG v2021.11.0 + GIT_PROGRESS TRUE + EXCLUDE_FROM_ALL + ) + FetchContent_MakeAvailable(TBB) + # note: we do want to install tbb to the user machine when built from + # source + if(NOT EMSCRIPTEN) + install(TARGETS tbb) + endif() + endif() +endif() + +# If we're building cross_section, we need Clipper2 +if(MANIFOLD_CROSS_SECTION) + find_package(Clipper2 QUIET) + if(NOT Clipper2_FOUND AND PKG_CONFIG_FOUND) + pkg_check_modules(Clipper2 Clipper2) + endif() + if(Clipper2_FOUND) + add_library(Clipper2 SHARED IMPORTED) + set_property( + TARGET Clipper2 + PROPERTY IMPORTED_LOCATION ${Clipper2_LINK_LIBRARIES} + ) + if(WIN32) + set_property( + TARGET Clipper2 + PROPERTY IMPORTED_IMPLIB ${Clipper2_LINK_LIBRARIES} + ) + endif() + target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) + else() + logmissingdep("Clipper2" , "cross_section") + set(CLIPPER2_UTILS OFF CACHE INTERNAL BOOL FORCE) + set(CLIPPER2_EXAMPLES OFF CACHE INTERNAL BOOL FORCE) + set(CLIPPER2_TESTS OFF CACHE INTERNAL BOOL FORCE) + set(CLIPPER2_USINGZ OFF CACHE INTERNAL BOOL FORCE) + FetchContent_Declare( + Clipper2 + GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git + GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba + GIT_PROGRESS TRUE + SOURCE_SUBDIR CPP + ) + FetchContent_MakeAvailable(Clipper2) + if(NOT EMSCRIPTEN) + install(TARGETS Clipper2) + endif() + endif() +endif() + +if(TRACY_ENABLE) + logmissingdep("tracy" , "TRACY_ENABLE") + FetchContent_Declare( + tracy + GIT_REPOSITORY https://github.com/wolfpld/tracy.git + GIT_TAG v0.10 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(tracy) +endif() + +# If we're supporting mesh I/O, we need assimp +if(MANIFOLD_EXPORT) + find_package(assimp REQUIRED) +endif() + +if(MANIFOLD_TEST) + find_package(GTest QUIET) + if(NOT GTest_FOUND) + logmissingdep("GTest" , "MANIFOLD_TEST") + set(gtest_force_shared_crt ON CACHE BOOL FORCE) + # Prevent installation of GTest with your project + set(INSTALL_GTEST OFF CACHE BOOL FORCE) + set(INSTALL_GMOCK OFF CACHE BOOL FORCE) + + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + FIND_PACKAGE_ARGS NAMES GTest gtest + ) + FetchContent_MakeAvailable(googletest) + endif() +endif() diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index 427d61d1c..ee87fc70b 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -19,30 +19,25 @@ endif() add_executable(perfTest perf_test.cpp) target_link_libraries(perfTest manifold) target_compile_options(perfTest PRIVATE ${MANIFOLD_FLAGS}) -target_compile_features(perfTest PUBLIC cxx_std_17) if(MANIFOLD_PAR AND NOT MSVC) add_executable(stlTest stl_test.cpp) target_link_libraries(stlTest manifold) target_compile_options(stlTest PRIVATE ${MANIFOLD_FLAGS}) - target_compile_features(stlTest PUBLIC cxx_std_17) endif() add_executable(largeSceneTest large_scene_test.cpp) target_link_libraries(largeSceneTest manifold) target_compile_options(largeSceneTest PRIVATE ${MANIFOLD_FLAGS}) -target_compile_features(largeSceneTest PUBLIC cxx_std_17) if(MANIFOLD_DEBUG) add_executable(minimizeTestcase minimize_testcase.cpp) target_link_libraries(minimizeTestcase manifold) target_compile_options(minimizeTestcase PRIVATE ${MANIFOLD_FLAGS}) - target_compile_features(minimizeTestcase PUBLIC cxx_std_17) endif() if(MANIFOLD_EXPORT) add_executable(convertFile convert_file.cpp) target_link_libraries(convertFile manifold manifold) target_compile_options(convertFile PRIVATE ${MANIFOLD_FLAGS}) - target_compile_features(convertFile PUBLIC cxx_std_17) endif() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index c66db5a8f..7e2dd51be 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -34,4 +34,3 @@ target_include_directories(samples PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_link_libraries(samples PUBLIC manifold) target_compile_options(samples PRIVATE ${MANIFOLD_FLAGS}) -target_compile_features(samples PUBLIC cxx_std_17) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3899c1a3c..878520874 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# For private headers -include_directories("${CMAKE_CURRENT_SOURCE_DIR}") - set( MANIFOLD_SRCS boolean3.cpp @@ -32,6 +29,12 @@ set( smoothing.cpp sort.cpp subdivision.cpp + + # optional source files + $<$: + cross_section/cross_section.cpp> + $<$: + meshIO/meshIO.cpp> ) set( @@ -51,61 +54,45 @@ set( vec.h ) -if(MANIFOLD_CROSS_SECTION) - list(APPEND MANIFOLD_SRCS cross_section/cross_section.cpp) -endif() - -if(MANIFOLD_EXPORT) - list(APPEND MANIFOLD_SRCS meshIO/meshIO.cpp) -endif() - -# Dependency libraries -if(MANIFOLD_CROSS_SECTION) - if(TARGET Clipper2::Clipper2) - list(APPEND MANIFOLD_LIBS Clipper2::Clipper2) - else() - list(APPEND MANIFOLD_LIBS Clipper2) - endif() -endif() -if(MANIFOLD_PAR) - if(TARGET TBB::tbb) - list(APPEND MANIFOLD_LIBS TBB::tbb) - else() - list(APPEND MANIFOLD_LIBS ${TBB_LINK_LIBRARIES}) - endif() -endif() -if(MANIFOLD_EXPORT) - list(APPEND MANIFOLD_LIBS assimp::assimp) -endif() - # Include directories -set(MANIFOLD_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include) -if(TBB_INCLUDE_DIRS) - list(APPEND MANIFOLD_INCLUDE_DIRS ${TBB_INCLUDE_DIRS}) -endif() +set( + MANIFOLD_INCLUDE_DIRS + ${PROJECT_SOURCE_DIR}/include + $<$:${TBB_INCLUDE_DIRS}> +) -add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) -set_property(TARGET manifold PROPERTY VERSION "${MANIFOLD_VERSION}") -set_property(TARGET manifold PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) -if(MSVC) - set_target_properties( - ${PROJECT_NAME} - PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON - ) -endif() -target_link_libraries(manifold PUBLIC ${MANIFOLD_LIBS}) -if(MANIFOLD_FLAGS) - target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) -endif() -target_include_directories( +add_library( + manifold + ${MANIFOLD_SRCS} + ${MANIFOLD_PRIVATE_HDRS} +) + +target_link_libraries( manifold PUBLIC - $ - $ - PRIVATE ${MANIFOLD_INCLUDE_DIRS} + # optional dependencies + $<$: + $, + Clipper2::Clipper2, + Clipper2>> + $<$: + $, + TBB::tbb, + ${TBB_LINK_LIBRARIES}>> + $<$:assimp::assimp> + $<$:TracyClient> ) -set(OPTIONS MANIFOLD_DEBUG MANIFOLD_CROSS_SECTION MANIFOLD_EXPORT) +target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) + +set( + OPTIONS + MANIFOLD_DEBUG + MANIFOLD_CROSS_SECTION + MANIFOLD_EXPORT + TRACY_ENABLE + TRACY_MEMORY_USAGE +) foreach(OPT IN LISTS OPTIONS) if(${${OPT}}) target_compile_options(manifold PUBLIC -D${OPT}) @@ -117,27 +104,22 @@ else() target_compile_options(manifold PUBLIC -DMANIFOLD_PAR=-1) endif() -target_compile_features(manifold PUBLIC cxx_std_17) - -install(TARGETS manifold EXPORT manifoldTargets) +target_include_directories( + manifold + PUBLIC + $ + $ + PRIVATE ${MANIFOLD_INCLUDE_DIRS} +) -# Tracy Support -if(TRACY_ENABLE) - if(NOT MANIFOLD_DOWNLOADS) - message( - WARNING - "Downloading is disabled, but tracy requires download - skipping.\n" - ) - return() - endif() - include(FetchContent) - FetchContent_Declare( - tracy - GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG v0.10 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE +add_library(manifold::manifold ALIAS manifold) +set_property(TARGET manifold PROPERTY VERSION "${MANIFOLD_VERSION}") +set_property(TARGET manifold PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) +if(MSVC) + set_target_properties( + manifold + PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) - FetchContent_MakeAvailable(tracy) - target_link_libraries(manifold PUBLIC TracyClient) endif() + +install(TARGETS manifold EXPORT manifoldTargets) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e7faabded..0544986ff 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,32 +18,6 @@ endif() enable_testing() -find_package(GTest QUIET) -if(NOT GTest_FOUND) - if(NOT MANIFOLD_DOWNLOADS) - message( - WARNING - "Downloading is disabled, but testing requires googletest - skipping.\n" - ) - return() - endif() - - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - # Prevent installation of GTest with your project - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) - - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - FIND_PACKAGE_ARGS NAMES GTest gtest - ) - FetchContent_MakeAvailable(googletest) -endif() # put fast/simple tests files first to run earlier set( @@ -96,10 +70,8 @@ if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) endif() target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) -target_compile_features(manifold_test PUBLIC cxx_std_17) add_test(test_all manifold_test) -target_precompile_headers(manifold_test INTERFACE test.h) if(EMSCRIPTEN) list( From 8a372bfd2ce8895492740418d61aed1b36bf4933 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 22:37:52 +0800 Subject: [PATCH 10/46] fix --- CMakeLists.txt | 6 ++---- cmake/manifoldDeps.cmake | 14 +++++++------- flake.nix | 10 +++++----- src/CMakeLists.txt | 16 ++++------------ 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a2fde0f..d749ad2b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,10 +230,8 @@ set( parallel.h polygon.h vec_view.h - $<$: - cross_section.h> - $<$: - meshIO.h> + $<$:cross_section.h> + $<$:meshIO.h> ) list(TRANSFORM MANIFOLD_PUBLIC_HDRS PREPEND include/manifold/) diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index e259690b4..9bfd058b9 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -82,10 +82,10 @@ if(MANIFOLD_CROSS_SECTION) target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) else() logmissingdep("Clipper2" , "cross_section") - set(CLIPPER2_UTILS OFF CACHE INTERNAL BOOL FORCE) - set(CLIPPER2_EXAMPLES OFF CACHE INTERNAL BOOL FORCE) - set(CLIPPER2_TESTS OFF CACHE INTERNAL BOOL FORCE) - set(CLIPPER2_USINGZ OFF CACHE INTERNAL BOOL FORCE) + set(CLIPPER2_UTILS OFF CACHE INTERNAL BOOL "" FORCE) + set(CLIPPER2_EXAMPLES OFF CACHE INTERNAL BOOL "" FORCE) + set(CLIPPER2_TESTS OFF CACHE INTERNAL BOOL "" FORCE) + set(CLIPPER2_USINGZ OFF CACHE INTERNAL BOOL "" FORCE) FetchContent_Declare( Clipper2 GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git @@ -121,10 +121,10 @@ if(MANIFOLD_TEST) find_package(GTest QUIET) if(NOT GTest_FOUND) logmissingdep("GTest" , "MANIFOLD_TEST") - set(gtest_force_shared_crt ON CACHE BOOL FORCE) + set(gtest_force_shared_crt ON CACHE INTERNAL BOOL "" FORCE) # Prevent installation of GTest with your project - set(INSTALL_GTEST OFF CACHE BOOL FORCE) - set(INSTALL_GMOCK OFF CACHE BOOL FORCE) + set(INSTALL_GTEST OFF CACHE INTERNAL BOOL "" FORCE) + set(INSTALL_GMOCK OFF CACHE INTERNAL BOOL "" FORCE) include(FetchContent) FetchContent_Declare( diff --git a/flake.nix b/flake.nix index 2a1a8a5e9..0706c6cdb 100644 --- a/flake.nix +++ b/flake.nix @@ -22,13 +22,13 @@ src = clipper2-src; }); manifold = - { parallel-backend ? "none" + { parallel-backend ? false , doCheck ? true , build-tools ? [ ] , ... }: pkgs.stdenv.mkDerivation { inherit doCheck; - pname = "manifold-${parallel-backend}"; + pname = "manifold-${if parallelBackends then "tbb" else "none" }"; version = "2.5.1"; src = self; nativeBuildInputs = (with pkgs; [ @@ -47,7 +47,7 @@ "-DMANIFOLD_CBIND=ON" "-DMANIFOLD_EXPORT=ON" "-DBUILD_SHARED_LIBS=ON" - "-DMANIFOLD_PAR=${pkgs.lib.strings.toUpper parallel-backend}" + "-DMANIFOLD_PAR=${if parallelBackends then "ON" else "OFF"}" ]; checkPhase = '' cd test @@ -56,9 +56,9 @@ ''; }; parallelBackends = [ - { parallel-backend = "none"; } + { parallel-backend = true; } { - parallel-backend = "tbb"; + parallel-backend = false; build-tools = with pkgs; [ tbb pkg-config ]; } ]; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 878520874..19fc639f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,10 +31,8 @@ set( subdivision.cpp # optional source files - $<$: - cross_section/cross_section.cpp> - $<$: - meshIO/meshIO.cpp> + $<$:cross_section/cross_section.cpp> + $<$:meshIO/meshIO.cpp> ) set( @@ -71,14 +69,8 @@ target_link_libraries( manifold PUBLIC # optional dependencies - $<$: - $, - Clipper2::Clipper2, - Clipper2>> - $<$: - $, - TBB::tbb, - ${TBB_LINK_LIBRARIES}>> + $<$:$,Clipper2::Clipper2,Clipper2>> + $<$:$,TBB::tbb,${TBB_LINK_LIBRARIES}>> $<$:assimp::assimp> $<$:TracyClient> ) From 590fc5c6969c9f8734124afd944690150dc0f889 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 22:44:50 +0800 Subject: [PATCH 11/46] update --- CMakeLists.txt | 15 +- cmake/manifoldDeps.cmake | 24 +-- flake.lock | 56 +++++-- flake.nix | 320 +++++++++++++++++++++++---------------- scripts/format.sh | 19 +-- src/CMakeLists.txt | 22 +-- test/CMakeLists.txt | 1 - 7 files changed, 278 insertions(+), 179 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d749ad2b6..d632f772c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,14 @@ endif() if(MSVC) list(APPEND MANIFOLD_FLAGS /DNOMINMAX /bigobj) else() - list(APPEND WARNING_FLAGS -Wall -Wno-unknown-warning-option -Wno-unused -Wno-shorten-64-to-32) + list( + APPEND + WARNING_FLAGS + -Wall + -Wno-unknown-warning-option + -Wno-unused + -Wno-shorten-64-to-32 + ) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") list(APPEND WARNING_FLAGS -Wno-format) @@ -244,7 +251,11 @@ install( if(MANIFOLD_CROSS_SECTION) set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2") endif() -configure_file(cmake/manifold.pc.in ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc @ONLY) +configure_file( + cmake/manifold.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc + @ONLY +) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index 9bfd058b9..1bbe32a0d 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -43,8 +43,8 @@ if(MANIFOLD_PAR) endif() if(NOT TBB_FOUND) logmissingdep("TBB" , "Parallel mode") - set(TBB_TEST OFF CACHE INTERNAL BOOL FORCE) - set(TBB_STRICT OFF CACHE INTERNAL BOOL FORCE) + set(TBB_TEST OFF CACHE INTERNAL "" FORCE) + set(TBB_STRICT OFF CACHE INTERNAL "" FORCE) FetchContent_Declare( TBB GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git @@ -82,10 +82,15 @@ if(MANIFOLD_CROSS_SECTION) target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) else() logmissingdep("Clipper2" , "cross_section") - set(CLIPPER2_UTILS OFF CACHE INTERNAL BOOL "" FORCE) - set(CLIPPER2_EXAMPLES OFF CACHE INTERNAL BOOL "" FORCE) - set(CLIPPER2_TESTS OFF CACHE INTERNAL BOOL "" FORCE) - set(CLIPPER2_USINGZ OFF CACHE INTERNAL BOOL "" FORCE) + set(CLIPPER2_UTILS OFF) + set(CLIPPER2_EXAMPLES OFF) + set(CLIPPER2_TESTS OFF) + set( + CLIPPER2_USINGZ + "OFF" + CACHE STRING + "Preempt cache default of USINGZ (we only use 2d)" + ) FetchContent_Declare( Clipper2 GIT_REPOSITORY https://github.com/AngusJohnson/Clipper2.git @@ -121,11 +126,10 @@ if(MANIFOLD_TEST) find_package(GTest QUIET) if(NOT GTest_FOUND) logmissingdep("GTest" , "MANIFOLD_TEST") - set(gtest_force_shared_crt ON CACHE INTERNAL BOOL "" FORCE) + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Prevent installation of GTest with your project - set(INSTALL_GTEST OFF CACHE INTERNAL BOOL "" FORCE) - set(INSTALL_GMOCK OFF CACHE INTERNAL BOOL "" FORCE) - + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) include(FetchContent) FetchContent_Declare( googletest diff --git a/flake.lock b/flake.lock index f6676b347..da17620ff 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "clipper2-src": { "flake": false, "locked": { - "lastModified": 1715688111, - "narHash": "sha256-iy2QV8IVEEIPijWIpzIQtqIQeTU4bfiH41pC0X6m72U=", + "lastModified": 1728932753, + "narHash": "sha256-m/uKGB3BHFRk0wrd71+/oURqxIR1/qQngm77No41la0=", "owner": "AngusJohnson", "repo": "Clipper2", - "rev": "ff378668baae3570e9d8070aa9eb339bdd5a6aba", + "rev": "ed98928c66707988d4eb2c49a31c41380a08931c", "type": "github" }, "original": { @@ -21,11 +21,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -34,6 +34,23 @@ "type": "github" } }, + "gersemi-src": { + "flake": false, + "locked": { + "lastModified": 1729957417, + "narHash": "sha256-t9W27lwNKRFAraynAGEawFb1qCW9/b3RCm/jeb9zJXg=", + "owner": "BlankSpruce", + "repo": "gersemi", + "rev": "27f279333ec3308f9910d53fe4dd69d622e4bc55", + "type": "github" + }, + "original": { + "owner": "BlankSpruce", + "ref": "0.17.0", + "repo": "gersemi", + "type": "github" + } + }, "gtest-src": { "flake": false, "locked": { @@ -53,11 +70,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726937504, - "narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=", + "lastModified": 1731139594, + "narHash": "sha256-IigrKK3vYRpUu+HEjPL/phrfh7Ox881er1UEsZvw9Q4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9357f4f23713673f310988025d9dc261c20e70c6", + "rev": "76612b17c0ce71689921ca12d9ffdc9c23ce40b2", "type": "github" }, "original": { @@ -66,12 +83,31 @@ "type": "indirect" } }, + "onetbb-src": { + "flake": false, + "locked": { + "lastModified": 1730395391, + "narHash": "sha256-XOlC1+rf65oEGKDba9N561NuFo1YJhn3Q1CTGtvkn7A=", + "owner": "oneapi-src", + "repo": "oneTBB", + "rev": "0c0ff192a2304e114bc9e6557582dfba101360ff", + "type": "github" + }, + "original": { + "owner": "oneapi-src", + "ref": "v2022.0.0", + "repo": "oneTBB", + "type": "github" + } + }, "root": { "inputs": { "clipper2-src": "clipper2-src", "flake-utils": "flake-utils", + "gersemi-src": "gersemi-src", "gtest-src": "gtest-src", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "onetbb-src": "onetbb-src" } }, "systems": { diff --git a/flake.nix b/flake.nix index 0706c6cdb..f37f57ff8 100644 --- a/flake.nix +++ b/flake.nix @@ -9,141 +9,203 @@ url = "github:AngusJohnson/Clipper2"; flake = false; }; - outputs = { self, nixpkgs, flake-utils, gtest-src, clipper2-src }: + inputs.onetbb-src = { + url = "github:oneapi-src/oneTBB/v2022.0.0"; + flake = false; + }; + inputs.gersemi-src = { + url = "github:BlankSpruce/gersemi/0.17.0"; + flake = false; + }; + outputs = + { self + , nixpkgs + , flake-utils + , gtest-src + , clipper2-src + , onetbb-src + , gersemi-src + }: flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - inherit system; - config.allowUnfree = true; - }; - clipper2 = pkgs.clipper2.overrideAttrs (_: _: { - version = "14052024"; - src = clipper2-src; - }); - manifold = - { parallel-backend ? false - , doCheck ? true - , build-tools ? [ ] - , ... - }: pkgs.stdenv.mkDerivation { - inherit doCheck; - pname = "manifold-${if parallelBackends then "tbb" else "none" }"; - version = "2.5.1"; - src = self; - nativeBuildInputs = (with pkgs; [ - cmake - ninja - (python3.withPackages - (ps: with ps; [ nanobind trimesh pytest ])) - gtest - pkg-config - ]) ++ build-tools; - buildInputs = with pkgs; [ - clipper2 - assimp - ]; - cmakeFlags = [ - "-DMANIFOLD_CBIND=ON" - "-DMANIFOLD_EXPORT=ON" - "-DBUILD_SHARED_LIBS=ON" - "-DMANIFOLD_PAR=${if parallelBackends then "ON" else "OFF"}" - ]; - checkPhase = '' - cd test - ./manifold_test - cd ../ - ''; - }; - parallelBackends = [ - { parallel-backend = true; } - { - parallel-backend = false; - build-tools = with pkgs; [ tbb pkg-config ]; - } + let + manifold-version = "2.5.1"; + pkgs = import nixpkgs { + inherit system; + overlays = [ + (final: prev: { + clipper2 = prev.clipper2.overrideAttrs (_: { + version = clipper2-src.rev; + src = clipper2-src; + }); + # https://github.com/NixOS/nixpkgs/pull/343743#issuecomment-2424163602 + binaryen = + let + testsuite = final.fetchFromGitHub { + owner = "WebAssembly"; + repo = "testsuite"; + rev = "e05365077e13a1d86ffe77acfb1a835b7aa78422"; + hash = "sha256-yvZ5AZTPUA6nsD3xpFC0VLthiu2CxVto66RTXBXXeJM="; + }; + in + prev.binaryen.overrideAttrs (_: rec { + version = "119"; + src = pkgs.fetchFromGitHub { + owner = "WebAssembly"; + repo = "binaryen"; + rev = "version_${version}"; + hash = "sha256-JYXtN3CW4qm/nnjGRvv3GxQ0x9O9wHtNYQLqHIYTTOA="; + }; + preConfigure = '' + if [ $doCheck -eq 1 ]; then + sed -i '/googletest/d' third_party/CMakeLists.txt + rmdir test/spec/testsuite + ln -s ${testsuite} test/spec/testsuite + else + cmakeFlagsArray=($cmakeFlagsArray -DBUILD_TESTS=0) + fi + ''; + }); + }) ]; - in - { - packages = (builtins.listToAttrs - (map - (x: { - name = "manifold-" + x.parallel-backend; - value = manifold x; - }) - parallelBackends)) // { - manifold-js = pkgs.buildEmscriptenPackage { - name = "manifold-js"; - version = "2.5.1"; - src = self; - nativeBuildInputs = (with pkgs; [ cmake python39 ]); - buildInputs = [ pkgs.nodejs ]; - configurePhase = '' - cp -r ${clipper2-src} clipper2 - chmod -R +w clipper2 - mkdir -p .emscriptencache - export EM_CACHE=$(pwd)/.emscriptencache - mkdir build - cd build - emcmake cmake -DCMAKE_BUILD_TYPE=Release \ - -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest-src} \ - -DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 .. - ''; - buildPhase = '' - emmake make -j''${NIX_BUILD_CORES} - ''; - checkPhase = '' - cd test - node manifold_test.js - cd ../ - ''; - installPhase = '' - mkdir -p $out - cp {extras,wasm}/*.js $out/ - cp {extras,wasm}/*.wasm $out/ - ''; - }; - # but how should we make it work with other python versions? - manifold3d = with pkgs.python3Packages; buildPythonPackage { - pname = "manifold3d"; - version = "2.5.1"; - src = self; - propagatedBuildInputs = [ - numpy - ]; - buildInputs = with pkgs; [ - tbb - clipper2 - ]; - nativeBuildInputs = with pkgs; [ - cmake - ninja - setuptools - scikit-build-core - pyproject-metadata - pathspec - pkg-config - ]; - checkInputs = [ - nanobind - trimesh - pytest - ]; - format = "pyproject"; - dontUseCmakeConfigure = true; - doCheck = true; - checkPhase = '' - python3 bindings/python/examples/run_all.py - python3 -m pytest - ''; - }; - }; - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ + }; + onetbb = pkgs.tbb_2021_11.overrideAttrs (_: { + version = onetbb-src.rev; + src = onetbb-src; + }); + gersemi = with pkgs.python3Packages; buildPythonPackage { + pname = "gersemi"; + version = "0.17.0"; + src = gersemi-src; + propagatedBuildInputs = [ + appdirs + lark + pyyaml + ]; + doCheck = true; + }; + manifold = + { parallel ? true }: pkgs.stdenv.mkDerivation { + pname = "manifold-${if parallel then "tbb" else "none"}"; + version = manifold-version; + src = self; + nativeBuildInputs = (with pkgs; [ cmake - tbb + ninja + (python3.withPackages + (ps: with ps; [ nanobind trimesh pytest ])) gtest + ]) ++ (if parallel then [ onetbb ] else [ ]); + buildInputs = with pkgs; [ + clipper2 + assimp + ]; + cmakeFlags = [ + "-DMANIFOLD_CBIND=ON" + "-DMANIFOLD_EXPORT=ON" + "-DBUILD_SHARED_LIBS=ON" + "-DMANIFOLD_PAR=${if parallel then "ON" else "OFF"}" ]; + checkPhase = '' + cd test + ./manifold_test + cd ../ + ''; }; - } + manifold-emscripten = { parallel, doCheck ? true }: pkgs.buildEmscriptenPackage { + name = "manifold-js"; + version = manifold-version; + src = self; + nativeBuildInputs = (with pkgs; [ cmake python39 ]); + buildInputs = [ pkgs.nodejs ]; + configurePhase = '' + cp -r ${clipper2-src} clipper2 + chmod -R +w clipper2 + mkdir -p .emscriptencache + export EM_CACHE=$(pwd)/.emscriptencache + mkdir build + cd build + emcmake cmake -DCMAKE_BUILD_TYPE=Release \ + -DMANIFOLD_PAR=${if parallel then "ON" else "OFF"} \ + -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest-src} \ + -DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 \ + ${if parallel then "-DFETCHCONTENT_SOURCE_DIR_TBB=${onetbb-src}" else ""} .. + ''; + buildPhase = '' + emmake make -j''${NIX_BUILD_CORES} + ''; + checkPhase = if doCheck then '' + cd test + node manifold_test.js + cd ../ + '' else ""; + installPhase = '' + mkdir -p $out + cp bindings/wasm/manifold.* $out/ + ''; + }; + in + { + packages = { + manifold-tbb = manifold { }; + manifold-none = manifold { parallel = false; }; + manifold-js = manifold-emscripten { parallel = false; }; + # disable check for now + manifold-js-tbb = manifold-emscripten { + parallel = true; + doCheck = false; + }; + # but how should we make it work with other python versions? + manifold3d = with pkgs.python3Packages; buildPythonPackage { + pname = "manifold3d"; + version = manifold-version; + src = self; + propagatedBuildInputs = [ numpy ]; + buildInputs = [ onetbb pkgs.clipper2 ]; + nativeBuildInputs = with pkgs; [ + cmake + ninja + setuptools + scikit-build-core + pyproject-metadata + pathspec + ]; + checkInputs = [ nanobind trimesh pytest ]; + format = "pyproject"; + dontUseCmakeConfigure = true; + doCheck = true; + checkPhase = '' + python3 bindings/python/examples/run_all.py + python3 -m pytest + ''; + }; + }; + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + (python3.withPackages (ps: with ps; [ + # test dependencies + trimesh + numpy + pytest + + # formatting tools + gersemi + black + ])) + + ninja + cmake + onetbb + gtest + assimp + clipper2 + + # useful tools + clang-tools_18 + clang_18 + tracy + ]; + }; + } ); } diff --git a/scripts/format.sh b/scripts/format.sh index 723d3f2f5..2d8538727 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -19,16 +19,11 @@ $CLANG_FORMAT -i include/manifold/*.h black bindings/python/examples/*.py -for f in $(find -name CMakeLists.txt); do - # skip build directories - if [[ $f != *build* ]]; then - gersemi -i $f - fi -done - -for f in $(find -name '*.cmake.in'); do - # skip build directories - if [[ $f != *build* ]]; then - gersemi -i $f - fi +for pattern in 'CMakeLists.txt' '*.cmake*'; do + for f in $(find -name ${pattern}); do + # skip build directories + if [[ $f != *build* && $f != *node_modules* ]]; then + gersemi -i $f + fi + done done diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 19fc639f1..4fe0c7483 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,6 @@ set( smoothing.cpp sort.cpp subdivision.cpp - # optional source files $<$:cross_section/cross_section.cpp> $<$:meshIO/meshIO.cpp> @@ -59,20 +58,16 @@ set( $<$:${TBB_INCLUDE_DIRS}> ) -add_library( - manifold - ${MANIFOLD_SRCS} - ${MANIFOLD_PRIVATE_HDRS} -) +add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) target_link_libraries( manifold PUBLIC - # optional dependencies - $<$:$,Clipper2::Clipper2,Clipper2>> - $<$:$,TBB::tbb,${TBB_LINK_LIBRARIES}>> - $<$:assimp::assimp> - $<$:TracyClient> + # optional dependencies + $<$:$,Clipper2::Clipper2,Clipper2>> + $<$:$,TBB::tbb,${TBB_LINK_LIBRARIES}>> + $<$:assimp::assimp> + $<$:TracyClient> ) target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) @@ -108,10 +103,7 @@ add_library(manifold::manifold ALIAS manifold) set_property(TARGET manifold PROPERTY VERSION "${MANIFOLD_VERSION}") set_property(TARGET manifold PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) if(MSVC) - set_target_properties( - manifold - PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON - ) + set_target_properties(manifold PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() install(TARGETS manifold EXPORT manifoldTargets) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0544986ff..e40c468e2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,6 @@ endif() enable_testing() - # put fast/simple tests files first to run earlier set( SOURCE_FILES From b15c7b3d8c40283dd515d90f1ec4114db6776c57 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 22:53:54 +0800 Subject: [PATCH 12/46] update --- CMakeLists.txt | 15 ++++++++++++++- src/CMakeLists.txt | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d632f772c..4df896a50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,13 +106,26 @@ endif() if(EMSCRIPTEN) message("Building for Emscripten") add_link_options("-s ALLOW_MEMORY_GROWTH=1") + add_link_options("-s MAXIMUM_MEMORY=4294967296") + if(MANIFOLD_PAR) + set(CMAKE_THREAD_LIBS_INIT "-pthread") + add_compile_options("-pthread") + # PTHREAD_POOL_SIZE is set to 4 for OK-ish performance, in general we are + # not getting too much speedup for very large number of cores, and a lot of + # CPUs now have 4 cores... + add_link_options("-s PTHREAD_POOL_SIZE=4") + # mimalloc is needed for good performance + add_link_options("-s MALLOC=mimalloc") + # The default stack size apparently causes problem when parallelization is + # enabled. + add_link_options("-s STACK_SIZE=10MB") + endif() if(MANIFOLD_DEBUG) list(APPEND MANIFOLD_FLAGS -fexceptions) add_link_options("-fexceptions") add_link_options("-s DISABLE_EXCEPTION_CATCHING=0") endif() set(MANIFOLD_PYBIND OFF) - set(MANIFOLD_CBIND OFF) set(BUILD_SHARED_LIBS OFF) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4fe0c7483..18fb65969 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -71,7 +71,8 @@ target_link_libraries( ) target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) - +# make sure users use appropriate c++ standard when including our headers +target_compile_features(manifold PUBLIC cxx_std_17) set( OPTIONS MANIFOLD_DEBUG From 8788bff2929af3a0065b628b663bac4f48bda8cc Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 22:59:56 +0800 Subject: [PATCH 13/46] update --- bindings/wasm/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/wasm/CMakeLists.txt b/bindings/wasm/CMakeLists.txt index 8f8a9ba3a..2dfd4befa 100644 --- a/bindings/wasm/CMakeLists.txt +++ b/bindings/wasm/CMakeLists.txt @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -project(wasm) - add_executable(manifoldjs bindings.cpp) set_source_files_properties( From b880c7bcc430d0c876a3206a9c1d20829f10203d Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:08:45 +0800 Subject: [PATCH 14/46] update --- CMakeLists.txt | 20 ++++++++++---------- bindings/python/CMakeLists.txt | 1 - bindings/wasm/CMakeLists.txt | 1 - 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4df896a50..2b59515ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ if(MANIFOLD_FUZZ) # enable fuzztest fuzzing mode set(FUZZTEST_FUZZING_MODE ON) # address sanitizer required - add_compile_options("-fsanitize=address") + add_compile_options(-fsanitize=address) endif() if(TRACY_ENABLE) @@ -105,25 +105,25 @@ endif() if(EMSCRIPTEN) message("Building for Emscripten") - add_link_options("-s ALLOW_MEMORY_GROWTH=1") - add_link_options("-s MAXIMUM_MEMORY=4294967296") + add_link_options(-sALLOW_MEMORY_GROWTH=1) + add_link_options(-sMAXIMUM_MEMORY=4294967296) if(MANIFOLD_PAR) set(CMAKE_THREAD_LIBS_INIT "-pthread") - add_compile_options("-pthread") + add_compile_options(-pthread) # PTHREAD_POOL_SIZE is set to 4 for OK-ish performance, in general we are # not getting too much speedup for very large number of cores, and a lot of # CPUs now have 4 cores... - add_link_options("-s PTHREAD_POOL_SIZE=4") + add_link_options(-sPTHREAD_POOL_SIZE=4) # mimalloc is needed for good performance - add_link_options("-s MALLOC=mimalloc") + add_link_options(-sMALLOC=mimalloc) # The default stack size apparently causes problem when parallelization is # enabled. - add_link_options("-s STACK_SIZE=10MB") + add_link_options(-sSTACK_SIZE=10MB) endif() if(MANIFOLD_DEBUG) list(APPEND MANIFOLD_FLAGS -fexceptions) - add_link_options("-fexceptions") - add_link_options("-s DISABLE_EXCEPTION_CATCHING=0") + add_link_options(-fexceptions) + add_link_options(-sDISABLE_EXCEPTION_CATCHING=0) endif() set(MANIFOLD_PYBIND OFF) set(BUILD_SHARED_LIBS OFF) @@ -176,7 +176,7 @@ else() -fkeep-inline-functions -fkeep-static-functions ) - add_link_options("-coverage") + add_link_options(-coverage) endif() endif() diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 4bfe513e7..0fbef8042 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -82,7 +82,6 @@ target_compile_options( manifold3d PRIVATE ${MANIFOLD_FLAGS} -DMODULE_NAME=manifold3d ) -target_compile_features(manifold3d PUBLIC cxx_std_17) set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d") message(Python_EXECUTABLE = ${Python_EXECUTABLE}) diff --git a/bindings/wasm/CMakeLists.txt b/bindings/wasm/CMakeLists.txt index 2dfd4befa..1138fd259 100644 --- a/bindings/wasm/CMakeLists.txt +++ b/bindings/wasm/CMakeLists.txt @@ -32,7 +32,6 @@ target_link_options( -sEXPORT_ES6=1 ) -target_compile_features(manifoldjs PUBLIC cxx_std_17) set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold") file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/built) From deab097c21022cb5ca70a40c9fe8761c5372a1ed Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:16:41 +0800 Subject: [PATCH 15/46] move python dependency handling --- bindings/python/CMakeLists.txt | 46 ------------------------------ cmake/manifoldDeps.cmake | 52 ++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 0fbef8042..fb5c8e83c 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -16,52 +16,6 @@ if(NOT MANIFOLD_PYBIND) return() endif() -if(Python_VERSION VERSION_LESS 3.12) - find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) -else() - find_package(Python COMPONENTS Interpreter Development.SABIModule REQUIRED) -endif() -if(Python_VERSION VERSION_GREATER_EQUAL 3.11) - set(MANIFOLD_PYBIND_STUBGEN ON) -else() - # stubgen does not support version less than 3.11 - set(MANIFOLD_PYBIND_STUBGEN OFF) - message("Python version too old, stub will not be generated") -endif() - -execute_process( - COMMAND "${Python_EXECUTABLE}" -m nanobind --version - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE NB_VERSION -) -# we are fine with 2.0.0 -if(NB_VERSION VERSION_GREATER_EQUAL 2.0.0) - message("Found nanobind, version ${NB_VERSION}") - execute_process( - COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE nanobind_ROOT - ) - find_package(nanobind CONFIG REQUIRED) -else() - include(FetchContent) - logmissingdep("nanobind" , "MANIFOLD_PYBIND") - FetchContent_Declare( - nanobind - GIT_REPOSITORY https://github.com/wjakob/nanobind.git - GIT_TAG - 784efa2a0358a4dc5432c74f5685ee026e20f2b6 # v2.2.0 - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(nanobind) - set(NB_VERSION 2.2.0) -endif() - -if(NB_VERSION VERSION_LESS 2.1.0) - message("Nanobind version too old, stub will not be generated") - set(MANIFOLD_PYBIND_STUBGEN OFF) -endif() - nanobind_add_module(manifold3d NB_STATIC STABLE_ABI LTO autogen_docstrings.inl manifold3d.cpp ) diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index 1bbe32a0d..0fe091ce9 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -87,8 +87,8 @@ if(MANIFOLD_CROSS_SECTION) set(CLIPPER2_TESTS OFF) set( CLIPPER2_USINGZ - "OFF" - CACHE STRING + OFF + CACHE BOOL "Preempt cache default of USINGZ (we only use 2d)" ) FetchContent_Declare( @@ -142,3 +142,51 @@ if(MANIFOLD_TEST) FetchContent_MakeAvailable(googletest) endif() endif() + +if(MANIFOLD_PYBIND) + if(Python_VERSION VERSION_LESS 3.12) + find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) + else() + find_package(Python COMPONENTS Interpreter Development.SABIModule REQUIRED) + endif() + if(Python_VERSION VERSION_GREATER_EQUAL 3.11) + set(MANIFOLD_PYBIND_STUBGEN ON) + else() + # stubgen does not support version less than 3.11 + set(MANIFOLD_PYBIND_STUBGEN OFF) + message("Python version too old, stub will not be generated") + endif() + + execute_process( + COMMAND "${Python_EXECUTABLE}" -m nanobind --version + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE NB_VERSION + ) + # we are fine with 2.0.0 + if(NB_VERSION VERSION_GREATER_EQUAL 2.0.0) + message("Found nanobind, version ${NB_VERSION}") + execute_process( + COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE nanobind_ROOT + ) + find_package(nanobind CONFIG REQUIRED) + else() + include(FetchContent) + logmissingdep("nanobind" , "MANIFOLD_PYBIND") + FetchContent_Declare( + nanobind + GIT_REPOSITORY https://github.com/wjakob/nanobind.git + GIT_TAG + 784efa2a0358a4dc5432c74f5685ee026e20f2b6 # v2.2.0 + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(nanobind) + set(NB_VERSION 2.2.0) + endif() + + if(NB_VERSION VERSION_LESS 2.1.0) + message("Nanobind version too old, stub will not be generated") + set(MANIFOLD_PYBIND_STUBGEN OFF) + endif() +endif() From 9d6892b44d2338e29be63c2b422f23ca886356c0 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:30:19 +0800 Subject: [PATCH 16/46] more changes --- bindings/python/CMakeLists.txt | 4 -- cmake/manifoldDeps.cmake | 70 ++++++++++++++++++++++++---------- src/CMakeLists.txt | 5 +-- test/CMakeLists.txt | 57 +++++++++------------------ 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index fb5c8e83c..a285a6bac 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -12,10 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -if(NOT MANIFOLD_PYBIND) - return() -endif() - nanobind_add_module(manifold3d NB_STATIC STABLE_ABI LTO autogen_docstrings.inl manifold3d.cpp ) diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index 0fe091ce9..1cbc57a8f 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -59,6 +59,18 @@ if(MANIFOLD_PAR) install(TARGETS tbb) endif() endif() + if(NOT TARGET TBB::tbb) + if(NOT TARGET tbb) + add_library(TBB::tbb SHARED IMPORTED) + set_property( + TARGET TBB::tbb + PROPERTY IMPORTED_LOCATION ${TBB_LINK_LIBRARIES} + ) + target_include_directories(TBB::tbb INTERFACE ${TBB_INCLUDE_DIRS}) + else() + add_library(TBB::tbb ALIAS tbb) + endif() + endif() endif() # If we're building cross_section, we need Clipper2 @@ -103,6 +115,9 @@ if(MANIFOLD_CROSS_SECTION) install(TARGETS Clipper2) endif() endif() + if(NOT TARGET Clipper2::Clipper2) + add_library(Clipper2::Clipper2 ALIAS Clipper2) + endif() endif() if(TRACY_ENABLE) @@ -122,27 +137,6 @@ if(MANIFOLD_EXPORT) find_package(assimp REQUIRED) endif() -if(MANIFOLD_TEST) - find_package(GTest QUIET) - if(NOT GTest_FOUND) - logmissingdep("GTest" , "MANIFOLD_TEST") - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - # Prevent installation of GTest with your project - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - FIND_PACKAGE_ARGS NAMES GTest gtest - ) - FetchContent_MakeAvailable(googletest) - endif() -endif() - if(MANIFOLD_PYBIND) if(Python_VERSION VERSION_LESS 3.12) find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) @@ -190,3 +184,37 @@ if(MANIFOLD_PYBIND) set(MANIFOLD_PYBIND_STUBGEN OFF) endif() endif() + +if(MANIFOLD_TEST) + find_package(GTest QUIET) + if(NOT GTest_FOUND) + logmissingdep("GTest" , "MANIFOLD_TEST") + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + # Prevent installation of GTest with your project + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + set(INSTALL_GMOCK OFF CACHE BOOL "" FORCE) + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + FIND_PACKAGE_ARGS NAMES GTest gtest + ) + FetchContent_MakeAvailable(googletest) + endif() + if(NOT TARGET GTest::gtest_main) + add_library(GTest::gtest_main ALIAS gtest_main) + endif() +endif() + +if(MANIFOLD_FUZZ) + FetchContent_Declare( + fuzztest + GIT_REPOSITORY https://github.com/google/fuzztest.git + GIT_TAG 2606e04a43e5a7730e437a849604a61f1cb0ff28 + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(fuzztest) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18fb65969..9e2db00ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,6 @@ set( set( MANIFOLD_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include - $<$:${TBB_INCLUDE_DIRS}> ) add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) @@ -64,8 +63,8 @@ target_link_libraries( manifold PUBLIC # optional dependencies - $<$:$,Clipper2::Clipper2,Clipper2>> - $<$:$,TBB::tbb,${TBB_LINK_LIBRARIES}>> + $<$:Clipper2::Clipper2> + $<$:TBB::tbb> $<$:assimp::assimp> $<$:TracyClient> ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e40c468e2..9627c16d1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,62 +31,39 @@ set( hull_test.cpp samples_test.cpp boolean_complex_test.cpp + $<$:cross_section_test.cpp> + $<$:manifoldc_test.cpp> ) -if(MANIFOLD_CROSS_SECTION) - list(APPEND SOURCE_FILES cross_section_test.cpp) -endif() - -if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) - list(APPEND SOURCE_FILES manifoldc_test.cpp) -endif() - -if(NOT TARGET GTest::gtest_main) - add_library(GTest::gtest_main ALIAS gtest_main) -endif() - add_executable(manifold_test ${SOURCE_FILES}) target_link_libraries(manifold_test GTest::gtest_main manifold samples) -if(MANIFOLD_FUZZ) - FetchContent_Declare( - fuzztest - GIT_REPOSITORY https://github.com/google/fuzztest.git - # note that if commit hash is used, it cannot be a shallow clone - GIT_TAG 2606e04a43e5a7730e437a849604a61f1cb0ff28 - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(fuzztest) - fuzztest_setup_fuzzing_flags() - add_executable(polygon_fuzz polygon_fuzz.cpp) - target_link_libraries(polygon_fuzz PUBLIC manifold) - link_fuzztest(polygon_fuzz) - gtest_discover_tests(polygon_fuzz) -endif() - if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) target_link_libraries(manifold_test manifoldc) endif() -target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) - -add_test(test_all manifold_test) - if(EMSCRIPTEN) - list( - APPEND - EMSCRIPTEN_LINK_FLAGS + target_link_options( + manifold_test + PRIVATE -sASSERTIONS=1 -sDEMANGLE_SUPPORT=1 --bind --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons ) - list(JOIN EMSCRIPTEN_LINK_FLAGS " " EMSCRIPTEN_LINK_FLAGS) - set_target_properties( - manifold_test - PROPERTIES LINK_FLAGS ${EMSCRIPTEN_LINK_FLAGS} - ) +endif() + +target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) + +add_test(test_all manifold_test) + +if(MANIFOLD_FUZZ) + fuzztest_setup_fuzzing_flags() + add_executable(polygon_fuzz polygon_fuzz.cpp) + target_link_libraries(polygon_fuzz PUBLIC manifold) + link_fuzztest(polygon_fuzz) + gtest_discover_tests(polygon_fuzz) endif() if(MSVC) From 4eca99582ef46bdc613cb0bbc7df97f7dbe86a6c Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:32:17 +0800 Subject: [PATCH 17/46] format --- src/CMakeLists.txt | 5 +---- test/CMakeLists.txt | 15 +++++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e2db00ce..0d4ccff2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,10 +52,7 @@ set( ) # Include directories -set( - MANIFOLD_INCLUDE_DIRS - ${PROJECT_SOURCE_DIR}/include -) +set(MANIFOLD_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include) add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9627c16d1..67ecd9472 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,7 +32,10 @@ set( samples_test.cpp boolean_complex_test.cpp $<$:cross_section_test.cpp> - $<$:manifoldc_test.cpp> + $<$:manifoldc_test.cpp> ) add_executable(manifold_test ${SOURCE_FILES}) @@ -46,11 +49,11 @@ if(EMSCRIPTEN) target_link_options( manifold_test PRIVATE - -sASSERTIONS=1 - -sDEMANGLE_SUPPORT=1 - --bind - --preload-file - ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons + -sASSERTIONS=1 + -sDEMANGLE_SUPPORT=1 + --bind + --preload-file + ${CMAKE_CURRENT_SOURCE_DIR}/polygons@/polygons ) endif() From ddfc19f8d11fdb774abdb8c6eeac380207202b56 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:37:10 +0800 Subject: [PATCH 18/46] fix broken format --- test/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 67ecd9472..d08aac46d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,10 +32,7 @@ set( samples_test.cpp boolean_complex_test.cpp $<$:cross_section_test.cpp> - $<$:manifoldc_test.cpp> + "$<$:manifoldc_test.cpp>" ) add_executable(manifold_test ${SOURCE_FILES}) From f5dafa9406a54477a3d08a62e31d4f4d38c52d9d Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:38:49 +0800 Subject: [PATCH 19/46] fix --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d08aac46d..97b5c7599 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,7 +32,7 @@ set( samples_test.cpp boolean_complex_test.cpp $<$:cross_section_test.cpp> - "$<$:manifoldc_test.cpp>" + $<$,$>>:manifoldc_test.cpp> ) add_executable(manifold_test ${SOURCE_FILES}) From e55356630d8ae41bb937c04f759315b1ef4473b6 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:41:22 +0800 Subject: [PATCH 20/46] simplify --- test/CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 97b5c7599..587db5cc7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,15 +32,17 @@ set( samples_test.cpp boolean_complex_test.cpp $<$:cross_section_test.cpp> - $<$,$>>:manifoldc_test.cpp> + $<$:manifoldc_test.cpp> ) add_executable(manifold_test ${SOURCE_FILES}) -target_link_libraries(manifold_test GTest::gtest_main manifold samples) - -if(MANIFOLD_CBIND AND NOT EMSCRIPTEN) - target_link_libraries(manifold_test manifoldc) -endif() +target_link_libraries( + manifold_test + GTest::gtest_main + manifold + samples + $<$:manifoldc> +) if(EMSCRIPTEN) target_link_options( From fa62dc27929bc849428750efcbfd30c34006f958 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 16 Nov 2024 23:55:34 +0800 Subject: [PATCH 21/46] allow emscripten with cbind --- bindings/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index dcf8429c4..bf7614498 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -16,7 +16,7 @@ if(NOT MANIFOLD_CROSS_SECTION) return() endif() -if(NOT EMSCRIPTEN AND MANIFOLD_CBIND) +if(MANIFOLD_CBIND) add_subdirectory(c) endif() From abc019e2119a7c2143dc66fdad7859af246d6b6b Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 02:27:32 +0800 Subject: [PATCH 22/46] build fetched dependencies as static libs --- cmake/manifoldDeps.cmake | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index 1cbc57a8f..e3d167499 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -33,6 +33,10 @@ function(logmissingdep PKG) endif() endfunction() +set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +# we build fetched dependencies as static library +set(BUILD_SHARED_LIBS OFF) + # If we're building parallel, we need the requisite libraries if(MANIFOLD_PAR) find_package(Threads REQUIRED) @@ -53,11 +57,6 @@ if(MANIFOLD_PAR) EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(TBB) - # note: we do want to install tbb to the user machine when built from - # source - if(NOT EMSCRIPTEN) - install(TARGETS tbb) - endif() endif() if(NOT TARGET TBB::tbb) if(NOT TARGET tbb) @@ -109,11 +108,9 @@ if(MANIFOLD_CROSS_SECTION) GIT_TAG ff378668baae3570e9d8070aa9eb339bdd5a6aba GIT_PROGRESS TRUE SOURCE_SUBDIR CPP + EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(Clipper2) - if(NOT EMSCRIPTEN) - install(TARGETS Clipper2) - endif() endif() if(NOT TARGET Clipper2::Clipper2) add_library(Clipper2::Clipper2 ALIAS Clipper2) @@ -128,6 +125,7 @@ if(TRACY_ENABLE) GIT_TAG v0.10 GIT_SHALLOW TRUE GIT_PROGRESS TRUE + EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(tracy) endif() @@ -174,6 +172,7 @@ if(MANIFOLD_PYBIND) GIT_TAG 784efa2a0358a4dc5432c74f5685ee026e20f2b6 # v2.2.0 GIT_PROGRESS TRUE + EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(nanobind) set(NB_VERSION 2.2.0) @@ -201,6 +200,7 @@ if(MANIFOLD_TEST) GIT_SHALLOW TRUE GIT_PROGRESS TRUE FIND_PACKAGE_ARGS NAMES GTest gtest + EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(googletest) endif() @@ -218,3 +218,5 @@ if(MANIFOLD_FUZZ) ) FetchContent_MakeAvailable(fuzztest) endif() + +set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS}) From 58e8be836295c13a28ef8192ef16749e0b632abc Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 03:39:33 +0800 Subject: [PATCH 23/46] fix static build --- cmake/manifoldConfig.cmake.in | 6 ++++-- cmake/manifoldDeps.cmake | 4 ++++ src/CMakeLists.txt | 18 ++++++++++++++++-- test/CMakeLists.txt | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cmake/manifoldConfig.cmake.in b/cmake/manifoldConfig.cmake.in index 93cfb0280..3bad36668 100644 --- a/cmake/manifoldConfig.cmake.in +++ b/cmake/manifoldConfig.cmake.in @@ -12,12 +12,14 @@ if(_FIND_ROOT STREQUAL "/") endif() set(MANIFOLD_CROSS_SECTION "@MANIFOLD_CROSS_SECTION@") -if(MANIFOLD_CROSS_SECTION) +set(MANIFOLD_BUILTIN_CLIPPER2 "@MANIFOLD_BUILTIN_CLIPPER2@") +if(MANIFOLD_CROSS_SECTION AND NOT MANIFOLD_BUILTIN_CLIPPER2) set(Clipper2_ROOT "${_FIND_ROOT}") find_package(Clipper2 REQUIRED) endif() set(MANIFOLD_PAR "@MANIFOLD_PAR@") -if(MANIFOLD_PAR STREQUAL "ON") +set(MANIFOLD_BUILTIN_TBB "@MANIFOLD_BUILTIN_TBB@") +if(MANIFOLD_PAR STREQUAL "ON" AND NOT MANIFOLD_BUILTIN_TBB) find_package(TBB REQUIRED) endif() set(MANIFOLD_EXPORT "@MANIFOLD_EXPORT@") diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index e3d167499..84cc3e16e 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -38,6 +38,7 @@ set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS OFF) # If we're building parallel, we need the requisite libraries +set(MANIFOLD_BUILTIN_TBB OFF) if(MANIFOLD_PAR) find_package(Threads REQUIRED) find_package(TBB QUIET) @@ -57,6 +58,7 @@ if(MANIFOLD_PAR) EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(TBB) + set(MANIFOLD_BUILTIN_TBB ON) endif() if(NOT TARGET TBB::tbb) if(NOT TARGET tbb) @@ -73,6 +75,7 @@ if(MANIFOLD_PAR) endif() # If we're building cross_section, we need Clipper2 +set(MANIFOLD_BUILTIN_CLIPPER2 OFF) if(MANIFOLD_CROSS_SECTION) find_package(Clipper2 QUIET) if(NOT Clipper2_FOUND AND PKG_CONFIG_FOUND) @@ -93,6 +96,7 @@ if(MANIFOLD_CROSS_SECTION) target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) else() logmissingdep("Clipper2" , "cross_section") + set(MANIFOLD_BUILTIN_CLIPPER2 ON) set(CLIPPER2_UTILS OFF) set(CLIPPER2_EXAMPLES OFF) set(CLIPPER2_TESTS OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d4ccff2b..e18d6b5ae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,12 +60,26 @@ target_link_libraries( manifold PUBLIC # optional dependencies - $<$:Clipper2::Clipper2> - $<$:TBB::tbb> $<$:assimp::assimp> $<$:TracyClient> ) +if(MANIFOLD_CROSS_SECTION) + if(MANIFOLD_BUILTIN_CLIPPER2) + target_link_libraries(manifold PRIVATE Clipper2::Clipper2) + else() + target_link_libraries(manifold PUBLIC Clipper2::Clipper2) + endif() +endif() + +if(MANIFOLD_PAR) + if(MANIFOLD_BUILTIN_TBB) + target_link_libraries(manifold PRIVATE TBB::tbb) + else() + target_link_libraries(manifold PUBLIC TBB::tbb) + endif() +endif() + target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) # make sure users use appropriate c++ standard when including our headers target_compile_features(manifold PUBLIC cxx_std_17) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 587db5cc7..b638cbf79 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,6 +43,13 @@ target_link_libraries( samples $<$:manifoldc> ) +if(MANIFOLD_PAR) + if(MANIFOLD_BUILTIN_TBB) + target_link_libraries(manifold_test PRIVATE TBB::tbb) + else() + target_link_libraries(manifold_test PUBLIC TBB::tbb) + endif() +endif() if(EMSCRIPTEN) target_link_options( From 0ca6a6ac4306736d55cdc8003d2d096acf17aed4 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 03:40:19 +0800 Subject: [PATCH 24/46] fix rebuild --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b638cbf79..b57c3ed8e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -38,6 +38,7 @@ set( add_executable(manifold_test ${SOURCE_FILES}) target_link_libraries( manifold_test + PRIVATE GTest::gtest_main manifold samples From 5b6a9dfd5db42b0a2eb037e540121f514bb3f841 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 03:41:41 +0800 Subject: [PATCH 25/46] fix extras --- extras/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index ee87fc70b..e2564eea7 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -22,8 +22,13 @@ target_compile_options(perfTest PRIVATE ${MANIFOLD_FLAGS}) if(MANIFOLD_PAR AND NOT MSVC) add_executable(stlTest stl_test.cpp) - target_link_libraries(stlTest manifold) + target_link_libraries(stlTest PRIVATE manifold) target_compile_options(stlTest PRIVATE ${MANIFOLD_FLAGS}) + if(MANIFOLD_BUILTIN_TBB) + target_link_libraries(stlTest PRIVATE TBB::tbb) + else() + target_link_libraries(stlTest PUBLIC TBB::tbb) + endif() endif() add_executable(largeSceneTest large_scene_test.cpp) From d8e8c4f450f099434fe62b46e788e5b56f79d8a1 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 07:48:35 +0800 Subject: [PATCH 26/46] remove parallel.h from public API --- CMakeLists.txt | 1 - src/CMakeLists.txt | 1 + {include/manifold => src}/parallel.h | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {include/manifold => src}/parallel.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b59515ee..b2590c1da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -247,7 +247,6 @@ set( linalg.h manifold.h optional_assert.h - parallel.h polygon.h vec_view.h $<$:cross_section.h> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e18d6b5ae..c292ec147 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,6 +42,7 @@ set( hashtable.h impl.h mesh_fixes.h + parallel.h quickhull.h shared.h sparse.h diff --git a/include/manifold/parallel.h b/src/parallel.h similarity index 100% rename from include/manifold/parallel.h rename to src/parallel.h From f6616a0de3cba5ab73638db850123d613454c616 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 07:49:19 +0800 Subject: [PATCH 27/46] update tests --- scripts/test-cmake.sh | 1 - scripts/test-pkgconfig.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/scripts/test-cmake.sh b/scripts/test-cmake.sh index 905ae1a3c..9468b4cb2 100755 --- a/scripts/test-cmake.sh +++ b/scripts/test-cmake.sh @@ -12,7 +12,6 @@ EOT cat < test.cpp #include -#include int main() { manifold::Manifold foo; return 0; } EOT diff --git a/scripts/test-pkgconfig.sh b/scripts/test-pkgconfig.sh index e447e0dac..631ab640e 100755 --- a/scripts/test-pkgconfig.sh +++ b/scripts/test-pkgconfig.sh @@ -11,7 +11,6 @@ EOT cat < testing.cpp #include -#include int main() { manifold::Manifold foo; return 0; } EOT From fdfdf73e45cd8f106bab3758fa6fbdb741279ebf Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 07:49:24 +0800 Subject: [PATCH 28/46] make dependencies private --- src/CMakeLists.txt | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c292ec147..341011d39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,26 +60,17 @@ add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) target_link_libraries( manifold PUBLIC - # optional dependencies - $<$:assimp::assimp> $<$:TracyClient> ) -if(MANIFOLD_CROSS_SECTION) - if(MANIFOLD_BUILTIN_CLIPPER2) - target_link_libraries(manifold PRIVATE Clipper2::Clipper2) - else() - target_link_libraries(manifold PUBLIC Clipper2::Clipper2) - endif() -endif() - -if(MANIFOLD_PAR) - if(MANIFOLD_BUILTIN_TBB) - target_link_libraries(manifold PRIVATE TBB::tbb) - else() - target_link_libraries(manifold PUBLIC TBB::tbb) - endif() -endif() +target_link_libraries( + manifold + PRIVATE + # optional dependencies + $<$:TBB::tbb> + $<$:Clipper2::Clipper2> + $<$:assimp::assimp> +) target_compile_options(manifold PRIVATE ${MANIFOLD_FLAGS}) # make sure users use appropriate c++ standard when including our headers From c19956038712d5c1a5494a3dc285806f16879acb Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 07:54:36 +0800 Subject: [PATCH 29/46] move parallel.h --- Doxyfile | 2 +- extras/stl_test.cpp | 2 +- src/CMakeLists.txt | 6 +----- src/boolean3.cpp | 2 +- src/boolean_result.cpp | 2 +- src/collider.h | 2 +- src/constructors.cpp | 2 +- src/csg_tree.cpp | 2 +- src/edge_op.cpp | 2 +- src/face_op.cpp | 2 +- src/impl.cpp | 2 +- src/manifold.cpp | 2 +- src/polygon.cpp | 2 +- src/properties.cpp | 2 +- src/sdf.cpp | 2 +- src/shared.h | 2 +- src/smoothing.cpp | 2 +- src/sort.cpp | 2 +- src/sparse.h | 2 +- src/subdivision.cpp | 2 +- src/vec.h | 2 +- test/CMakeLists.txt | 8 ++++---- 22 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Doxyfile b/Doxyfile index 0e25175d6..2988011d1 100644 --- a/Doxyfile +++ b/Doxyfile @@ -971,10 +971,10 @@ INPUT = include/manifold/manifold.h \ include/manifold/common.h \ include/manifold/meshIO.h \ include/manifold/linalg.h \ - include/manifold/parallel.h \ include/manifold/vec_view.h \ include/manifold/iters.h \ include/manifold/optional_assert.h \ + src/parallel.h \ src/manifold.cpp \ src/constructors.cpp \ src/polygon.cpp \ diff --git a/extras/stl_test.cpp b/extras/stl_test.cpp index 4d2c7f502..3f5873d23 100644 --- a/extras/stl_test.cpp +++ b/extras/stl_test.cpp @@ -10,7 +10,7 @@ #include #include -#include "manifold/parallel.h" +#include "../src/parallel.h" static constexpr size_t g_Iterations = 5; static constexpr size_t g_IterationsDiscard = 1; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 341011d39..629c924d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,11 +57,7 @@ set(MANIFOLD_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include) add_library(manifold ${MANIFOLD_SRCS} ${MANIFOLD_PRIVATE_HDRS}) -target_link_libraries( - manifold - PUBLIC - $<$:TracyClient> -) +target_link_libraries(manifold PUBLIC $<$:TracyClient>) target_link_libraries( manifold diff --git a/src/boolean3.cpp b/src/boolean3.cpp index ab383f6ce..1fca99db4 100644 --- a/src/boolean3.cpp +++ b/src/boolean3.cpp @@ -16,7 +16,7 @@ #include -#include "manifold/parallel.h" +#include "./parallel.h" using namespace manifold; diff --git a/src/boolean_result.cpp b/src/boolean_result.cpp index f53b7460d..44faf73e9 100644 --- a/src/boolean_result.cpp +++ b/src/boolean_result.cpp @@ -17,8 +17,8 @@ #include #include "./boolean3.h" +#include "./parallel.h" #include "./utils.h" -#include "manifold/parallel.h" #if (MANIFOLD_PAR == 1) && __has_include() #define TBB_PREVIEW_CONCURRENT_ORDERED_CONTAINERS 1 diff --git a/src/collider.h b/src/collider.h index 6c303fb5c..80de94b7c 100644 --- a/src/collider.h +++ b/src/collider.h @@ -13,11 +13,11 @@ // limitations under the License. #pragma once +#include "./parallel.h" #include "./sparse.h" #include "./utils.h" #include "./vec.h" #include "manifold/common.h" -#include "manifold/parallel.h" #ifdef _MSC_VER #include diff --git a/src/constructors.cpp b/src/constructors.cpp index 92e0af974..17df744ee 100644 --- a/src/constructors.cpp +++ b/src/constructors.cpp @@ -14,7 +14,7 @@ #include "./csg_tree.h" #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" #include "manifold/polygon.h" namespace manifold { diff --git a/src/csg_tree.cpp b/src/csg_tree.cpp index f04a9e95b..8f98fe298 100644 --- a/src/csg_tree.cpp +++ b/src/csg_tree.cpp @@ -25,7 +25,7 @@ #include "./csg_tree.h" #include "./impl.h" #include "./mesh_fixes.h" -#include "manifold/parallel.h" +#include "./parallel.h" constexpr int kParallelThreshold = 4096; diff --git a/src/edge_op.cpp b/src/edge_op.cpp index 20f2fd0f5..d22577a2a 100644 --- a/src/edge_op.cpp +++ b/src/edge_op.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" namespace { using namespace manifold; diff --git a/src/face_op.cpp b/src/face_op.cpp index 15cab42a8..b1a6b16c7 100644 --- a/src/face_op.cpp +++ b/src/face_op.cpp @@ -20,7 +20,7 @@ #include #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" #include "manifold/polygon.h" namespace manifold { diff --git a/src/impl.cpp b/src/impl.cpp index 1718bcb1e..9582b2c12 100644 --- a/src/impl.cpp +++ b/src/impl.cpp @@ -20,8 +20,8 @@ #include "./hashtable.h" #include "./mesh_fixes.h" +#include "./parallel.h" #include "./svd.h" -#include "manifold/parallel.h" namespace { using namespace manifold; diff --git a/src/manifold.cpp b/src/manifold.cpp index 92ac4d957..a36dd460b 100644 --- a/src/manifold.cpp +++ b/src/manifold.cpp @@ -19,7 +19,7 @@ #include "./boolean3.h" #include "./csg_tree.h" #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" namespace { using namespace manifold; diff --git a/src/polygon.cpp b/src/polygon.cpp index 639d3ed3c..60f510a98 100644 --- a/src/polygon.cpp +++ b/src/polygon.cpp @@ -19,9 +19,9 @@ #include #include "./collider.h" +#include "./parallel.h" #include "./utils.h" #include "manifold/optional_assert.h" -#include "manifold/parallel.h" namespace { using namespace manifold; diff --git a/src/properties.cpp b/src/properties.cpp index 056baa60a..c53c020a2 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -15,8 +15,8 @@ #include #include "./impl.h" +#include "./parallel.h" #include "./tri_dist.h" -#include "manifold/parallel.h" namespace { using namespace manifold; diff --git a/src/sdf.cpp b/src/sdf.cpp index 51d880580..64dd7094d 100644 --- a/src/sdf.cpp +++ b/src/sdf.cpp @@ -14,10 +14,10 @@ #include "./hashtable.h" #include "./impl.h" +#include "./parallel.h" #include "./utils.h" #include "./vec.h" #include "manifold/manifold.h" -#include "manifold/parallel.h" namespace { using namespace manifold; diff --git a/src/shared.h b/src/shared.h index b1e807370..3f3336141 100644 --- a/src/shared.h +++ b/src/shared.h @@ -14,10 +14,10 @@ #pragma once +#include "./parallel.h" #include "./sparse.h" #include "./utils.h" #include "./vec.h" -#include "manifold/parallel.h" namespace manifold { diff --git a/src/smoothing.cpp b/src/smoothing.cpp index 5c1d7e811..57d81b462 100644 --- a/src/smoothing.cpp +++ b/src/smoothing.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" namespace { using namespace manifold; diff --git a/src/sort.cpp b/src/sort.cpp index a1c78e083..f394aa526 100644 --- a/src/sort.cpp +++ b/src/sort.cpp @@ -16,7 +16,7 @@ #include #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" namespace { using namespace manifold; diff --git a/src/sparse.h b/src/sparse.h index 9eedb16a3..a25ea6114 100644 --- a/src/sparse.h +++ b/src/sparse.h @@ -13,11 +13,11 @@ // limitations under the License. #pragma once +#include "./parallel.h" #include "./utils.h" #include "./vec.h" #include "manifold/common.h" #include "manifold/optional_assert.h" -#include "manifold/parallel.h" namespace { template diff --git a/src/subdivision.cpp b/src/subdivision.cpp index 83b66d442..c8631d79c 100644 --- a/src/subdivision.cpp +++ b/src/subdivision.cpp @@ -13,7 +13,7 @@ // limitations under the License. #include "./impl.h" -#include "manifold/parallel.h" +#include "./parallel.h" template <> struct std::hash { diff --git a/src/vec.h b/src/vec.h index 48c6d4e10..b59b4b6ad 100644 --- a/src/vec.h +++ b/src/vec.h @@ -21,7 +21,7 @@ #endif #include -#include "manifold/parallel.h" +#include "./parallel.h" #include "manifold/vec_view.h" namespace manifold { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b57c3ed8e..473e188fd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,10 +39,10 @@ add_executable(manifold_test ${SOURCE_FILES}) target_link_libraries( manifold_test PRIVATE - GTest::gtest_main - manifold - samples - $<$:manifoldc> + GTest::gtest_main + manifold + samples + $<$:manifoldc> ) if(MANIFOLD_PAR) if(MANIFOLD_BUILTIN_TBB) From 1c9b86f5ac830042e4c0e4cbf46655672e8261a0 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 07:55:10 +0800 Subject: [PATCH 30/46] missing utils.h change --- src/utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.h b/src/utils.h index 29589f530..28ab45de3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -39,7 +39,7 @@ #endif #endif -#include "manifold/parallel.h" +#include "./parallel.h" #if __has_include() #include From 385e89afa0dfadef22a372949d061bfbc35fda72 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 07:59:25 +0800 Subject: [PATCH 31/46] fix --- extras/CMakeLists.txt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index e2564eea7..38aecaa1b 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -22,13 +22,8 @@ target_compile_options(perfTest PRIVATE ${MANIFOLD_FLAGS}) if(MANIFOLD_PAR AND NOT MSVC) add_executable(stlTest stl_test.cpp) - target_link_libraries(stlTest PRIVATE manifold) + target_link_libraries(stlTest PRIVATE manifold TBB::tbb) target_compile_options(stlTest PRIVATE ${MANIFOLD_FLAGS}) - if(MANIFOLD_BUILTIN_TBB) - target_link_libraries(stlTest PRIVATE TBB::tbb) - else() - target_link_libraries(stlTest PUBLIC TBB::tbb) - endif() endif() add_executable(largeSceneTest large_scene_test.cpp) @@ -37,7 +32,11 @@ target_compile_options(largeSceneTest PRIVATE ${MANIFOLD_FLAGS}) if(MANIFOLD_DEBUG) add_executable(minimizeTestcase minimize_testcase.cpp) - target_link_libraries(minimizeTestcase manifold) + target_link_libraries( + minimizeTestcase + manifold + $<$TBB::tbb> + ) target_compile_options(minimizeTestcase PRIVATE ${MANIFOLD_FLAGS}) endif() From 414350963ed2c8c0f7b3283b14c9f8b1dcad39ba Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 08:00:38 +0800 Subject: [PATCH 32/46] fix... --- extras/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index 38aecaa1b..690e47fb6 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -35,7 +35,7 @@ if(MANIFOLD_DEBUG) target_link_libraries( minimizeTestcase manifold - $<$TBB::tbb> + $<$:TBB::tbb> ) target_compile_options(minimizeTestcase PRIVATE ${MANIFOLD_FLAGS}) endif() From 7e0a9df3b42afef650d366dd60633bd9966a1d78 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 08:12:56 +0800 Subject: [PATCH 33/46] fix wasm tbb --- bindings/wasm/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bindings/wasm/CMakeLists.txt b/bindings/wasm/CMakeLists.txt index 1138fd259..190e6142a 100644 --- a/bindings/wasm/CMakeLists.txt +++ b/bindings/wasm/CMakeLists.txt @@ -18,7 +18,10 @@ set_source_files_properties( bindings.cpp PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js ) -target_link_libraries(manifoldjs manifold) +target_link_libraries( + manifoldjs + PRIVATE manifold $<$:TBB::tbb> +) target_compile_options(manifoldjs PRIVATE ${MANIFOLD_FLAGS}) target_link_options( manifoldjs From 916c3b2a1eb41409d6e81514ac2b80b4c39570b2 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 08:18:30 +0800 Subject: [PATCH 34/46] add more cmake consumer tests --- .github/workflows/manifold.yml | 46 +++++++++++++++++++++++++++++++++- scripts/test-cmake-subdir.sh | 25 ++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100755 scripts/test-cmake-subdir.sh diff --git a/.github/workflows/manifold.yml b/.github/workflows/manifold.yml index 352c3b6fd..3038d49eb 100644 --- a/.github/workflows/manifold.yml +++ b/.github/workflows/manifold.yml @@ -213,7 +213,7 @@ jobs: pip install trimesh pytest - name: Install TBB if: matrix.parallelization == 'ON' - run: brew install tbb onedpl + run: brew install tbb - uses: actions/checkout@v4 - uses: jwlawson/actions-setup-cmake@v2 - name: Build @@ -232,6 +232,50 @@ jobs: sudo cmake --install . cd .. ./scripts/test-cmake.sh + ./scripts/test-pkgconfig.sh + + build_mac_builtin_tbb: + timeout-minutes: 30 + runs-on: macos-latest + steps: + - name: Install common dependencies + run: | + brew install pkg-config googletest + pip install trimesh pytest + - uses: actions/checkout@v4 + - uses: jwlawson/actions-setup-cmake@v2 + - name: Build + run: | + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_PYBIND=OFF -DMANIFOLD_PAR=ON .. && make + - name: Test + run: | + cd build/test + ./manifold_test + cd ../../ + - name: test cmake consumer + run: | + cd build + sudo cmake --install . + cd .. + ./scripts/test-cmake.sh + ./scripts/test-pkgconfig.sh + + build_mac_builtin_tbb_subdir: + timeout-minutes: 30 + runs-on: macos-latest + steps: + - name: Install common dependencies + run: | + brew install pkg-config googletest + pip install trimesh pytest + - uses: actions/checkout@v4 + - uses: jwlawson/actions-setup-cmake@v2 + - name: test cmake consumer + run: | + cd .. + ./manifold/scripts/test-cmake-subdir.sh build_nix: timeout-minutes: 30 diff --git a/scripts/test-cmake-subdir.sh b/scripts/test-cmake-subdir.sh new file mode 100755 index 000000000..89350583b --- /dev/null +++ b/scripts/test-cmake-subdir.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +mkdir cmake-consumer +cd cmake-consumer + +cat < CMakeLists.txt +cmake_minimum_required(VERSION 3.18) +project(testing LANGUAGES CXX) +set(MANIFOLD_PAR ON) +add_subdirectory(manifold EXCLUDE_FROM_ALL) +add_executable(testing test.cpp) +target_link_libraries(testing PRIVATE manifold::manifold) +EOT + +cat < test.cpp +#include +int main() { manifold::Manifold foo; return 0; } +EOT + +mv ../manifold ./ +mkdir build +cd build +cmake .. +make +./testing + From 21ed208a770f1a48ff9eee0c3a7dd90563799f43 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 08:25:22 +0800 Subject: [PATCH 35/46] fix consumer --- cmake/manifold.pc.in | 2 +- scripts/test-cmake-subdir.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/manifold.pc.in b/cmake/manifold.pc.in index edd066175..a53a6a11c 100644 --- a/cmake/manifold.pc.in +++ b/cmake/manifold.pc.in @@ -9,4 +9,4 @@ Version: @MANIFOLD_VERSION@ URL: https://github.com/elalish/manifold Requires-private: tbb @TEMPLATE_OPTIONAL_CLIPPER@ Libs: -L${libdir} -lmanifold@PCFILE_LIB_SUFFIX@ -Cflags: -I${includedir} +Cflags: -I${includedir} -std=c++17 diff --git a/scripts/test-cmake-subdir.sh b/scripts/test-cmake-subdir.sh index 89350583b..c97f64b36 100755 --- a/scripts/test-cmake-subdir.sh +++ b/scripts/test-cmake-subdir.sh @@ -16,7 +16,7 @@ cat < test.cpp int main() { manifold::Manifold foo; return 0; } EOT -mv ../manifold ./ +cp -r ../manifold ./ mkdir build cd build cmake .. From 2e8a96c90b26f7044617953ccf0f6935e4de8fdf Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 08:39:02 +0800 Subject: [PATCH 36/46] add rpath --- cmake/manifold.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/manifold.pc.in b/cmake/manifold.pc.in index a53a6a11c..b4ab9edb6 100644 --- a/cmake/manifold.pc.in +++ b/cmake/manifold.pc.in @@ -8,5 +8,5 @@ Description: Geometry library for topological robustness Version: @MANIFOLD_VERSION@ URL: https://github.com/elalish/manifold Requires-private: tbb @TEMPLATE_OPTIONAL_CLIPPER@ -Libs: -L${libdir} -lmanifold@PCFILE_LIB_SUFFIX@ +Libs: -L${libdir} -lmanifold@PCFILE_LIB_SUFFIX@ -Wl,-rpath,${libdir} Cflags: -I${includedir} -std=c++17 From f2fd36d2bc029f1e1ad81315ac235a0f8cdfbe3c Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 08:54:25 +0800 Subject: [PATCH 37/46] Revert "add rpath" This reverts commit 2e8a96c90b26f7044617953ccf0f6935e4de8fdf. --- cmake/manifold.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/manifold.pc.in b/cmake/manifold.pc.in index b4ab9edb6..a53a6a11c 100644 --- a/cmake/manifold.pc.in +++ b/cmake/manifold.pc.in @@ -8,5 +8,5 @@ Description: Geometry library for topological robustness Version: @MANIFOLD_VERSION@ URL: https://github.com/elalish/manifold Requires-private: tbb @TEMPLATE_OPTIONAL_CLIPPER@ -Libs: -L${libdir} -lmanifold@PCFILE_LIB_SUFFIX@ -Wl,-rpath,${libdir} +Libs: -L${libdir} -lmanifold@PCFILE_LIB_SUFFIX@ Cflags: -I${includedir} -std=c++17 From 14cc18285ce71f215c0288a81c76edb120e85543 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 09:07:50 +0800 Subject: [PATCH 38/46] rpath specific to macos --- .github/workflows/manifold.yml | 2 +- scripts/test-pkgconfig.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/manifold.yml b/.github/workflows/manifold.yml index 3038d49eb..d3daed99c 100644 --- a/.github/workflows/manifold.yml +++ b/.github/workflows/manifold.yml @@ -260,7 +260,7 @@ jobs: sudo cmake --install . cd .. ./scripts/test-cmake.sh - ./scripts/test-pkgconfig.sh + LDFLAGS=-Wl,-rpath,/usr/local/lib ./scripts/test-pkgconfig.sh build_mac_builtin_tbb_subdir: timeout-minutes: 30 diff --git a/scripts/test-pkgconfig.sh b/scripts/test-pkgconfig.sh index 631ab640e..6f5a9c969 100755 --- a/scripts/test-pkgconfig.sh +++ b/scripts/test-pkgconfig.sh @@ -4,7 +4,7 @@ cd make-consumer cat <<'EOT' > Makefile CXXFLAGS=$(shell pkg-config --cflags manifold) -LDFLAGS=$(shell pkg-config --libs manifold) +LDFLAGS=${LDFLAGS} $(shell pkg-config --libs manifold) testing : testing.cpp EOT From 271b95b371f0268bc665d5a13fb500ceb79122bb Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 09:13:25 +0800 Subject: [PATCH 39/46] use override --- scripts/test-pkgconfig.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test-pkgconfig.sh b/scripts/test-pkgconfig.sh index 6f5a9c969..107a0451d 100755 --- a/scripts/test-pkgconfig.sh +++ b/scripts/test-pkgconfig.sh @@ -3,8 +3,8 @@ mkdir make-consumer cd make-consumer cat <<'EOT' > Makefile -CXXFLAGS=$(shell pkg-config --cflags manifold) -LDFLAGS=${LDFLAGS} $(shell pkg-config --libs manifold) +override CXXFLAGS += $(shell pkg-config --cflags manifold) +override LDFLAGS += $(shell pkg-config --libs manifold) testing : testing.cpp EOT From 4fdba845d1e1ac0b5961f9ae99679e9cc32afc9b Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 09:17:23 +0800 Subject: [PATCH 40/46] forgot to set rpath... --- .github/workflows/manifold.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/manifold.yml b/.github/workflows/manifold.yml index d3daed99c..15f4bd35d 100644 --- a/.github/workflows/manifold.yml +++ b/.github/workflows/manifold.yml @@ -232,7 +232,7 @@ jobs: sudo cmake --install . cd .. ./scripts/test-cmake.sh - ./scripts/test-pkgconfig.sh + LDFLAGS=-Wl,-rpath,/usr/local/lib ./scripts/test-pkgconfig.sh build_mac_builtin_tbb: timeout-minutes: 30 From f02edbba402ef49cc41325817caf748702c1ae46 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 14:07:19 +0800 Subject: [PATCH 41/46] remove #1045 related changes --- .github/workflows/manifold.yml | 2 +- bindings/wasm/bindings.cpp | 26 -------------------------- bindings/wasm/bindings.js | 3 --- bindings/wasm/examples/README.md | 5 ----- bindings/wasm/examples/vite.config.js | 6 ------ bindings/wasm/fixup.sh | 3 --- bindings/wasm/helpers.cpp | 2 +- flake.nix | 14 ++++---------- test/test_main.cpp | 21 --------------------- 9 files changed, 6 insertions(+), 76 deletions(-) delete mode 100755 bindings/wasm/fixup.sh diff --git a/.github/workflows/manifold.yml b/.github/workflows/manifold.yml index 15f4bd35d..0a98b9adb 100644 --- a/.github/workflows/manifold.yml +++ b/.github/workflows/manifold.yml @@ -281,7 +281,7 @@ jobs: timeout-minutes: 30 strategy: matrix: - variant: [manifold-none, manifold-tbb, manifold-js, manifold-js-tbb, manifold3d] + variant: [manifold-none, manifold-tbb, manifold-js, manifold3d] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/bindings/wasm/bindings.cpp b/bindings/wasm/bindings.cpp index 55376c6b9..c48fcfd30 100644 --- a/bindings/wasm/bindings.cpp +++ b/bindings/wasm/bindings.cpp @@ -22,29 +22,6 @@ #include "manifold/manifold.h" #include "manifold/polygon.h" -#if (MANIFOLD_PAR == 1) -#include - -#include -#endif - -void initTBB() { -#if (MANIFOLD_PAR == 1) - int num_threads = tbb::this_task_arena::max_concurrency(); - std::atomic barrier{num_threads}; - tbb::parallel_for( - 0, num_threads, - [&barrier](int) { - barrier--; - while (barrier > 0) { - // Send browser thread to event loop - std::this_thread::yield(); - } - }, - tbb::static_partitioner{}); -#endif -} - using namespace emscripten; using namespace manifold; @@ -218,7 +195,4 @@ EMSCRIPTEN_BINDINGS(whatever) { function("setCircularSegments", &Quality::SetCircularSegments); function("getCircularSegments", &Quality::GetCircularSegments); function("resetToCircularDefaults", &Quality::ResetToDefaults); - - // https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations - function("initTBB", &initTBB); } diff --git a/bindings/wasm/bindings.js b/bindings/wasm/bindings.js index 9ccaaedf6..b03b745f9 100644 --- a/bindings/wasm/bindings.js +++ b/bindings/wasm/bindings.js @@ -17,9 +17,6 @@ Module.setup = function() { if (_ManifoldInitialized) return; _ManifoldInitialized = true; - // warmup tbb for emscripten, according to - // https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations - Module.initTBB(); // conversion utilities function toVec(vec, list, f = x => x) { diff --git a/bindings/wasm/examples/README.md b/bindings/wasm/examples/README.md index da5146ebb..d394e45c9 100644 --- a/bindings/wasm/examples/README.md +++ b/bindings/wasm/examples/README.md @@ -43,8 +43,3 @@ To use the manifoldCAD.org editor (`npm run dev`), you'll likely have to set discussion of the [issue#328](https://github.com/elalish/manifold/issues/328#issuecomment-1473847102) of this repository. - -## Fixing Vite Static Worker Option Error - -Run `fixup.sh` in `bindings/wasm`. - diff --git a/bindings/wasm/examples/vite.config.js b/bindings/wasm/examples/vite.config.js index 9676c2d75..b5e5fadd1 100644 --- a/bindings/wasm/examples/vite.config.js +++ b/bindings/wasm/examples/vite.config.js @@ -7,12 +7,6 @@ export default defineConfig({ worker: { format: 'es', }, - server: { - headers: { - 'Cross-Origin-Embedder-Policy': 'require-corp', - 'Cross-Origin-Opener-Policy': 'same-origin', - }, - }, build: { target: 'esnext', sourcemap: true, diff --git a/bindings/wasm/fixup.sh b/bindings/wasm/fixup.sh deleted file mode 100755 index 6cab53f94..000000000 --- a/bindings/wasm/fixup.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -sed -i 's/var workerOptions={type:"module",workerData:"em-pthread",name:"em-pthread"};//g' ./examples/built/manifold.js -sed -i 's/workerOptions/{type:"module",workerData:"em-pthread",name:"em-pthread"}/g' ./examples/built/manifold.js diff --git a/bindings/wasm/helpers.cpp b/bindings/wasm/helpers.cpp index c9104017a..66bf70b9e 100644 --- a/bindings/wasm/helpers.cpp +++ b/bindings/wasm/helpers.cpp @@ -208,7 +208,7 @@ Manifold SetProperties(Manifold& manifold, int numProp, uintptr_t funcPtr) { Manifold LevelSet(uintptr_t funcPtr, Box bounds, double edgeLength, double level, double tolerance) { double (*f)(const vec3&) = reinterpret_cast(funcPtr); - return Manifold::LevelSet(f, bounds, edgeLength, level, tolerance, false); + return Manifold::LevelSet(f, bounds, edgeLength, level, tolerance); } std::vector Split(Manifold& a, Manifold& b) { diff --git a/flake.nix b/flake.nix index f37f57ff8..1671ce390 100644 --- a/flake.nix +++ b/flake.nix @@ -112,7 +112,7 @@ cd ../ ''; }; - manifold-emscripten = { parallel, doCheck ? true }: pkgs.buildEmscriptenPackage { + manifold-emscripten = { doCheck ? true }: pkgs.buildEmscriptenPackage { name = "manifold-js"; version = manifold-version; src = self; @@ -126,10 +126,8 @@ mkdir build cd build emcmake cmake -DCMAKE_BUILD_TYPE=Release \ - -DMANIFOLD_PAR=${if parallel then "ON" else "OFF"} \ -DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest-src} \ - -DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 \ - ${if parallel then "-DFETCHCONTENT_SOURCE_DIR_TBB=${onetbb-src}" else ""} .. + -DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 .. ''; buildPhase = '' emmake make -j''${NIX_BUILD_CORES} @@ -149,12 +147,7 @@ packages = { manifold-tbb = manifold { }; manifold-none = manifold { parallel = false; }; - manifold-js = manifold-emscripten { parallel = false; }; - # disable check for now - manifold-js-tbb = manifold-emscripten { - parallel = true; - doCheck = false; - }; + manifold-js = manifold-emscripten { }; # but how should we make it work with other python versions? manifold3d = with pkgs.python3Packages; buildPythonPackage { pname = "manifold3d"; @@ -199,6 +192,7 @@ gtest assimp clipper2 + pkg-config # useful tools clang-tools_18 diff --git a/test/test_main.cpp b/test/test_main.cpp index 250a76133..79728e40b 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -25,10 +25,6 @@ #define FrameMarkEnd(x) #endif -#if (MANIFOLD_PAR == 1) -#include -#endif - using namespace manifold; Options options; @@ -46,23 +42,6 @@ void print_usage() { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - // warmup tbb for emscripten, according to - // https://github.com/oneapi-src/oneTBB/blob/master/WASM_Support.md#limitations -#if defined(__EMSCRIPTEN__) && (MANIFOLD_PAR == 1) - int num_threads = tbb::this_task_arena::max_concurrency(); - std::atomic barrier{num_threads}; - tbb::parallel_for( - 0, num_threads, - [&barrier](int) { - barrier--; - while (barrier > 0) { - // Send browser thread to event loop - std::this_thread::yield(); - } - }, - tbb::static_partitioner{}); -#endif - const char* name = "test setup"; FrameMarkStart(name); From 253333c41b0aad878aa6c66d35b0f29980cea999 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 14:13:05 +0800 Subject: [PATCH 42/46] integrate #1052 --- CMakeLists.txt | 14 ++++++++++++++ cmake/version.h.in | 19 +++++++++++++++++++ scripts/test-cmake-subdir.sh | 1 + scripts/test-cmake.sh | 1 + scripts/test-pkgconfig.sh | 1 + src/CMakeLists.txt | 1 + 6 files changed, 37 insertions(+) create mode 100644 cmake/version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b2590c1da..f1016b37d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,6 +259,20 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold ) +configure_file( + cmake/version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h + @ONLY +) +set_source_files_properties( + ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h + PROPERTIES GENERATED TRUE +) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold +) + # PkgConfig file if(MANIFOLD_CROSS_SECTION) set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2") diff --git a/cmake/version.h.in b/cmake/version.h.in new file mode 100644 index 000000000..256ae36db --- /dev/null +++ b/cmake/version.h.in @@ -0,0 +1,19 @@ +// Copyright 2024 The Manifold Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#define MANIFOLD_VERSION_MAJOR @MANIFOLD_VERSION_MAJOR@ +#define MANIFOLD_VERSION_MINOR @MANIFOLD_VERSION_MINOR@ +#define MANIFOLD_VERSION_PATH @MANIFOLD_VERSION_PATCH@ diff --git a/scripts/test-cmake-subdir.sh b/scripts/test-cmake-subdir.sh index c97f64b36..b719a9bce 100755 --- a/scripts/test-cmake-subdir.sh +++ b/scripts/test-cmake-subdir.sh @@ -13,6 +13,7 @@ EOT cat < test.cpp #include +#include int main() { manifold::Manifold foo; return 0; } EOT diff --git a/scripts/test-cmake.sh b/scripts/test-cmake.sh index 9468b4cb2..456632cb2 100755 --- a/scripts/test-cmake.sh +++ b/scripts/test-cmake.sh @@ -12,6 +12,7 @@ EOT cat < test.cpp #include +#include int main() { manifold::Manifold foo; return 0; } EOT diff --git a/scripts/test-pkgconfig.sh b/scripts/test-pkgconfig.sh index 107a0451d..e3f7ccd29 100755 --- a/scripts/test-pkgconfig.sh +++ b/scripts/test-pkgconfig.sh @@ -11,6 +11,7 @@ EOT cat < testing.cpp #include +#include int main() { manifold::Manifold foo; return 0; } EOT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 629c924d3..0c6503551 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,6 +95,7 @@ target_include_directories( PUBLIC $ $ + $ PRIVATE ${MANIFOLD_INCLUDE_DIRS} ) From 73359da21e2965a8eecad407f3e9153fcd035911 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 14:49:03 +0800 Subject: [PATCH 43/46] allow version override --- CMakeLists.txt | 11 ++++++ README.md | 19 +++++++++- cmake/manifoldConfig.cmake.in | 8 ++--- cmake/manifoldDeps.cmake | 66 +++++++++++++++++++---------------- 4 files changed, 69 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1016b37d..29892950d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,17 @@ cmake_dependent_option( "EMSCRIPTEN" OFF ) +# These three options can force the build to avoid using the system version of +# the dependency +# This will either use the provided source directory via +# FETCHCONTENT_SOURCE_DIR_XXX, or fetch the source from GitHub. +# Note that the dependency will be built as static dependency to avoid dynamic +# library conflict. +# When the system package is unavailable, the option will be automatically set +# to true. +option(MANIFOLD_USE_BUILTIN_TBB "Use builtin tbb" OFF) +option(MANIFOLD_USE_BUILTIN_CLIPPER2 "Use builtin clipper2" OFF) +option(MANIFOLD_USE_BUILTIN_NANOBIND "Use builtin nanobind" OFF) # default to Release build option(CMAKE_BUILD_TYPE "Build type" Release) diff --git a/README.md b/README.md index 2c17d47cb..cd4b51707 100644 --- a/README.md +++ b/README.md @@ -112,13 +112,30 @@ CMake flags (usage e.g. `-DMANIFOLD_DEBUG=ON`): - `TRACY_ENABLE=[, ON]`: Enable integration with tracy profiler. See profiling section below. -Offline building (with missing dependencies): +Dependency version override: +- `MANIFOLD_USE_BUILTIN_TBB=[, ON]`: Use builtin version of tbb. +- `MANIFOLD_USE_BUILTIN_CLIPPER2=[, ON]`: Use builtin version of clipper2. +- `MANIFOLD_USE_BUILTIN_NANOBIND=[, ON]`: Use builtin version of nanobind. + +> Note: These three options can force the build to avoid using the system +> version of the dependency. This will either use the provided source directory +> via `FETCHCONTENT_SOURCE_DIR_*` (see below), or fetch the source from GitHub. +> Note that the dependency will be built as static dependency to avoid dynamic +> library conflict. When the system package is unavailable, the option will be +> automatically set to true. + +Offline building (with missing dependencies/dependency version override): - `MANIFOLD_DOWNLOADS=[OFF, ]`: Automatically download missing dependencies. Need to set `FETCHCONTENT_SOURCE_DIR_*` if the dependency `*` is missing. - `FETCHCONTENT_SOURCE_DIR_TBB`: path to tbb source (if `MANIFOLD_PAR` is enabled). - `FETCHCONTENT_SOURCE_DIR_CLIPPER2`: path to tbb source (if `MANIFOLD_CROSS_SECTION` is enabled). +- `FETCHCONTENT_SOURCE_DIR_NANOBIND`: path to nanobind source (if `MANIFOLD_PYBIND` is enabled). - `FETCHCONTENT_SOURCE_DIR_GOOGLETEST`: path to googletest source (if `MANIFOLD_TEST` is enabled). +> Note: When `FETCHCONTENT_SOURCE_DIR_*` is set, CMake will use the provided +> source directly without downloading regardless of the value of +> `MANIFOLD_DOWNLOADS`. + The build instructions used by our CI are in [manifold.yml](https://github.com/elalish/manifold/blob/master/.github/workflows/manifold.yml), which is a good source to check if something goes wrong and for instructions specific to other platforms, like Windows. ### WASM diff --git a/cmake/manifoldConfig.cmake.in b/cmake/manifoldConfig.cmake.in index 3bad36668..b4d3feb2e 100644 --- a/cmake/manifoldConfig.cmake.in +++ b/cmake/manifoldConfig.cmake.in @@ -12,14 +12,14 @@ if(_FIND_ROOT STREQUAL "/") endif() set(MANIFOLD_CROSS_SECTION "@MANIFOLD_CROSS_SECTION@") -set(MANIFOLD_BUILTIN_CLIPPER2 "@MANIFOLD_BUILTIN_CLIPPER2@") -if(MANIFOLD_CROSS_SECTION AND NOT MANIFOLD_BUILTIN_CLIPPER2) +set(MANIFOLD_USE_BUILTIN_CLIPPER2 "@MANIFOLD_USE_BUILTIN_CLIPPER2@") +if(MANIFOLD_CROSS_SECTION AND NOT MANIFOLD_USE_BUILTIN_CLIPPER2) set(Clipper2_ROOT "${_FIND_ROOT}") find_package(Clipper2 REQUIRED) endif() set(MANIFOLD_PAR "@MANIFOLD_PAR@") -set(MANIFOLD_BUILTIN_TBB "@MANIFOLD_BUILTIN_TBB@") -if(MANIFOLD_PAR STREQUAL "ON" AND NOT MANIFOLD_BUILTIN_TBB) +set(MANIFOLD_USE_BUILTIN_TBB "@MANIFOLD_USE_BUILTIN_TBB@") +if(MANIFOLD_PAR STREQUAL "ON" AND NOT MANIFOLD_USE_BUILTIN_TBB) find_package(TBB REQUIRED) endif() set(MANIFOLD_EXPORT "@MANIFOLD_EXPORT@") diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index 84cc3e16e..f1b3faca8 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -38,16 +38,31 @@ set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS OFF) # If we're building parallel, we need the requisite libraries -set(MANIFOLD_BUILTIN_TBB OFF) if(MANIFOLD_PAR) find_package(Threads REQUIRED) - find_package(TBB QUIET) - find_package(PkgConfig QUIET) - if(NOT TBB_FOUND AND PKG_CONFIG_FOUND) - pkg_check_modules(TBB tbb) + if(NOT MANIFOLD_USE_BUILTIN_TBB) + find_package(TBB QUIET) + find_package(PkgConfig QUIET) + if(NOT TBB_FOUND AND PKG_CONFIG_FOUND) + pkg_check_modules(TBB tbb) + endif() endif() - if(NOT TBB_FOUND) + if(TBB_FOUND) + if(NOT TARGET TBB::tbb) + if(NOT TARGET tbb) + add_library(TBB::tbb SHARED IMPORTED) + set_property( + TARGET TBB::tbb + PROPERTY IMPORTED_LOCATION ${TBB_LINK_LIBRARIES} + ) + target_include_directories(TBB::tbb INTERFACE ${TBB_INCLUDE_DIRS}) + else() + add_library(TBB::tbb ALIAS tbb) + endif() + endif() + else() logmissingdep("TBB" , "Parallel mode") + set(MANIFOLD_USE_BUILTIN_TBB ON) set(TBB_TEST OFF CACHE INTERNAL "" FORCE) set(TBB_STRICT OFF CACHE INTERNAL "" FORCE) FetchContent_Declare( @@ -58,28 +73,16 @@ if(MANIFOLD_PAR) EXCLUDE_FROM_ALL ) FetchContent_MakeAvailable(TBB) - set(MANIFOLD_BUILTIN_TBB ON) - endif() - if(NOT TARGET TBB::tbb) - if(NOT TARGET tbb) - add_library(TBB::tbb SHARED IMPORTED) - set_property( - TARGET TBB::tbb - PROPERTY IMPORTED_LOCATION ${TBB_LINK_LIBRARIES} - ) - target_include_directories(TBB::tbb INTERFACE ${TBB_INCLUDE_DIRS}) - else() - add_library(TBB::tbb ALIAS tbb) - endif() endif() endif() # If we're building cross_section, we need Clipper2 -set(MANIFOLD_BUILTIN_CLIPPER2 OFF) if(MANIFOLD_CROSS_SECTION) - find_package(Clipper2 QUIET) - if(NOT Clipper2_FOUND AND PKG_CONFIG_FOUND) - pkg_check_modules(Clipper2 Clipper2) + if(NOT MANIFOLD_USE_BUILTIN_CLIPPER2) + find_package(Clipper2 QUIET) + if(NOT Clipper2_FOUND AND PKG_CONFIG_FOUND) + pkg_check_modules(Clipper2 Clipper2) + endif() endif() if(Clipper2_FOUND) add_library(Clipper2 SHARED IMPORTED) @@ -96,7 +99,7 @@ if(MANIFOLD_CROSS_SECTION) target_include_directories(Clipper2 INTERFACE ${Clipper2_INCLUDE_DIRS}) else() logmissingdep("Clipper2" , "cross_section") - set(MANIFOLD_BUILTIN_CLIPPER2 ON) + set(MANIFOLD_USE_BUILTIN_CLIPPER2 ON) set(CLIPPER2_UTILS OFF) set(CLIPPER2_EXAMPLES OFF) set(CLIPPER2_TESTS OFF) @@ -153,11 +156,13 @@ if(MANIFOLD_PYBIND) message("Python version too old, stub will not be generated") endif() - execute_process( - COMMAND "${Python_EXECUTABLE}" -m nanobind --version - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE NB_VERSION - ) + if(NOT MANIFOLD_USE_BUILTIN_NANOBIND) + execute_process( + COMMAND "${Python_EXECUTABLE}" -m nanobind --version + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE NB_VERSION + ) + endif() # we are fine with 2.0.0 if(NB_VERSION VERSION_GREATER_EQUAL 2.0.0) message("Found nanobind, version ${NB_VERSION}") @@ -168,8 +173,8 @@ if(MANIFOLD_PYBIND) ) find_package(nanobind CONFIG REQUIRED) else() - include(FetchContent) logmissingdep("nanobind" , "MANIFOLD_PYBIND") + set(MANIFOLD_USE_BUILTIN_NANOBIND ON) FetchContent_Declare( nanobind GIT_REPOSITORY https://github.com/wjakob/nanobind.git @@ -214,6 +219,7 @@ if(MANIFOLD_TEST) endif() if(MANIFOLD_FUZZ) + logmissingdep("fuzztest" , "MANIFOLD_FUZZ") FetchContent_Declare( fuzztest GIT_REPOSITORY https://github.com/google/fuzztest.git From 3370652ca5cb8354daf2d25e644f88821631f865 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 19:21:38 +0800 Subject: [PATCH 44/46] minor improvements --- CMakeLists.txt | 6 +++++ cmake/info.cmake | 57 +++++++++++++++++++++++++--------------- cmake/manifold.pc.in | 2 +- cmake/manifoldDeps.cmake | 2 +- test/CMakeLists.txt | 8 +----- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29892950d..5246ab8fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,6 +270,9 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/manifold ) +# note that the path ${CMAKE_CURRENT_BINARY_DIR}/include is included when we +# build the manifold target (as ${PROJECT_SOURCE_DIR}/include), so users can +# include manifold/version.h without installing our library. configure_file( cmake/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/manifold/version.h @@ -285,6 +288,9 @@ install( ) # PkgConfig file +if(MANIFOLD_PAR) + set(TEMPLATE_OPTIONAL_TBB "tbb") +endif() if(MANIFOLD_CROSS_SECTION) set(TEMPLATE_OPTIONAL_CLIPPER "Clipper2") endif() diff --git a/cmake/info.cmake b/cmake/info.cmake index 85ee1c0bd..961b3bdac 100644 --- a/cmake/info.cmake +++ b/cmake/info.cmake @@ -14,6 +14,10 @@ # configuration summary, idea from openscad # https://github.com/openscad/openscad/blob/master/cmake/Modules/info.cmake + +get_target_property(MANIFOLD_COMPILE_OPTIONS manifold COMPILE_OPTIONS) +get_target_property(MANIFOLD_LINK_OPTIONS manifold LINK_OPTIONS) + message(STATUS "====================================") message(STATUS "Manifold Build Configuration Summary") message(STATUS "====================================") @@ -36,28 +40,39 @@ else() message(STATUS "Environment: Unknown") endif() message(STATUS " ") -message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") -message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") -message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") -message(STATUS "CPACK_CMAKE_GENERATOR: ${CPACK_CMAKE_GENERATOR}") -message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") -message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") -message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") -message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") +message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") +message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") +message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}") +message(STATUS "CPACK_CMAKE_GENERATOR: ${CPACK_CMAKE_GENERATOR}") +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") +message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") +message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") if(APPLE) - message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") - message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") + message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") + message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") endif() -message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") +message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") message(STATUS " ") -message(STATUS "MANIFOLD_PAR: ${MANIFOLD_PAR}") -message(STATUS "MANIFOLD_CROSS_SECTION: ${MANIFOLD_CROSS_SECTION}") -message(STATUS "MANIFOLD_EXPORT: ${MANIFOLD_EXPORT}") -message(STATUS "MANIFOLD_TEST: ${MANIFOLD_TEST}") -message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}") -message(STATUS "MANIFOLD_DEBUG: ${MANIFOLD_DEBUG}") -message(STATUS "MANIFOLD_CBIND: ${MANIFOLD_CBIND}") -message(STATUS "MANIFOLD_PYBIND: ${MANIFOLD_PYBIND}") -message(STATUS "MANIFOLD_JSBIND: ${MANIFOLD_JSBIND}") -message(STATUS "MANIFOLD_FLAGS: ${MANIFOLD_FLAGS}") +message(STATUS "MANIFOLD_VERSION: ${MANIFOLD_VERSION}") +message(STATUS "MANIFOLD_PAR: ${MANIFOLD_PAR}") +message(STATUS "MANIFOLD_CROSS_SECTION: ${MANIFOLD_CROSS_SECTION}") +message(STATUS "MANIFOLD_EXPORT: ${MANIFOLD_EXPORT}") +message(STATUS "MANIFOLD_TEST: ${MANIFOLD_TEST}") +message(STATUS "MANIFOLD_DEBUG: ${MANIFOLD_DEBUG}") +message(STATUS "MANIFOLD_CBIND: ${MANIFOLD_CBIND}") +message(STATUS "MANIFOLD_PYBIND: ${MANIFOLD_PYBIND}") +message(STATUS "MANIFOLD_JSBIND: ${MANIFOLD_JSBIND}") +message(STATUS "MANIFOLD_FLAGS: ${MANIFOLD_FLAGS}") +# these two include global flags added through add_compile_options and +# add_link_options +message(STATUS "MANIFOLD_COMPILE_OPTIONS: ${MANIFOLD_COMPILE_OPTIONS}") +message(STATUS "MANIFOLD_LINK_OPTIONS: ${MANIFOLD_LINK_OPTIONS}") +message(STATUS "MANIFOLD_DOWNLOADS: ${MANIFOLD_DOWNLOADS}") +message(STATUS "MANIFOLD_USE_BUILTIN_TBB: ${MANIFOLD_USE_BUILTIN_TBB}") +message(STATUS "MANIFOLD_USE_BUILTIN_CLIPPER2: ${MANIFOLD_USE_BUILTIN_CLIPPER2}") +message(STATUS "MANIFOLD_USE_BUILTIN_NANOBIND: ${MANIFOLD_USE_BUILTIN_NANOBIND}") +message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}") +message(STATUS "TRACY_ENABLE: ${TRACY_ENABLE}") +message(STATUS "TRACY_MEMORY_USAGE: ${TRACY_MEMORY_USAGE}") message(STATUS " ") diff --git a/cmake/manifold.pc.in b/cmake/manifold.pc.in index a53a6a11c..6d0da0d85 100644 --- a/cmake/manifold.pc.in +++ b/cmake/manifold.pc.in @@ -7,6 +7,6 @@ Name: manifold@PCFILE_LIB_SUFFIX@ Description: Geometry library for topological robustness Version: @MANIFOLD_VERSION@ URL: https://github.com/elalish/manifold -Requires-private: tbb @TEMPLATE_OPTIONAL_CLIPPER@ +Requires-private: @TEMPLATE_OPTIONAL_TBB@ @TEMPLATE_OPTIONAL_CLIPPER@ Libs: -L${libdir} -lmanifold@PCFILE_LIB_SUFFIX@ Cflags: -I${includedir} -std=c++17 diff --git a/cmake/manifoldDeps.cmake b/cmake/manifoldDeps.cmake index f1b3faca8..a0e1af0ec 100644 --- a/cmake/manifoldDeps.cmake +++ b/cmake/manifoldDeps.cmake @@ -37,7 +37,7 @@ set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) # we build fetched dependencies as static library set(BUILD_SHARED_LIBS OFF) -# If we're building parallel, we need the requisite libraries +# If we're building parallel, we need tbb if(MANIFOLD_PAR) find_package(Threads REQUIRED) if(NOT MANIFOLD_USE_BUILTIN_TBB) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 473e188fd..31f668ac9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,14 +43,8 @@ target_link_libraries( manifold samples $<$:manifoldc> + $<$:TBB::tbb> ) -if(MANIFOLD_PAR) - if(MANIFOLD_BUILTIN_TBB) - target_link_libraries(manifold_test PRIVATE TBB::tbb) - else() - target_link_libraries(manifold_test PUBLIC TBB::tbb) - endif() -endif() if(EMSCRIPTEN) target_link_options( From bc7d3cd89792ded809f551fe34eb3e734ff03109 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 17 Nov 2024 19:51:26 +0800 Subject: [PATCH 45/46] msvc changes --- CMakeLists.txt | 1 + bindings/c/CMakeLists.txt | 16 +--------------- cmake/configHelper.cmake | 39 +++++++++++++++++++++++++++++++++++++++ cmake/info.cmake | 18 +++++++++++++++--- extras/CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 7 +------ test/CMakeLists.txt | 12 +----------- 7 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 cmake/configHelper.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5246ab8fc..c7f84ef7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,6 +207,7 @@ if("${isSystemDir}" STREQUAL "-1") endif("${isSystemDir}" STREQUAL "-1") include(${PROJECT_SOURCE_DIR}/cmake/manifoldDeps.cmake) +include(${PROJECT_SOURCE_DIR}/cmake/configHelper.cmake) add_subdirectory(src) add_subdirectory(bindings) diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 9bd481003..2f3150d06 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -26,21 +26,7 @@ add_library( cross.cpp rect.cpp ) -add_library(manifold::manifoldc ALIAS manifoldc) -set_property(TARGET manifoldc PROPERTY VERSION "${MANIFOLD_VERSION}") -set_property(TARGET manifoldc PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) - -if(MSVC) - set_target_properties(manifoldc PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) - set_target_properties( - manifoldc - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin - ) - set_target_properties( - manifoldc - PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin - ) -endif() +exportlib(manifoldc) if(MANIFOLD_EXPORT) target_sources(manifoldc PRIVATE meshIOc.cpp) diff --git a/cmake/configHelper.cmake b/cmake/configHelper.cmake new file mode 100644 index 000000000..cddf0b32d --- /dev/null +++ b/cmake/configHelper.cmake @@ -0,0 +1,39 @@ +# Copyright 2024 The Manifold Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function(exportbin TARGET) + if(MSVC) + set_target_properties( + ${TARGET} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin + ) + endif() +endfunction() + +function(exportlib TARGET) + add_library(manifold::${TARGET} ALIAS ${TARGET}) + set_target_properties( + ${TARGET} + PROPERTIES VERSION "${MANIFOLD_VERSION}" SOVERSION ${MANIFOLD_VERSION_MAJOR} + ) + if(MSVC) + set_target_properties( + ${TARGET} + PROPERTIES + WINDOWS_EXPORT_ALL_SYMBOLS ON + LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib + ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib + ) + endif() +endfunction() diff --git a/cmake/info.cmake b/cmake/info.cmake index 961b3bdac..2687bd6cf 100644 --- a/cmake/info.cmake +++ b/cmake/info.cmake @@ -17,6 +17,9 @@ get_target_property(MANIFOLD_COMPILE_OPTIONS manifold COMPILE_OPTIONS) get_target_property(MANIFOLD_LINK_OPTIONS manifold LINK_OPTIONS) +if(MANIFOLD_LINK_OPTIONS STREQUAL "MANIFOLD_LINK_OPTIONS-NOTFOUND") + set(MANIFOLD_LINK_OPTIONS "") +endif() message(STATUS "====================================") message(STATUS "Manifold Build Configuration Summary") @@ -49,7 +52,10 @@ message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") if(APPLE) - message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") + message( + STATUS + "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}" + ) message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}") endif() message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") @@ -70,8 +76,14 @@ message(STATUS "MANIFOLD_COMPILE_OPTIONS: ${MANIFOLD_COMPILE_OPTIONS}") message(STATUS "MANIFOLD_LINK_OPTIONS: ${MANIFOLD_LINK_OPTIONS}") message(STATUS "MANIFOLD_DOWNLOADS: ${MANIFOLD_DOWNLOADS}") message(STATUS "MANIFOLD_USE_BUILTIN_TBB: ${MANIFOLD_USE_BUILTIN_TBB}") -message(STATUS "MANIFOLD_USE_BUILTIN_CLIPPER2: ${MANIFOLD_USE_BUILTIN_CLIPPER2}") -message(STATUS "MANIFOLD_USE_BUILTIN_NANOBIND: ${MANIFOLD_USE_BUILTIN_NANOBIND}") +message( + STATUS + "MANIFOLD_USE_BUILTIN_CLIPPER2: ${MANIFOLD_USE_BUILTIN_CLIPPER2}" +) +message( + STATUS + "MANIFOLD_USE_BUILTIN_NANOBIND: ${MANIFOLD_USE_BUILTIN_NANOBIND}" +) message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}") message(STATUS "TRACY_ENABLE: ${TRACY_ENABLE}") message(STATUS "TRACY_MEMORY_USAGE: ${TRACY_MEMORY_USAGE}") diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index 690e47fb6..ec69f2f2b 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -19,6 +19,7 @@ endif() add_executable(perfTest perf_test.cpp) target_link_libraries(perfTest manifold) target_compile_options(perfTest PRIVATE ${MANIFOLD_FLAGS}) +exportbin(perfTest) if(MANIFOLD_PAR AND NOT MSVC) add_executable(stlTest stl_test.cpp) @@ -29,6 +30,7 @@ endif() add_executable(largeSceneTest large_scene_test.cpp) target_link_libraries(largeSceneTest manifold) target_compile_options(largeSceneTest PRIVATE ${MANIFOLD_FLAGS}) +exportbin(largeSceneTest) if(MANIFOLD_DEBUG) add_executable(minimizeTestcase minimize_testcase.cpp) @@ -38,10 +40,12 @@ if(MANIFOLD_DEBUG) $<$:TBB::tbb> ) target_compile_options(minimizeTestcase PRIVATE ${MANIFOLD_FLAGS}) + exportbin(minimizeTestcase) endif() if(MANIFOLD_EXPORT) add_executable(convertFile convert_file.cpp) target_link_libraries(convertFile manifold manifold) target_compile_options(convertFile PRIVATE ${MANIFOLD_FLAGS}) + exportbin(convertFile) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c6503551..72b174441 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,11 +99,6 @@ target_include_directories( PRIVATE ${MANIFOLD_INCLUDE_DIRS} ) -add_library(manifold::manifold ALIAS manifold) -set_property(TARGET manifold PROPERTY VERSION "${MANIFOLD_VERSION}") -set_property(TARGET manifold PROPERTY SOVERSION ${MANIFOLD_VERSION_MAJOR}) -if(MSVC) - set_target_properties(manifold PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) -endif() +exportlib(manifold) install(TARGETS manifold EXPORT manifoldTargets) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 31f668ac9..53d571265 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,6 +59,7 @@ if(EMSCRIPTEN) endif() target_compile_options(manifold_test PRIVATE ${MANIFOLD_FLAGS}) +exportbin(manifold_test) add_test(test_all manifold_test) @@ -69,14 +70,3 @@ if(MANIFOLD_FUZZ) link_fuzztest(polygon_fuzz) gtest_discover_tests(polygon_fuzz) endif() - -if(MSVC) - set_target_properties( - manifold_test - PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin - ) - set_target_properties( - manifold_test - PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin - ) -endif() From 5979b060873c650d72df21014c977dc81eedfc0c Mon Sep 17 00:00:00 2001 From: Emmett Lalish Date: Sun, 17 Nov 2024 11:46:56 -0800 Subject: [PATCH 46/46] fix typo --- cmake/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/version.h.in b/cmake/version.h.in index 256ae36db..f708f90c9 100644 --- a/cmake/version.h.in +++ b/cmake/version.h.in @@ -16,4 +16,4 @@ #define MANIFOLD_VERSION_MAJOR @MANIFOLD_VERSION_MAJOR@ #define MANIFOLD_VERSION_MINOR @MANIFOLD_VERSION_MINOR@ -#define MANIFOLD_VERSION_PATH @MANIFOLD_VERSION_PATCH@ +#define MANIFOLD_VERSION_PATCH @MANIFOLD_VERSION_PATCH@