Skip to content

Commit

Permalink
Move CMake dependencies to CPM and add alternative to SSE instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Ferguson committed Mar 29, 2024
1 parent 71ec1da commit 6ce8f0f
Show file tree
Hide file tree
Showing 21 changed files with 246 additions and 343 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
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ option(IPC_WITH_TESTS "Build unit tests using Catch2" ${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 +101,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 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/[email protected]")
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/[email protected]")
82 changes: 34 additions & 48 deletions cmake/recipes/eigen.cmake
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${eigen_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# 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)
Expand All @@ -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::)
Loading

0 comments on commit 6ce8f0f

Please sign in to comment.