Skip to content

Commit

Permalink
Switch to CPM with cache (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Ferguson authored Jun 29, 2023
1 parent 07e66e3 commit e5dda8c
Show file tree
Hide file tree
Showing 44 changed files with 417 additions and 410 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
cd build
cmake .. \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DIPC_TOOLKIT_BUILD_UNIT_TESTS=ON \
-DIPC_TOOLKIT_BUILD_TESTS=ON \
-DCMAKE_BUILD_TYPE=${{ matrix.config }}
- name: Build
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
cmake -G Ninja ^
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache ^
-DCMAKE_BUILD_TYPE=${{ matrix.config }} ^
-DIPC_TOOLKIT_BUILD_UNIT_TESTS=ON ^
-DIPC_TOOLKIT_BUILD_TESTS=ON ^
-B build ^
-S .
cmake --build build -j1
Expand Down
87 changes: 56 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ else()
endif()

# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.14.0")
set(REQUIRED_CMAKE_VERSION "3.18.0")
if(IPC_TOOLKIT_TOPLEVEL_PROJECT)
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
else()
Expand All @@ -24,19 +24,52 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/IPCToolkitOptions.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/IPCToolkitOptions.cmake)
endif()

# Enable ccache if available
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
option(IPC_TOOLKIT_WITH_CCACHE "Enable ccache when building IPC Toolkit" ${IPC_TOOLKIT_TOPLEVEL_PROJECT})
else()
option(IPC_TOOLKIT_WITH_CCACHE "Enable ccache when building IPC Toolkit" OFF)
endif()
if(IPC_TOOLKIT_WITH_CCACHE AND CCACHE_PROGRAM)
message(STATUS "Enabling Ccache support")
set(ccacheEnv
CCACHE_BASEDIR=${CMAKE_BINARY_DIR}
CCACHE_SLOPPINESS=clang_index_store,include_file_ctime,include_file_mtime,locale,pch_defines,time_macros
)
foreach(lang IN ITEMS C CXX)
set(CMAKE_${lang}_COMPILER_LAUNCHER
${CMAKE_COMMAND} -E env ${ccacheEnv} ${CCACHE_PROGRAM}
)
endforeach()
endif()


################################################################################
# CMake Policies
################################################################################

cmake_policy(SET CMP0054 NEW) # Only interpret if() arguments as variables or keywords when unquoted.
cmake_policy(SET CMP0076 NEW) # target_sources() command converts relative paths to absolute.
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW) # Set the timestamps of all extracted contents to the time of the extraction.
endif()

################################################################################

project(IPCToolkit
DESCRIPTION "A set of reusable functions to integrate IPC into an existing simulation."
LANGUAGES CXX
VERSION "1.0.0")
VERSION "1.0.1")

option(IPC_TOOLKIT_BUILD_TESTS "Build unit-tests" ${IPC_TOOLKIT_TOPLEVEL_PROJECT})
option(IPC_TOOLKIT_BUILD_PYTHON "Build Python bindings" OFF)
option(IPC_TOOLKIT_WITH_CORRECT_CCD "Use the TightInclusion CCD" ON)
option(IPC_TOOLKIT_WITH_SIMD "Enable SIMD" OFF)
option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" OFF)
option(IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION "Use rational edge-triangle intersection check" OFF)
option(IPC_TOOLKIT_WITH_ROBIN_MAP "Use Tessil's robin-map rather than std maps" ON)
option(IPC_TOOLKIT_WITH_ABSEIL "Use Abseil's hash functions" ON)

# Set default minimum C++ standard
if(IPC_TOOLKIT_TOPLEVEL_PROJECT)
Expand All @@ -53,25 +86,13 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/ipc_toolkit/")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/find/")

# Color output
# General CMake utils
include(ipc_toolkit_cpm_cache)
include(ipc_toolkit_use_colors)

# IPC Toolkit utils
include(ipc_toolkit_prepend_current_path)
include(ipc_toolkit_set_source_group)
include(ipc_toolkit_target_link_system_libraries)

# Generate position independent code by default
# Generate position-independent code by default
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

################################################################################
# CMake Policies
################################################################################

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24")
cmake_policy(SET CMP0135 NEW) # https://cmake.org/cmake/help/latest/policy/CMP0135.html
endif()

################################################################################
# IPC Toolkit Library
################################################################################
Expand Down Expand Up @@ -105,54 +126,58 @@ target_compile_definitions(ipc_toolkit PUBLIC NOMINMAX)
# libigl
include(eigen)
include(libigl)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC
target_link_libraries(ipc_toolkit PUBLIC
Eigen3::Eigen
igl::core
igl::predicates
)

# TBB
include(onetbb)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC TBB::tbb)
target_link_libraries(ipc_toolkit PUBLIC TBB::tbb)

# CCD
if(IPC_TOOLKIT_WITH_CORRECT_CCD)
# Provably conservative CCD of [Wang and Ferguson et al. 2021]
include(tight_inclusion)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC tight_inclusion::tight_inclusion)
target_link_libraries(ipc_toolkit PUBLIC tight_inclusion::tight_inclusion)
else()
# Etienne Vouga's CTCD Library for the floating point root finding algorithm
include(evouga_ccd)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC evouga::ccd)
target_link_libraries(ipc_toolkit PUBLIC evouga::ccd)
endif()

# Logger
include(spdlog)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC spdlog::spdlog)
target_link_libraries(ipc_toolkit PUBLIC spdlog::spdlog)

if(IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION)
include(gmp)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC GMP::GMP)
target_link_libraries(ipc_toolkit PUBLIC GMP::GMP)
endif()

# Sweep and Tiniest Queue and CCD
if(IPC_TOOLKIT_WITH_CUDA)
include(gpu_ccd)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC gpu_ccd::gpu_ccd)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC STQ::CPU)
target_link_libraries(ipc_toolkit PUBLIC gpu_ccd::gpu_ccd)
target_link_libraries(ipc_toolkit PUBLIC STQ::CPU)
else()
set(STQ_WITH_CUDA OFF CACHE BOOL "Enable CUDA Implementation" FORCE)
include(sweep_and_tiniest_queue)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC STQ::CPU)
target_link_libraries(ipc_toolkit PUBLIC STQ::CPU)
endif()

# Faster unordered map
include(robin_map)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC tsl::robin_map)
if(IPC_TOOLKIT_WITH_ROBIN_MAP)
include(robin_map)
target_link_libraries(ipc_toolkit PUBLIC tsl::robin_map)
endif()

# Hashes
include(abseil)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PUBLIC absl::hash)
if(IPC_TOOLKIT_WITH_ABSEIL)
include(abseil)
target_link_libraries(ipc_toolkit PUBLIC absl::hash)
endif()

# Extra warnings (link last for highest priority)
include(ipc_toolkit_warnings)
Expand Down Expand Up @@ -221,7 +246,7 @@ if(IPC_TOOLKIT_WITH_CUDA)
endif()

find_package(CUDAToolkit)
ipc_toolkit_target_link_system_libraries(ipc_toolkit PRIVATE CUDA::cudart)
target_link_libraries(ipc_toolkit PRIVATE CUDA::cudart)
endif()

################################################################################
Expand Down
44 changes: 1 addition & 43 deletions IPCToolkitOptions.cmake.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
# Generates a `compile_commands.json` that can be used for autocompletion
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Enable/Disable output of compile commands during generation.")

# Use ccache to speed up compilation of repeated builds
# find_program(CCACHE_PROGRAM ccache)
# if(CCACHE_PROGRAM)
# message(STATUS "Enabling Ccache support")
# set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE STRING "")
# set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE STRING "")
# endif()

# Use a specific C/C++ compiler, e.g. llvm-clang on macOS (so we can use clangd)
# set(CMAKE_C_COMPILER "/usr/local/opt/llvm/bin/clang" CACHE STRING "C compiler")
# set(CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++" CACHE STRING "C++ compiler")
Expand All @@ -32,10 +24,6 @@
# Set deployment platform for macOS
# set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12 CACHE STRING "macOS deployment target")

# Always add colored output (e.g. when using Ninja)
# list(APPEND CMAKE_CXX_FLAGS -fdiagnostics-color=always) # GCC
# list(APPEND CMAKE_CXX_FLAGS -fcolor-diagnostics) # Clang

################################################################################
# IPC Toolkit Options
################################################################################
Expand All @@ -46,34 +34,4 @@
# option(IPC_TOOLKIT_WITH_SIMD "Enable SIMD" OFF)
# option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" OFF)
# option(IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION "Use rational edge-triangle intersection check" OFF)

# Options for third-party libraries
# option(EIGEN_WITH_MKL "Use Eigen with MKL" ON)
# set(MKL_INTERFACE "lp64" CACHE STRING "Interface layer to use with MKL (lp64 or ilp64)")
# set(MKL_LINKING "static" CACHE STRING "Linking strategy to use with MKL (static, dynamic or sdl)")
# set(MKL_THREADING "tbb" CACHE STRING "Threading layer to use with MKL (sequential, tbb or openmp)")

################################################################################
# FetchContent Options
################################################################################

# option(FETCHCONTENT_FULLY_DISCONNECTED "Disables all attempts to download or update content and assumes source dirs already exist" OFF)
# option(FETCHCONTENT_UPDATES_DISCONNECTED "Enables UPDATE_DISCONNECTED behavior for all content population" OFF)
# option(FETCHCONTENT_QUIET "Enables QUIET option for all content population" ON)
# set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/_deps" CACHE PATH "Directory under which to collect all populated content")

# Development Locations for Third Party Libraries
# set(FETCHCONTENT_SOURCE_DIR_ABSEIL "" CACHE PATH "When not empty, overrides where to find pre-populated content for abseil")
# set(FETCHCONTENT_SOURCE_DIR_BROADPHASE "" CACHE PATH "When not empty, overrides where to find pre-populated content for broadphase")
# set(FETCHCONTENT_SOURCE_DIR_CATCH2 "" CACHE PATH "When not empty, overrides where to find pre-populated content for catch2")
# set(FETCHCONTENT_SOURCE_DIR_EIGEN "" CACHE PATH "When not empty, overrides where to find pre-populated content for eigen")
# set(FETCHCONTENT_SOURCE_DIR_FINITE-DIFF "" CACHE PATH "When not empty, overrides where to find pre-populated content for finite-diff")
# set(FETCHCONTENT_SOURCE_DIR_GPU_CCD "" CACHE PATH "When not empty, overrides where to find pre-populated content for gpu_ccd")
# set(FETCHCONTENT_SOURCE_DIR_LIBIGL "" CACHE PATH "When not empty, overrides where to find pre-populated content for libigl")
# set(FETCHCONTENT_SOURCE_DIR_NLOHMANN_JSON "" CACHE PATH "When not empty, overrides where to find pre-populated content for nlohmann_json")
# set(FETCHCONTENT_SOURCE_DIR_PREDICATES "" CACHE PATH "When not empty, overrides where to find pre-populated content for predicates")
# set(FETCHCONTENT_SOURCE_DIR_PYBIND11 "" CACHE PATH "When not empty, overrides where to find pre-populated content for pybind11")
# set(FETCHCONTENT_SOURCE_DIR_ROBIN-MAP "" CACHE PATH "When not empty, overrides where to find pre-populated content for robin-map")
# set(FETCHCONTENT_SOURCE_DIR_SPDLOG "" CACHE PATH "When not empty, overrides where to find pre-populated content for spdlog")
# set(FETCHCONTENT_SOURCE_DIR_TBB "" CACHE PATH "When not empty, overrides where to find pre-populated content for tbb")
# set(FETCHCONTENT_SOURCE_DIR_TIGHT_INCLUSION "" CACHE PATH "When not empty, overrides where to find pre-populated content for tight_inclusion")
# option(IPC_TOOLKIT_WITH_ROBIN_MAP "Use Tessil's robin-map rather than std maps" ON)
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ The following libraries are used in this project:
* [TBB](https://github.com/wjakob/tbb): parallelization
* [Tight-Inclusion](https://github.com/Continuous-Collision-Detection/Tight-Inclusion): correct (conservative) CCD
* [spdlog](https://github.com/gabime/spdlog): logging information
* [robin-map](https://github.com/Tessil/robin-map): faster hash set/map than `std::unordered_set`/`std::unordered_map`
* [Abseil](https://abseil.io/): hashing utilities

#### Optional

* [robin-map](https://github.com/Tessil/robin-map): faster hash set/map than `std::unordered_set`/`std::unordered_map`
* Enable by using the CMake option `IPC_TOOLKIT_WITH_ROBIN_MAP`
* Enabled by default
* [Abseil](https://abseil.io/): hashing utilities
* Enable by using the CMake option `IPC_TOOLKIT_WITH_ABSEIL`
* Enabled by default
* [GMP](https://gmplib.org/): rational arithmetic used for exact intersection checks
* Enable by using the CMake option `IPC_TOOLKIT_WITH_RATIONAL_INTERSECTION`
* GMP must be installed at a system level
Expand Down
24 changes: 24 additions & 0 deletions cmake/ipc_toolkit/ipc_toolkit_cpm_cache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# 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}")
25 changes: 25 additions & 0 deletions cmake/ipc_toolkit/ipc_toolkit_filter_flags.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.
#
function(ipc_toolkit_filter_flags flags)
include(CheckCXXCompilerFlag)
set(output_flags)
foreach(FLAG IN ITEMS ${${flags}})
string(REPLACE "=" "-" FLAG_VAR "${FLAG}")
if(NOT DEFINED IS_SUPPORTED_${FLAG_VAR})
check_cxx_compiler_flag("${FLAG}" IS_SUPPORTED_${FLAG_VAR})
endif()
if(IS_SUPPORTED_${FLAG_VAR})
list(APPEND output_flags $<$<COMPILE_LANGUAGE:CXX>:${FLAG}>)
endif()
endforeach()
set(${flags} ${output_flags} PARENT_SCOPE)
endfunction()
8 changes: 0 additions & 8 deletions cmake/ipc_toolkit/ipc_toolkit_prepend_current_path.cmake

This file was deleted.

8 changes: 0 additions & 8 deletions cmake/ipc_toolkit/ipc_toolkit_set_source_group.cmake

This file was deleted.

29 changes: 0 additions & 29 deletions cmake/ipc_toolkit/ipc_toolkit_target_link_system_libraries.cmake

This file was deleted.

Loading

0 comments on commit e5dda8c

Please sign in to comment.