From efacf9982facc436b6fc7c6fefad96756b9238c3 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Fri, 29 Mar 2024 00:30:02 -0400 Subject: [PATCH] Apple Silicon Support (#39) * Move CMake dependencies to CPM and add alternative to SSE instructions * Add header to Triplet.hpp * Update libigl * Move project CMake option * Update CI * Fix CI Ccache path * Fix debug build --- .clang-format | 3 - .github/workflows/continuous.yml | 28 ++-- CMakeLists.txt | 14 +- README.md | 4 +- cmake/ipc/ipc_cpm_cache.cmake | 25 ++++ .../ipc_warnings.cmake} | 0 cmake/recipes/CPM.cmake | 33 +++++ cmake/recipes/amgcl.cmake | 16 +-- cmake/recipes/boost.cmake | 59 +++++--- cmake/recipes/catch2.cmake | 27 ++-- cmake/recipes/ccd_wrapper.cmake | 9 +- cmake/recipes/cli11.cmake | 12 +- cmake/recipes/eigen.cmake | 82 +++++------ cmake/recipes/eigen_gurobi.cmake | 9 +- cmake/recipes/filesystem.cmake | 11 +- cmake/recipes/finite_diff.cmake | 12 +- cmake/recipes/libigl.cmake | 72 ++-------- cmake/recipes/mshio.cmake | 12 +- cmake/recipes/onetbb.cmake | 88 ++++++++---- cmake/recipes/osqp.cmake | 10 +- cmake/recipes/spdlog.cmake | 24 +--- cmake/recipes/tbb.cmake | 136 ------------------ src/Mesh.cpp | 5 +- src/Projects/CMakeLists.txt | 7 +- src/Projects/Diagnostic/CMakeLists.txt | 2 +- src/Projects/Diagnostic/Diagnostic.cpp | 1 - src/Projects/MeshProcessing/CMakeLists.txt | 2 +- .../MeshProcessing/MeshProcessing.cpp | 2 - src/Utils/SVD/Tools.h | 13 +- src/Utils/Triplet.hpp | 1 + src/main.cpp | 4 +- 31 files changed, 285 insertions(+), 438 deletions(-) create mode 100644 cmake/ipc/ipc_cpm_cache.cmake rename cmake/{IPCWarnings.cmake => ipc/ipc_warnings.cmake} (100%) create mode 100644 cmake/recipes/CPM.cmake delete mode 100644 cmake/recipes/tbb.cmake diff --git a/.clang-format b/.clang-format index fdaddcde1..1bb1db53f 100644 --- a/.clang-format +++ b/.clang-format @@ -58,12 +58,9 @@ SpacesInAngles: false SpaceInEmptyParentheses: false SpacesInCStyleCastParentheses: false SpaceAfterCStyleCast: false -SpacesInSquareBrackets: false SpaceAfterTemplateKeyword: true SpacesInContainerLiterals: false -SpacesInParentheses: false SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: false ContinuationIndentWidth: 4 CommentPragmas: '^ IWYU pragma:' ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] diff --git a/.github/workflows/continuous.yml b/.github/workflows/continuous.yml index f06ed412b..c974dee18 100644 --- a/.github/workflows/continuous.yml +++ b/.github/workflows/continuous.yml @@ -4,10 +4,10 @@ on: workflow_dispatch: push: branches: - - master + - main pull_request: branches: - - master + - main env: CTEST_OUTPUT_ON_FAILURE: ON @@ -33,37 +33,35 @@ jobs: name: Linux steps: - name: Checkout repository - uses: actions/checkout@v1 + uses: actions/checkout@v4.0.0 with: fetch-depth: 10 - name: Dependencies (Linux) if: runner.os == 'Linux' run: | - sudo apt-get update && - sudo apt-get install \ - xorg-dev \ - libsuitesparse-dev \ - libblas-dev \ - libglu1-mesa-dev \ - liblapack-dev \ - ccache + sudo apt-get update + sudo apt-get install xorg-dev libsuitesparse-dev libblas-dev libglu1-mesa-dev liblapack-dev ccache + echo 'CACHE_PATH=~/.cache/ccache' >> "$GITHUB_ENV" - name: Dependencies (macOS) if: runner.os == 'macOS' - run: brew install suite-sparse ccache + run: | + brew install suite-sparse ccache + echo 'CACHE_PATH=~/Library/Caches/ccache' >> "$GITHUB_ENV" - name: Cache Build id: cache-build - uses: actions/cache@v1 + uses: actions/cache@v3.0.11 with: - path: ~/.ccache + path: ${{ env.CACHE_PATH }} key: ${{ runner.os }}-${{ matrix.config }}-cache - name: Prepare ccache run: | ccache --max-size=1.0G - ccache -V && ccache --show-stats && ccache --zero-stats + ccache -V && ccache --show-config + ccache --show-stats && ccache --zero-stats - name: Configure run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index deb002b67..344201751 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,13 +45,19 @@ option(IPC_WITH_EXACT_CCD "Use exact CCD as a verification" ## Top level options option(IPC_WITH_TESTS "Build unit tests using Catch2" ${IPC_TOPLEVEL_PROJECT}) +# project-options +option(IPC_BUILD_DIAGNOSTIC_PROJECT "Build the Diagnostic sub-project" ${IPC_TOPLEVEL_PROJECT}) +option(IPC_BUILD_MESH_PROCESSING_PROJECT "Build the MeshProcessing sub-project" ${IPC_TOPLEVEL_PROJECT}) + ################################################################################ ### Configuration -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ipc) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/find) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/recipes) +include(ipc_cpm_cache) + ################################################################################ # IPC Library ################################################################################ @@ -99,7 +105,7 @@ target_include_directories(${PROJECT_NAME}_dev PUBLIC ################################################################################ # Extra warnings -include(IPCWarnings) +include(ipc_warnings) target_link_libraries(${PROJECT_NAME}_dev PRIVATE IPC::warnings) # tbb @@ -122,9 +128,9 @@ target_link_libraries(${PROJECT_NAME}_dev PUBLIC osqp::osqp) # libigl include(eigen) include(libigl) -target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::core igl::triangle igl::tetgen) +target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::core) if(IPC_WITH_OPENGL) - target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::opengl_glfw igl::opengl_glfw_imgui igl::png) + target_link_libraries(${PROJECT_NAME}_dev PUBLIC igl::glfw igl::imgui igl::stb) target_compile_definitions(${PROJECT_NAME}_dev PUBLIC USE_OPENGL) endif() diff --git a/README.md b/README.md index cc948d51f..55ad58e2b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Build status](https://github.com/ipc-sim/IPC/workflows/Build/badge.svg?event=push)](https://github.com/ipc-sim/IPC/actions?query=workflow%3ABuild+branch%3Amaster+event%3Apush) -[![License](https://img.shields.io/github/license/ipc-sim/IPC.svg?color=blue)](https://github.com/ipc-sim/IPC/blob/master/LICENSE) +[![Build status](https://github.com/ipc-sim/IPC/workflows/Build/badge.svg?event=push)](https://github.com/ipc-sim/IPC/actions?query=workflow%3ABuild+branch%3Amain+event%3Apush) +[![License](https://img.shields.io/github/license/ipc-sim/IPC.svg?color=blue)](https://github.com/ipc-sim/IPC/blob/main/LICENSE) # IPC diff --git a/cmake/ipc/ipc_cpm_cache.cmake b/cmake/ipc/ipc_cpm_cache.cmake new file mode 100644 index 000000000..4f9820ba5 --- /dev/null +++ b/cmake/ipc/ipc_cpm_cache.cmake @@ -0,0 +1,25 @@ + +# +# Copyright 2021 Adobe. All rights reserved. +# This file is licensed to you 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 REPRESENTATIONS +# OF ANY KIND, either express or implied. See the License for the specific language +# governing permissions and limitations under the License. +# + +if(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE}) +else() + # Set CPM cache folder if unset + file(REAL_PATH "~/.cache/CPM" CPM_SOURCE_CACHE_DEFAULT EXPAND_TILDE) +endif() + +set(CPM_SOURCE_CACHE + ${CPM_SOURCE_CACHE_DEFAULT} + CACHE PATH "Directory to download CPM dependencies" +) +message(STATUS "Using CPM cache folder: ${CPM_SOURCE_CACHE}") diff --git a/cmake/IPCWarnings.cmake b/cmake/ipc/ipc_warnings.cmake similarity index 100% rename from cmake/IPCWarnings.cmake rename to cmake/ipc/ipc_warnings.cmake diff --git a/cmake/recipes/CPM.cmake b/cmake/recipes/CPM.cmake new file mode 100644 index 000000000..a3086b791 --- /dev/null +++ b/cmake/recipes/CPM.cmake @@ -0,0 +1,33 @@ +set(CPM_DOWNLOAD_VERSION 0.38.1) + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +function(download_cpm) + message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") + file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + ) +endfunction() + +if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + download_cpm() +else() + # resume download if it previously failed + file(READ ${CPM_DOWNLOAD_LOCATION} check) + if("${check}" STREQUAL "") + download_cpm() + endif() + unset(check) +endif() + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/recipes/amgcl.cmake b/cmake/recipes/amgcl.cmake index f281ec9f0..dd7001766 100644 --- a/cmake/recipes/amgcl.cmake +++ b/cmake/recipes/amgcl.cmake @@ -16,14 +16,6 @@ endif() message(STATUS "Third-party: creating target 'amgcl::amgcl'") -include(FetchContent) -FetchContent_Declare( - amgcl - GIT_REPOSITORY https://github.com/ddemidov/amgcl.git - GIT_TAG 1.4.2 - GIT_SHALLOW TRUE -) - function(amgcl_import_target) macro(ignore_package NAME VERSION_NUM) include(CMakePackageConfigHelpers) @@ -40,6 +32,7 @@ function(amgcl_import_target) include(boost) ignore_package(Boost 1.71.0) + set(Boost_ROOT "") set(Boost_INCLUDE_DIRS "") set(Boost_LIBRARIES "") @@ -47,7 +40,12 @@ function(amgcl_import_target) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) # Ready to include third-party lib - FetchContent_MakeAvailable(amgcl) + include(CPM) + CPMAddPackage( + NAME amgcl + GITHUB_REPOSITORY ddemidov/amgcl + GIT_TAG 1.4.2 + ) target_link_libraries(amgcl INTERFACE Boost::boost) endfunction() diff --git a/cmake/recipes/boost.cmake b/cmake/recipes/boost.cmake index 813715273..5c5cd09c9 100644 --- a/cmake/recipes/boost.cmake +++ b/cmake/recipes/boost.cmake @@ -1,5 +1,5 @@ # -# Copyright 2020 Adobe. All rights reserved. +# Copyright 2021 Adobe. All rights reserved. # This file is licensed to you 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 @@ -9,33 +9,58 @@ # OF ANY KIND, either express or implied. See the License for the specific language # governing permissions and limitations under the License. # - if(TARGET Boost::boost) return() endif() message(STATUS "Third-party: creating targets 'Boost::boost'...") -include(FetchContent) -FetchContent_Declare( - boost-cmake - GIT_REPOSITORY https://github.com/Orphis/boost-cmake.git - GIT_TAG 7f97a08b64bd5d2e53e932ddf80c40544cf45edf -) - set(PREVIOUS_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") set(OLD_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# This guy will download boost using FetchContent -FetchContent_GetProperties(boost-cmake) -if(NOT boost-cmake_POPULATED) - FetchContent_Populate(boost-cmake) - # File lcid.cpp from Boost_locale.cpp doesn't compile on MSVC, so we exclude them from the default - # targets being built by the project (only targets explicitly used by other targets will be built). - add_subdirectory(${boost-cmake_SOURCE_DIR} ${boost-cmake_BINARY_DIR} EXCLUDE_FROM_ALL) -endif() +set(BOOST_URL "https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2" CACHE STRING "Boost download URL") +set(BOOST_URL_SHA256 "6478edfe2f3305127cffe8caf73ea0176c53769f4bf1585be237eb30798c3b8e" CACHE STRING "Boost download URL SHA256 checksum") + +include(CPM) +CPMAddPackage( + NAME boost + URL ${BOOST_URL} + URL_HASH SHA256=${BOOST_URL_SHA256} + DOWNLOAD_ONLY ON +) +set(BOOST_SOURCE ${boost_SOURCE_DIR}) +set(Boost_POPULATED ON) + +# Only build the following Boost libs +set(BOOST_LIBS_OPTIONAL "" CACHE STRING "Boost libs to be compiled" FORCE) + +# File lcid.cpp from Boost_locale.cpp doesn't compile on MSVC, so we exclude them from the default +# targets being built by the project (only targets explicitly used by other targets will be built). +CPMAddPackage( + NAME boost-cmake + GITHUB_REPOSITORY Orphis/boost-cmake + GIT_TAG 7f97a08b64bd5d2e53e932ddf80c40544cf45edf + EXCLUDE_FROM_ALL +) set(CMAKE_POSITION_INDEPENDENT_CODE ${OLD_CMAKE_POSITION_INDEPENDENT_CODE}) set(CMAKE_CXX_FLAGS "${PREVIOUS_CMAKE_CXX_FLAGS}") + +foreach(name IN ITEMS + atomic + chrono + container + date_time + filesystem + iostreams + log + system + thread + timer + ) + if(TARGET Boost_${name}) + set_target_properties(Boost_${name} PROPERTIES FOLDER third_party/boost) + endif() +endforeach() diff --git a/cmake/recipes/catch2.cmake b/cmake/recipes/catch2.cmake index e74e07cbc..448e42d7a 100644 --- a/cmake/recipes/catch2.cmake +++ b/cmake/recipes/catch2.cmake @@ -1,25 +1,14 @@ -# -# Copyright 2020 Adobe. All rights reserved. -# This file is licensed to you 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# +# Catch2 (https://github.com/catchorg/Catch2) +# License: BSL-1.0 if(TARGET Catch2::Catch2) return() endif() message(STATUS "Third-party: creating target 'Catch2::Catch2'") -include(FetchContent) -FetchContent_Declare( - catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.6 - GIT_SHALLOW TRUE -) -FetchContent_MakeAvailable(catch2) +option(CATCH_CONFIG_CPP17_STRING_VIEW "Enable support for std::string_view" ON) +option(CATCH_INSTALL_DOCS "Install documentation alongside library" OFF) +option(CATCH_INSTALL_EXTRAS "Install extras alongside library" OFF) + +include(CPM) +CPMAddPackage("gh:catchorg/Catch2@2.13.6") \ No newline at end of file diff --git a/cmake/recipes/ccd_wrapper.cmake b/cmake/recipes/ccd_wrapper.cmake index a821d8669..8fa4e665d 100644 --- a/cmake/recipes/ccd_wrapper.cmake +++ b/cmake/recipes/ccd_wrapper.cmake @@ -12,10 +12,5 @@ set(CCD_WRAPPER_WITH_BSC ${IPC_WITH_EXACT_CCD} CACHE BOOL "Enable Bernstein sign option(CCD_WRAPPER_WITH_TIGHT_INCLUSION "Enable Tight Inclusion method" ON) option(TIGHT_INCLUSION_WITH_NO_ZERO_TOI "Enable refinement if CCD produces a zero ToI" ON) -include(FetchContent) -FetchContent_Declare( - ccd_wrapper - GIT_REPOSITORY https://github.com/Continuous-Collision-Detection/CCD-Wrapper.git - GIT_TAG 23907dadf3e1eef606e38450ada4aa4f96fd9f71 -) -FetchContent_MakeAvailable(ccd_wrapper) +include(CPM) +CPMAddPackage("gh:Continuous-Collision-Detection/CCD-Wrapper#23907dadf3e1eef606e38450ada4aa4f96fd9f71") \ No newline at end of file diff --git a/cmake/recipes/cli11.cmake b/cmake/recipes/cli11.cmake index 0d103c4ca..7745d41f4 100644 --- a/cmake/recipes/cli11.cmake +++ b/cmake/recipes/cli11.cmake @@ -10,19 +10,13 @@ # governing permissions and limitations under the License. # +# CLI11 (https://github.com/CLIUtils/CLI11) # BSD license - if(TARGET CLI11::CLI11) return() endif() message(STATUS "Third-party: creating target 'CLI11::CLI11'") -include(FetchContent) -FetchContent_Declare( - cli11 - GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git - GIT_TAG v2.2.0 - GIT_SHALLOW TRUE -) -FetchContent_MakeAvailable(cli11) +include(CPM) +CPMAddPackage("gh:CLIUtils/CLI11@2.2.0") \ No newline at end of file diff --git a/cmake/recipes/eigen.cmake b/cmake/recipes/eigen.cmake index 30fc11f1f..6bbe8ea0b 100644 --- a/cmake/recipes/eigen.cmake +++ b/cmake/recipes/eigen.cmake @@ -1,64 +1,50 @@ -# -# Copyright 2020 Adobe. All rights reserved. -# This file is licensed to you 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# +# Eigen (https://gitlab.com/libeigen/eigen) +# License: MPL 2.0 if(TARGET Eigen3::Eigen) return() endif() -# option(EIGEN_WITH_MKL "Use Eigen with MKL" OFF) +option(EIGEN_WITH_MKL "Use Eigen with MKL" OFF) +option(EIGEN_DONT_VECTORIZE "Disable Eigen vectorization" OFF) +option(EIGEN_MPL2_ONLY "Enable Eigen MPL2 license only" OFF) -if(EIGEN_ROOT) - message(STATUS "Third-party: creating target 'Eigen3::Eigen' for external path: ${EIGEN_ROOT}") - set(EIGEN_INCLUDE_DIRS ${EIGEN_ROOT}) -else() - message(STATUS "Third-party: creating target 'Eigen3::Eigen'") +message(STATUS "Third-party: creating target 'Eigen3::Eigen'") - include(FetchContent) - FetchContent_Declare( - eigen - GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git - GIT_TAG tags/3.3.7 - GIT_SHALLOW TRUE - ) - FetchContent_GetProperties(eigen) - if(NOT eigen_POPULATED) - FetchContent_Populate(eigen) - endif() - set(EIGEN_INCLUDE_DIRS ${eigen_SOURCE_DIR}) - - install(DIRECTORY ${EIGEN_INCLUDE_DIRS}/Eigen - DESTINATION include - ) -endif() +include(CPM) +CPMAddPackage( + NAME eigen + GITLAB_REPOSITORY libeigen/eigen + GIT_TAG 3.4.0 + DOWNLOAD_ONLY YES +) add_library(Eigen3_Eigen INTERFACE) add_library(Eigen3::Eigen ALIAS Eigen3_Eigen) include(GNUInstallDirs) target_include_directories(Eigen3_Eigen SYSTEM INTERFACE - $ + $ $ ) -# target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_MPL2_ONLY) -# if(EIGEN_WITH_MKL) -# # TODO: Checks that, on 64bits systems, `mkl::mkl` is using the LP64 interface -# # (by looking at the compile definition of the target) -# include(mkl) -# target_link_libraries(Eigen3_Eigen INTERFACE mkl::mkl) -# target_compile_definitions(Eigen3_Eigen INTERFACE -# EIGEN_USE_MKL_ALL -# EIGEN_USE_LAPACKE_STRICT -# ) -# endif() +if(EIGEN_MPL2_ONLY) + target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_MPL2_ONLY) +endif() + +if(EIGEN_DONT_VECTORIZE) + target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_DONT_VECTORIZE) +endif() + +if(EIGEN_WITH_MKL) + # TODO: Checks that, on 64bits systems, `mkl::mkl` is using the LP64 interface + # (by looking at the compile definition of the target) + include(mkl) + target_link_libraries(Eigen3_Eigen INTERFACE mkl::mkl) + target_compile_definitions(Eigen3_Eigen INTERFACE + EIGEN_USE_MKL_ALL + EIGEN_USE_LAPACKE_STRICT + ) +endif() # On Windows, enable natvis files to improve debugging experience if(WIN32 AND eigen_SOURCE_DIR) @@ -68,6 +54,6 @@ endif() # Install rules set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME eigen) set_target_properties(Eigen3_Eigen PROPERTIES EXPORT_NAME Eigen) -install(DIRECTORY ${EIGEN_INCLUDE_DIRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(DIRECTORY ${eigen_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(TARGETS Eigen3_Eigen EXPORT Eigen_Targets) -install(EXPORT Eigen_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eigen NAMESPACE Eigen3::) +install(EXPORT Eigen_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eigen NAMESPACE Eigen3::) \ No newline at end of file diff --git a/cmake/recipes/eigen_gurobi.cmake b/cmake/recipes/eigen_gurobi.cmake index b127d9f3b..f76eeb028 100644 --- a/cmake/recipes/eigen_gurobi.cmake +++ b/cmake/recipes/eigen_gurobi.cmake @@ -5,12 +5,7 @@ endif() message(STATUS "Third-party: creating target 'EigenGurobi::EigenGurobi'") -include(FetchContent) -FetchContent_Declare( - eigen_gurobi - GIT_REPOSITORY https://github.com/zfergus/eigen-gurobi.git - GIT_TAG 51b1aacb3c5733555d09fe362887d618ee97826d -) -FetchContent_MakeAvailable(eigen_gurobi) +include(CPM) +CPMAddPackage("gh:zfergus/eigen-gurobi#51b1aacb3c5733555d09fe362887d618ee97826d") add_library(EigenGurobi::EigenGurobi ALIAS EigenGurobi) diff --git a/cmake/recipes/filesystem.cmake b/cmake/recipes/filesystem.cmake index 632b32298..36f672f42 100644 --- a/cmake/recipes/filesystem.cmake +++ b/cmake/recipes/filesystem.cmake @@ -5,12 +5,7 @@ endif() message(STATUS "Third-party: creating target 'ghc::filesystem'") -include(FetchContent) -FetchContent_Declare( - filesystem - GIT_REPOSITORY https://github.com/gulrak/filesystem.git - GIT_TAG v1.5.10 -) -FetchContent_MakeAvailable(filesystem) +include(CPM) +CPMAddPackage("gh:gulrak/filesystem@1.5.10") -add_library(ghc::filesystem ALIAS ghc_filesystem) +add_library(ghc::filesystem ALIAS ghc_filesystem) \ No newline at end of file diff --git a/cmake/recipes/finite_diff.cmake b/cmake/recipes/finite_diff.cmake index 6c0c93f87..be4ba5455 100644 --- a/cmake/recipes/finite_diff.cmake +++ b/cmake/recipes/finite_diff.cmake @@ -1,14 +1,10 @@ +# finite-diff (https://github.com/zfergus/finite-diff) +# License: MIT if(TARGET finitediff::finitediff) return() endif() message(STATUS "Third-party: creating target 'finitediff::finitediff'") -include(FetchContent) -FetchContent_Declare( - finite-diff - GIT_REPOSITORY https://github.com/zfergus/finite-diff.git - GIT_TAG c5961a6014b725ac00cfc2df9ecba048766e9b46 - GIT_SHALLOW FALSE -) -FetchContent_MakeAvailable(finite-diff) +include(CPM) +CPMAddPackage("gh:zfergus/finite-diff@1.0.1") \ No newline at end of file diff --git a/cmake/recipes/libigl.cmake b/cmake/recipes/libigl.cmake index 5141eb126..4148ef521 100644 --- a/cmake/recipes/libigl.cmake +++ b/cmake/recipes/libigl.cmake @@ -1,72 +1,20 @@ -# -# Copyright 2020 Adobe. All rights reserved. -# This file is licensed to you 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# +# libigl (https://github.com/libigl/libigl) +# License: MPL-2.0 if(TARGET igl::core) return() endif() message(STATUS "Third-party: creating target 'igl::core'") -# libigl -# WARNING: LIBIGL_USE_STATIC_LIBRARY=ON does not work with C++ 17 -option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF) -option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF) -option(LIBIGL_WITH_CGAL "Use CGAL" OFF) -option(LIBIGL_WITH_COMISO "Use CoMiso" OFF) -option(LIBIGL_WITH_CORK "Use Cork" OFF) -option(LIBIGL_WITH_EMBREE "Use Embree" OFF) -option(LIBIGL_WITH_LIM "Use LIM" OFF) -option(LIBIGL_WITH_MATLAB "Use Matlab" OFF) -option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF) -option(LIBIGL_WITH_OPENGL "Use OpenGL" ON) -option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON) -option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON) -option(LIBIGL_WITH_PNG "Use PNG" ON) -option(LIBIGL_WITH_PYTHON "Use Python" OFF) -option(LIBIGL_WITH_TETGEN "Use Tetgen" ON) -option(LIBIGL_WITH_TRIANGLE "Use Triangle" ON) -option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON) -option(LIBIGL_QUIET_VIEWER "Suppress viewer messages" ON) -option(LIBIGL_WITH_XML "Use XML" OFF) -option(LIBIGL_WITH_PREDICATES "Use exact predicates" ON) -set(LIBIGL_WITH_VIEWER ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) -set(LIBIGL_WITH_OPENGL_GLFW_IMGUI ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) -set(LIBIGL_WITH_OPENGL_GLFW ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) -set(LIBIGL_WITH_OPENGL ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) -set(LIBIGL_WITH_PNG ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) - -include(FetchContent) -FetchContent_Declare( - libigl - GIT_REPOSITORY https://github.com/libigl/libigl.git - GIT_TAG v2.3.0 - GIT_SHALLOW TRUE -) -FetchContent_GetProperties(libigl) -if(libigl_POPULATED) - return() -endif() -FetchContent_Populate(libigl) +set(LIBIGL_IMGUI ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) +set(LIBIGL_GLFW ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) +set(LIBIGL_OPENGL ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) +set(LIBIGL_STB ${IPC_WITH_OPENGL} CACHE BOOL "" FORCE) +set(LIBIGL_PREDICATES ON CACHE BOOL "Use exact predicates" FORCE) +set(LIBIGL_COPYLEFT_TETGEN ${IPC_BUILD_MESH_PROCESSING_PROJECT} CACHE BOOL "Use Tetgen" FORCE) include(eigen) -set(LIBIGL_WITH_PREDICATES ON CACHE BOOL "Use exact predicates" FORCE) - -list(APPEND CMAKE_MODULE_PATH ${libigl_SOURCE_DIR}/cmake) -include(${libigl_SOURCE_DIR}/cmake/libigl.cmake ${libigl_BINARY_DIR}) - -# Install rules -set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME libigl) -set_target_properties(igl PROPERTIES EXPORT_NAME core) -install(DIRECTORY ${libigl_SOURCE_DIR}/include/igl DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(TARGETS igl igl_common EXPORT Libigl_Targets) -install(EXPORT Libigl_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/igl NAMESPACE igl::) +include(CPM) +CPMAddPackage("gh:libigl/libigl#36930e5d19bed6c7703ec194fed4fa36df945284") \ No newline at end of file diff --git a/cmake/recipes/mshio.cmake b/cmake/recipes/mshio.cmake index 2d8d6d0da..c4f0974c4 100644 --- a/cmake/recipes/mshio.cmake +++ b/cmake/recipes/mshio.cmake @@ -1,4 +1,4 @@ -# MshIO +# MshIO (https://github.com/qnzhou/MshIO) # License: Apache-2.0 if(TARGET mshio) @@ -8,11 +8,5 @@ endif() message(STATUS "Third-party: creating target 'mshio'") -include(FetchContent) -FetchContent_Declare( - mshio - GIT_REPOSITORY https://github.com/qnzhou/MshIO.git - GIT_TAG a82fb59e25b5e4f586b29ec85a29c3bbc8117307 - GIT_SHALLOW FALSE -) -FetchContent_MakeAvailable(mshio) +include(CPM) +CPMAddPackage("gh:qnzhou/MshIO#29d0263b45bbbb2931ecbe892d0d7f0f3a493d0c") \ No newline at end of file diff --git a/cmake/recipes/onetbb.cmake b/cmake/recipes/onetbb.cmake index b819d7e81..318d6fdc2 100644 --- a/cmake/recipes/onetbb.cmake +++ b/cmake/recipes/onetbb.cmake @@ -1,45 +1,64 @@ -# -# Copyright 2020 Adobe. All rights reserved. -# This file is licensed to you 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# - +# oneTBB (https://github.com/oneapi-src/oneTBB) +# License: Apache-2.0 if(TARGET TBB::tbb) return() endif() -message(STATUS "Third-party: creating targets 'TBB::tbb'") +message(STATUS "Third-party: creating target 'TBB::tbb' (OneTBB)") -include(FetchContent) -FetchContent_Declare( - tbb - GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git - GIT_TAG 1098f48187c718ef782b0aa01861184886906cf4 -) +# Emscripten sets CMAKE_SYSTEM_PROCESSOR to "x86". Change it to "WASM" to prevent TBB from +# adding machine-specific "-mrtm" and "-mwaitpkg" compile options. +if(EMSCRIPTEN) + set(CMAKE_SYSTEM_PROCESSOR "WASM") +endif() option(TBB_TEST "Enable testing" OFF) option(TBB_EXAMPLES "Enable examples" OFF) -option(TBB_STRICT "Treat compiler warnings as errors" ON) +option(TBB_STRICT "Treat compiler warnings as errors" OFF) option(TBB_PREFER_STATIC "Use the static version of TBB for the alias target" ON) unset(TBB_DIR CACHE) -set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) -if(TBB_PREFER_STATIC) - set(BUILD_SHARED_LIBS OFF CACHE STRING "Build shared library" FORCE) -else() - set(BUILD_SHARED_LIBS ON CACHE STRING "Build shared library" FORCE) -endif() +function(onetbb_import_target) + macro(push_variable var value) + if(DEFINED CACHE{${var}}) + set(ONETBB_OLD_${var}_VALUE "${${var}}") + set(ONETBB_OLD_${var}_TYPE CACHE_TYPE) + elseif(DEFINED ${var}) + set(ONETBB_OLD_${var}_VALUE "${${var}}") + set(ONETBB_OLD_${var}_TYPE NORMAL_TYPE) + else() + set(ONETBB_OLD_${var}_TYPE NONE_TYPE) + endif() + set(${var} "${value}" CACHE PATH "" FORCE) + endmacro() + + macro(pop_variable var) + if(ONETBB_OLD_${var}_TYPE STREQUAL CACHE_TYPE) + set(${var} "${ONETBB_OLD_${var}_VALUE}" CACHE PATH "" FORCE) + elseif(ONETBB_OLD_${var}_TYPE STREQUAL NORMAL_TYPE) + unset(${var} CACHE) + set(${var} "${ONETBB_OLD_${var}_VALUE}") + elseif(ONETBB_OLD_${var}_TYPE STREQUAL NONE_TYPE) + unset(${var} CACHE) + else() + message(FATAL_ERROR "Trying to pop a variable that has not been pushed: ${var}") + endif() + endmacro() -set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME tbb) -FetchContent_MakeAvailable(tbb) + if(TBB_PREFER_STATIC) + push_variable(BUILD_SHARED_LIBS OFF) + else() + push_variable(BUILD_SHARED_LIBS ON) + endif() + + set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME tbb) + include(CPM) + CPMAddPackage("gh:oneapi-src/oneTBB@2021.9.0") -set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS} CACHE STRING "Build shared library" FORCE) + pop_variable(BUILD_SHARED_LIBS) +endfunction() + +onetbb_import_target() if(NOT TARGET TBB::tbb) message(FATAL_ERROR "TBB::tbb is still not defined!") @@ -56,5 +75,16 @@ foreach(name IN ITEMS tbb tbbmalloc tbbmalloc_proxy) # Without this macro, TBB will explicitly link against "tbb12_debug.lib" in Debug configs. # This is undesirable, since our pre-compiled version of MKL is linked against "tbb12.dll". target_compile_definitions(${name} PUBLIC -D__TBB_NO_IMPLICIT_LINKAGE=1) + + # Disable some features and avoid processor-specific code paths when compiling with + # Emscripten for WebAssembly. + if(EMSCRIPTEN) + target_compile_definitions(${name} PRIVATE + ITT_ARCH=-1 + __TBB_RESUMABLE_TASKS_USE_THREADS=1 + __TBB_DYNAMIC_LOAD_ENABLED=0 + __TBB_WEAK_SYMBOLS_PRESENT=0 + ) + endif() endif() endforeach() diff --git a/cmake/recipes/osqp.cmake b/cmake/recipes/osqp.cmake index 3881d6b21..14213c16c 100644 --- a/cmake/recipes/osqp.cmake +++ b/cmake/recipes/osqp.cmake @@ -10,14 +10,8 @@ message(STATUS "Third-party: creating target 'osqp::osqp'") set(DFLOAT OFF CACHE BOOL "Use float numbers instead of doubles" FORCE) set(DLONG OFF CACHE BOOL "Use long integers (64bit) for indexing" FORCE) -include(FetchContent) -FetchContent_Declare( - osqp - GIT_REPOSITORY https://github.com/oxfordcontrol/osqp.git - GIT_TAG v0.4.1 - GIT_SHALLOW TRUE -) -FetchContent_MakeAvailable(osqp) +include(CPM) +CPMAddPackage("gh:oxfordcontrol/osqp@0.4.1") if(UNIX AND NOT APPLE) set_target_properties(osqpstatic PROPERTIES INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) diff --git a/cmake/recipes/spdlog.cmake b/cmake/recipes/spdlog.cmake index 1056fb800..352677b98 100644 --- a/cmake/recipes/spdlog.cmake +++ b/cmake/recipes/spdlog.cmake @@ -1,30 +1,16 @@ -# -# Copyright 2020 Adobe. All rights reserved. -# This file is licensed to you 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# +# spdlog (https://github.com/gabime/spdlog) +# License: MIT if(TARGET spdlog::spdlog) return() endif() message(STATUS "Third-party: creating target 'spdlog::spdlog'") -include(FetchContent) -FetchContent_Declare( - spdlog - URL https://github.com/gabime/spdlog/archive/refs/tags/v1.9.2.zip - URL_HASH MD5=a3d2fb9e5c811ba100380aa82d48f989 -) - option(SPDLOG_INSTALL "Generate the install target" ON) set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "spdlog") -FetchContent_MakeAvailable(spdlog) + +include(CPM) +CPMAddPackage("gh:gabime/spdlog@1.9.2") set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/cmake/recipes/tbb.cmake b/cmake/recipes/tbb.cmake deleted file mode 100644 index abc498cb8..000000000 --- a/cmake/recipes/tbb.cmake +++ /dev/null @@ -1,136 +0,0 @@ -# -# Copyright 2020 Adobe. All rights reserved. -# This file is licensed to you 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 REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# - -#################################################################################################### -# IMPORTANT -# -# This file defines a single ALIAS target `TBB::tbb`. -# -# Depending on the option TBB_PREFER_STATIC, this alias may point to either the dynamic version -# of TBB, or the static version. The official recommendation is to use the dynamic library: -# -# https://www.threadingbuildingblocks.org/faq/there-version-tbb-provides-statically-linked-libraries -# https://stackoverflow.com/questions/638278/how-to-statically-link-to-tbb -# -# For now we do not have a proper CMake workflow to deal with DLLs, so we default to tbb_static -#################################################################################################### - -if(TARGET TBB::tbb) - return() -endif() - -message(STATUS "Third-party: creating target 'TBB::tbb'") - -# Using wjakob's fork as it has a better cmake build system -# Change it back to intel's once they fix it -# https://github.com/intel/tbb/issues/6 -include(FetchContent) -FetchContent_Declare( - tbb - GIT_REPOSITORY https://github.com/wjakob/tbb.git - GIT_TAG 141b0e310e1fb552bdca887542c9c1a8544d6503 - GIT_SHALLOW FALSE -) - -option(TBB_PREFER_STATIC "Use the static version of TBB for the alias target" ON) -option(TBB_BUILD_SHARED "Build TBB shared library" OFF) -option(TBB_BUILD_STATIC "Build TBB static library" OFF) -option(TBB_BUILD_TBBMALLOC "Build TBB malloc library" ON) -option(TBB_BUILD_TBBMALLOC_PROXY "Build TBB malloc proxy library" OFF) -option(TBB_BUILD_TESTS "Build TBB tests and enable testing infrastructure" OFF) -option(TBB_NO_DATE "Do not save the configure date in the version string" ON) - -# Mark those options as advanced so they don't show up in CMake GUI -# Please use TBB_PREFER_STATIC instead -mark_as_advanced(TBB_BUILD_SHARED TBB_BUILD_STATIC) - -# Make sure tbb or tbb_static is built, according to the user's option -if(TBB_PREFER_STATIC) - set(TBB_BUILD_STATIC ON CACHE BOOL "Build TBB static library" FORCE) - set(TBB_BUILD_SHARED OFF CACHE BOOL "Build TBB shared library" FORCE) -else() - set(TBB_BUILD_SHARED ON CACHE BOOL "Build TBB shared library" FORCE) - set(TBB_BUILD_STATIC OFF CACHE BOOL "Build TBB static library" FORCE) -endif() - -set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME TBB) -FetchContent_MakeAvailable(tbb) - -# Install rules for the tbb_static target (not defined by upstream CMakeLists.txt) -if(TBB_INSTALL_TARGETS AND TBB_BUILD_STATIC) - if(NOT TBB_INSTALL_RUNTIME_DIR) - set(TBB_INSTALL_RUNTIME_DIR bin) - endif() - if(NOT TBB_INSTALL_LIBRARY_DIR) - set(TBB_INSTALL_LIBRARY_DIR lib) - endif() - if(NOT TBB_INSTALL_ARCHIVE_DIR) - set(TBB_INSTALL_ARCHIVE_DIR lib) - endif() - if(NOT TBB_INSTALL_INCLUDE_DIR) - set(TBB_INSTALL_INCLUDE_DIR include) - endif() - if(NOT TBB_CMAKE_PACKAGE_INSTALL_DIR) - set(TBB_CMAKE_PACKAGE_INSTALL_DIR lib/cmake/tbb) - endif() - if(TARGET tbb_interface) - install(TARGETS tbb_interface EXPORT TBB) - endif() - if(TARGET tbb_static) - install(TARGETS tbb_static EXPORT TBB - LIBRARY DESTINATION ${TBB_INSTALL_LIBRARY_DIR} - ARCHIVE DESTINATION ${TBB_INSTALL_ARCHIVE_DIR} - RUNTIME DESTINATION ${TBB_INSTALL_RUNTIME_DIR}) - endif() - if(TARGET tbbmalloc_static) - install(TARGETS tbbmalloc_static EXPORT TBB - LIBRARY DESTINATION ${TBB_INSTALL_LIBRARY_DIR} - ARCHIVE DESTINATION ${TBB_INSTALL_ARCHIVE_DIR} - RUNTIME DESTINATION ${TBB_INSTALL_RUNTIME_DIR}) - endif() - install(EXPORT TBB DESTINATION ${TBB_CMAKE_PACKAGE_INSTALL_DIR} NAMESPACE TBB:: FILE TBBConfig.cmake) -endif() - -# Fix include directories to not explicitly reference the build directory, otherwise install() will complain -function(tbb_fix_include_dirs) - foreach(name IN ITEMS ${ARGN}) - if(NOT TARGET ${name}) - message(FATAL_ERROR "'${name}' is not a CMake target") - endif() - get_target_property(__include_dirs ${name} INTERFACE_INCLUDE_DIRECTORIES) - set_property(TARGET ${name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES - $ - $ - ) - endforeach() -endfunction() - -# Meta-target that brings both tbb and tbbmalloc -add_library(tbb_tbb INTERFACE) -add_library(TBB::tbb ALIAS tbb_tbb) -if(TBB_PREFER_STATIC) - target_link_libraries(tbb_tbb INTERFACE tbb_static tbbmalloc_static) - tbb_fix_include_dirs(tbb_static) -else() - target_link_libraries(tbb_tbb INTERFACE tbb tbbmalloc) - tbb_fix_include_dirs(tbb) -endif() - -# Install rules -install(TARGETS tbb_tbb EXPORT TBB) - -# Set -fPIC flag and IDE folder name for tbb targets -foreach(name IN ITEMS tbb_def_files tbb_static tbb tbbmalloc tbbmalloc_static) - if(TARGET ${name}) - set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE ON) - endif() -endforeach() diff --git a/src/Mesh.cpp b/src/Mesh.cpp index cb0b81685..d8d68e7c6 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -11,7 +11,6 @@ #include "Timer.hpp" #include "CCDUtils.hpp" -#include #include #include #include @@ -204,7 +203,7 @@ void Mesh::computeMassMatrix(const igl::MassMatrixType type) cosines.col(1) = (l.col(0).array().pow(2) + l.col(2).array().pow(2) - l.col(1).array().pow(2)) / (l.col(2).array() * l.col(0).array() * 2.0); cosines.col(2) = (l.col(1).array().pow(2) + l.col(0).array().pow(2) - l.col(2).array().pow(2)) / (l.col(0).array() * l.col(1).array() * 2.0); Matrix barycentric = cosines.array() * l.array(); - normalize_row_sums(barycentric, barycentric); + barycentric = (barycentric.array().colwise() / barycentric.array().rowwise().sum()).eval(); Matrix partial = barycentric; partial.col(0).array() *= dblA.array() * 0.5; partial.col(1).array() *= dblA.array() * 0.5; @@ -354,7 +353,7 @@ void Mesh::computeMassMatrix(const igl::MassMatrixType type) cosines.col(1) = (l.col(0).array().pow(2) + l.col(2).array().pow(2) - l.col(1).array().pow(2)) / (l.col(2).array() * l.col(0).array() * 2.0); cosines.col(2) = (l.col(1).array().pow(2) + l.col(0).array().pow(2) - l.col(2).array().pow(2)) / (l.col(0).array() * l.col(1).array() * 2.0); Matrix barycentric = cosines.array() * l.array(); - normalize_row_sums(barycentric, barycentric); + barycentric = (barycentric.array().colwise() / barycentric.array().rowwise().sum()).eval(); Matrix partial = barycentric; partial.col(0).array() *= dblA.array() * 0.5; partial.col(1).array() *= dblA.array() * 0.5; diff --git a/src/Projects/CMakeLists.txt b/src/Projects/CMakeLists.txt index 73bcdcac0..552c53375 100644 --- a/src/Projects/CMakeLists.txt +++ b/src/Projects/CMakeLists.txt @@ -1,14 +1,9 @@ cmake_minimum_required(VERSION 3.9) -######################################################################################################## -# project-options -option(IPC_BUILD_DIAGNOSTIC_PROJECT "Build the Diagnostic sub-project" ${IPC_TOPLEVEL_PROJECT}) -option(IPC_BUILD_MESH_PROCESSING_PROJECT "Build the MeshProcessing sub-project" ${IPC_TOPLEVEL_PROJECT}) -######################################################################################################## - if(IPC_BUILD_DIAGNOSTIC_PROJECT) add_subdirectory(Diagnostic) endif() + if(IPC_BUILD_MESH_PROCESSING_PROJECT) add_subdirectory(MeshProcessing) endif() diff --git a/src/Projects/Diagnostic/CMakeLists.txt b/src/Projects/Diagnostic/CMakeLists.txt index 493c34074..8af09f048 100644 --- a/src/Projects/Diagnostic/CMakeLists.txt +++ b/src/Projects/Diagnostic/CMakeLists.txt @@ -19,7 +19,7 @@ endif() target_link_libraries(diagnostic PUBLIC osqp::osqp) # libigl -target_link_libraries(diagnostic PUBLIC igl::core igl::triangle igl::tetgen) +target_link_libraries(diagnostic PUBLIC igl::core) # tbb target_link_libraries(diagnostic PUBLIC TBB::tbb) diff --git a/src/Projects/Diagnostic/Diagnostic.cpp b/src/Projects/Diagnostic/Diagnostic.cpp index 2bad61eac..01f5cf5da 100644 --- a/src/Projects/Diagnostic/Diagnostic.cpp +++ b/src/Projects/Diagnostic/Diagnostic.cpp @@ -47,7 +47,6 @@ std::string outputFolderPath = "output/"; #include #include #include -#include #include diff --git a/src/Projects/MeshProcessing/CMakeLists.txt b/src/Projects/MeshProcessing/CMakeLists.txt index 36916a180..bea9e1a85 100644 --- a/src/Projects/MeshProcessing/CMakeLists.txt +++ b/src/Projects/MeshProcessing/CMakeLists.txt @@ -11,7 +11,7 @@ set_target_properties(meshprocessing PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE target_link_libraries(meshprocessing PUBLIC ${PROJECT_NAME}_dev) # libigl -target_link_libraries(meshprocessing PUBLIC igl::core igl::triangle igl::tetgen) +target_link_libraries(meshprocessing PUBLIC igl::core igl_copyleft::tetgen) # tbb target_link_libraries(meshprocessing PUBLIC TBB::tbb) diff --git a/src/Projects/MeshProcessing/MeshProcessing.cpp b/src/Projects/MeshProcessing/MeshProcessing.cpp index 70b97fe61..7d863ff72 100644 --- a/src/Projects/MeshProcessing/MeshProcessing.cpp +++ b/src/Projects/MeshProcessing/MeshProcessing.cpp @@ -22,8 +22,6 @@ #include #endif -#include - #include std::string outputFolderPath = "output/"; diff --git a/src/Utils/SVD/Tools.h b/src/Utils/SVD/Tools.h index c0acd083c..7734d8cfe 100644 --- a/src/Utils/SVD/Tools.h +++ b/src/Utils/SVD/Tools.h @@ -52,8 +52,10 @@ Sample usage: #include #pragma GCC diagnostic pop +#if !defined(__APPLE__) || defined(__i386__) || defined(__x86_64__) #include #include +#endif #include #include #include @@ -112,7 +114,12 @@ The relative error is less than 1.5*2^-12 */ inline float approx_rsqrt(float a) { + // return 1.0f / std::sqrt(a); +#if !defined(__APPLE__) || defined(__i386__) || defined(__x86_64__) return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(a))); +#else + return vgetq_lane_f32(vrsqrteq_f32(vld1q_dup_f32(&a)), 0); +#endif } /** @@ -150,15 +157,15 @@ class Timer { ~Timer() {} /** - \brief Start timing - */ + \brief Start timing + */ void start() { start_time = std::chrono::steady_clock::now(); } /** - \return time elapsed since last click in seconds + \return time elapsed since last click in seconds */ double click() { diff --git a/src/Utils/Triplet.hpp b/src/Utils/Triplet.hpp index ba2938d91..792ff2c1b 100644 --- a/src/Utils/Triplet.hpp +++ b/src/Utils/Triplet.hpp @@ -11,6 +11,7 @@ #include #include +#include #include diff --git a/src/main.cpp b/src/main.cpp index 8b8021217..1fbba6f4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ #include #ifdef USE_OPENGL #include -#include +#include #endif #include @@ -384,7 +384,7 @@ void saveScreenshot(const std::string& filePath, double scale, bool writeGIF, bo if (writePNG) { // Save it to a PNG - igl::png::writePNG(R, G, B, A, filePath); + igl::stb::write_image(filePath, R, G, B, A); } if (writeGIF && (iterNum % GIFStep == 0)) {