Skip to content

Commit

Permalink
Apple Silicon Support (#39)
Browse files Browse the repository at this point in the history
* Move CMake dependencies to CPM and add alternative to SSE instructions

* Add <array> header to Triplet.hpp

* Update libigl

* Move project CMake option

* Update CI

* Fix CI Ccache path

* Fix debug build
  • Loading branch information
zfergus authored Mar 29, 2024
1 parent 71ec1da commit efacf99
Show file tree
Hide file tree
Showing 31 changed files with 285 additions and 438 deletions.
3 changes: 0 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
workflow_dispatch:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

env:
CTEST_OUTPUT_ON_FAILURE: ON
Expand All @@ -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: |
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
################################################################################
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
25 changes: 25 additions & 0 deletions cmake/ipc/ipc_cpm_cache.cmake
Original file line number Diff line number Diff line change
@@ -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}")
File renamed without changes.
33 changes: 33 additions & 0 deletions cmake/recipes/CPM.cmake
Original file line number Diff line number Diff line change
@@ -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})
16 changes: 7 additions & 9 deletions cmake/recipes/amgcl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,14 +32,20 @@ function(amgcl_import_target)
include(boost)

ignore_package(Boost 1.71.0)
set(Boost_ROOT "")
set(Boost_INCLUDE_DIRS "")
set(Boost_LIBRARIES "")

# Prefer Config mode before Module mode to prevent lib from loading its own FindXXX.cmake
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()
Expand Down
59 changes: 42 additions & 17 deletions cmake/recipes/boost.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
27 changes: 8 additions & 19 deletions cmake/recipes/catch2.cmake
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 2 additions & 7 deletions cmake/recipes/ccd_wrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
12 changes: 3 additions & 9 deletions cmake/recipes/cli11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading

0 comments on commit efacf99

Please sign in to comment.