Skip to content

Commit 70c1341

Browse files
committed
Switch to CPM
1 parent d77d82c commit 70c1341

File tree

13 files changed

+192
-142
lines changed

13 files changed

+192
-142
lines changed

CMakeLists.txt

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ else()
77
endif()
88

99
# Check required CMake version
10-
set(REQUIRED_CMAKE_VERSION "3.14.0")
10+
set(REQUIRED_CMAKE_VERSION "3.18.0")
1111
if(SIMPLE_BVH_TOPLEVEL_PROJECT)
1212
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
1313
else()
@@ -24,13 +24,33 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/SimpleBVHOptions.cmake)
2424
include(${CMAKE_CURRENT_SOURCE_DIR}/SimpleBVHOptions.cmake)
2525
endif()
2626

27+
# Enable ccache if available
28+
find_program(CCACHE_PROGRAM ccache)
29+
if(CCACHE_PROGRAM)
30+
option(SIMPLE_BVH_WITH_CCACHE "Enable ccache when building IPC Toolkit" ${SIMPLE_BVH_TOPLEVEL_PROJECT})
31+
else()
32+
option(SIMPLE_BVH_WITH_CCACHE "Enable ccache when building IPC Toolkit" OFF)
33+
endif()
34+
if(SIMPLE_BVH_WITH_CCACHE AND CCACHE_PROGRAM)
35+
message(STATUS "Enabling Ccache support (${CCACHE_PROGRAM})")
36+
set(ccacheEnv
37+
CCACHE_BASEDIR=${CMAKE_BINARY_DIR}
38+
CCACHE_SLOPPINESS=clang_index_store,include_file_ctime,include_file_mtime,locale,pch_defines,time_macros
39+
)
40+
foreach(lang IN ITEMS C CXX)
41+
set(CMAKE_${lang}_COMPILER_LAUNCHER
42+
${CMAKE_COMMAND} -E env ${ccacheEnv} ${CCACHE_PROGRAM}
43+
)
44+
endforeach()
45+
endif()
46+
2747
################################################################################
2848

2949
project(SimpleBVH
3050
DESCRIPTION "A simple BVH data structure."
3151
LANGUAGES CXX)
3252

33-
option(SIMPLE_BVH_WITH_UNIT_TESTS "Build unit-tests" ${SIMPLE_BVH_TOPLEVEL_PROJECT})
53+
option(SIMPLE_BVH_BUILD_TESTS "Build unit-tests" ${SIMPLE_BVH_TOPLEVEL_PROJECT})
3454

3555
# Set default minimum C++ standard
3656
if(SIMPLE_BVH_TOPLEVEL_PROJECT)
@@ -42,13 +62,16 @@ endif()
4262
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/simple_bvh/")
4363
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")
4464

65+
# General CMake utils
66+
include(simple_bvh_cpm_cache)
67+
4568
################################################################################
4669
# Main library
4770
################################################################################
4871

4972
add_library(simple_bvh
50-
src/BVH.cpp
51-
src/Morton.cpp
73+
src/SimpleBVH/BVH.cpp
74+
src/SimpleBVH/Morton.cpp
5275
)
5376
target_include_directories(simple_bvh PUBLIC src)
5477
add_library(simple_bvh::simple_bvh ALIAS simple_bvh)
@@ -61,13 +84,13 @@ add_library(simple_bvh::simple_bvh ALIAS simple_bvh)
6184
# Required Libraries
6285
################################################################################
6386

64-
# Extra warnings
65-
include(simple_bvh_warnings)
66-
target_link_libraries(simple_bvh PRIVATE simple_bvh::warnings)
67-
6887
include(eigen)
6988
target_link_libraries(simple_bvh PUBLIC Eigen3::Eigen)
7089

90+
# Extra warnings (link last for highest priority)
91+
include(simple_bvh_warnings)
92+
target_link_libraries(simple_bvh PRIVATE simple_bvh::warnings)
93+
7194
################################################################################
7295
# Compiler options
7396
################################################################################
@@ -80,14 +103,8 @@ target_compile_features(simple_bvh PUBLIC cxx_std_14)
80103
################################################################################
81104

82105
# Enable unit testing at the root level
83-
if(SIMPLE_BVH_WITH_UNIT_TESTS)
84-
include(CTest)
85-
enable_testing()
86-
87-
# Include Catch2 and provide function `catch_discover_tests` to register tests.
88-
include(catch2)
89-
FetchContent_GetProperties(catch2)
90-
include("${catch2_SOURCE_DIR}/contrib/Catch.cmake")
91-
92-
add_subdirectory(tests)
93-
endif()
106+
if(SIMPLE_BVH_TOPLEVEL_PROJECT AND SIMPLE_BVH_BUILD_TESTS)
107+
include(CTest)
108+
enable_testing()
109+
add_subdirectory(tests)
110+
endif()

cmake/recipes/CPM.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
set(CPM_DOWNLOAD_VERSION 0.38.1)
2+
3+
if(CPM_SOURCE_CACHE)
4+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
5+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
6+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
7+
else()
8+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
9+
endif()
10+
11+
# Expand relative path. This is important if the provided path contains a tilde (~)
12+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
13+
14+
function(download_cpm)
15+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
16+
file(DOWNLOAD
17+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
18+
${CPM_DOWNLOAD_LOCATION}
19+
)
20+
endfunction()
21+
22+
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
23+
download_cpm()
24+
else()
25+
# resume download if it previously failed
26+
file(READ ${CPM_DOWNLOAD_LOCATION} check)
27+
if("${check}" STREQUAL "")
28+
download_cpm()
29+
endif()
30+
unset(check)
31+
endif()
32+
33+
include(${CPM_DOWNLOAD_LOCATION})

cmake/recipes/catch2.cmake

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
#
2-
# Copyright 2020 Adobe. All rights reserved.
3-
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License. You may obtain a copy
5-
# of the License at http://www.apache.org/licenses/LICENSE-2.0
6-
#
7-
# Unless required by applicable law or agreed to in writing, software distributed under
8-
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9-
# OF ANY KIND, either express or implied. See the License for the specific language
10-
# governing permissions and limitations under the License.
11-
#
1+
# Catch2 (https://github.com/catchorg/Catch2)
2+
# License: BSL-1.0
123
if(TARGET Catch2::Catch2)
134
return()
145
endif()
156

167
message(STATUS "Third-party: creating target 'Catch2::Catch2'")
178

18-
include(FetchContent)
19-
FetchContent_Declare(
20-
catch2
21-
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
22-
GIT_TAG v2.13.6
23-
GIT_SHALLOW TRUE
24-
)
25-
FetchContent_MakeAvailable(catch2)
9+
option(CATCH_CONFIG_CPP17_STRING_VIEW "Enable support for std::string_view" ON)
10+
option(CATCH_INSTALL_DOCS "Install documentation alongside library" OFF)
11+
option(CATCH_INSTALL_EXTRAS "Install extras alongside library" OFF)
12+
13+
include(CPM)
14+
CPMAddPackage("gh:catchorg/[email protected]")

cmake/recipes/eigen.cmake

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
1-
#
2-
# Copyright 2020 Adobe. All rights reserved.
3-
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License. You may obtain a copy
5-
# of the License at http://www.apache.org/licenses/LICENSE-2.0
6-
#
7-
# Unless required by applicable law or agreed to in writing, software distributed under
8-
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9-
# OF ANY KIND, either express or implied. See the License for the specific language
10-
# governing permissions and limitations under the License.
11-
#
1+
# Eigen (https://gitlab.com/libeigen/eigen)
2+
# License: MPL 2.0
123
if(TARGET Eigen3::Eigen)
134
return()
145
endif()
156

167
option(EIGEN_WITH_MKL "Use Eigen with MKL" OFF)
8+
option(EIGEN_DONT_VECTORIZE "Disable Eigen vectorization" OFF)
9+
option(EIGEN_MPL2_ONLY "Enable Eigen MPL2 license only" OFF)
1710

18-
if(EIGEN_ROOT)
19-
message(STATUS "Third-party: creating target 'Eigen3::Eigen' for external path: ${EIGEN_ROOT}")
20-
set(EIGEN_INCLUDE_DIRS ${EIGEN_ROOT})
21-
else()
22-
message(STATUS "Third-party: creating target 'Eigen3::Eigen'")
11+
message(STATUS "Third-party: creating target 'Eigen3::Eigen'")
2312

24-
include(FetchContent)
25-
FetchContent_Declare(
26-
eigen
27-
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
28-
GIT_TAG tags/3.3.7
29-
GIT_SHALLOW TRUE
30-
)
31-
FetchContent_GetProperties(eigen)
32-
if(NOT eigen_POPULATED)
33-
FetchContent_Populate(eigen)
34-
endif()
35-
set(EIGEN_INCLUDE_DIRS ${eigen_SOURCE_DIR})
36-
37-
install(DIRECTORY ${EIGEN_INCLUDE_DIRS}/Eigen
38-
DESTINATION include
39-
)
40-
endif()
13+
include(CPM)
14+
CPMAddPackage(
15+
NAME eigen
16+
GITLAB_REPOSITORY libeigen/eigen
17+
GIT_TAG 3.4.0
18+
DOWNLOAD_ONLY ON
19+
)
4120

4221
add_library(Eigen3_Eigen INTERFACE)
4322
add_library(Eigen3::Eigen ALIAS Eigen3_Eigen)
4423

4524
include(GNUInstallDirs)
4625
target_include_directories(Eigen3_Eigen SYSTEM INTERFACE
47-
$<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS}>
26+
$<BUILD_INTERFACE:${eigen_SOURCE_DIR}>
4827
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
4928
)
50-
# target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_MPL2_ONLY)
29+
30+
if(EIGEN_MPL2_ONLY)
31+
target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_MPL2_ONLY)
32+
endif()
33+
34+
if(EIGEN_DONT_VECTORIZE)
35+
target_compile_definitions(Eigen3_Eigen INTERFACE EIGEN_DONT_VECTORIZE)
36+
endif()
5137

5238
if(EIGEN_WITH_MKL)
5339
# TODO: Checks that, on 64bits systems, `mkl::mkl` is using the LP64 interface
@@ -68,6 +54,6 @@ endif()
6854
# Install rules
6955
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME eigen)
7056
set_target_properties(Eigen3_Eigen PROPERTIES EXPORT_NAME Eigen)
71-
install(DIRECTORY ${EIGEN_INCLUDE_DIRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
57+
install(DIRECTORY ${eigen_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
7258
install(TARGETS Eigen3_Eigen EXPORT Eigen_Targets)
73-
install(EXPORT Eigen_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eigen NAMESPACE Eigen3::)
59+
install(EXPORT Eigen_Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/eigen NAMESPACE Eigen3::)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright 2021 Adobe. All rights reserved.
3+
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License. You may obtain a copy
5+
# of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software distributed under
8+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
# OF ANY KIND, either express or implied. See the License for the specific language
10+
# governing permissions and limitations under the License.
11+
#
12+
13+
if(DEFINED ENV{CPM_SOURCE_CACHE})
14+
set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
15+
else()
16+
# Set CPM cache folder if unset
17+
file(REAL_PATH "~/.cache/CPM" CPM_SOURCE_CACHE_DEFAULT EXPAND_TILDE)
18+
endif()
19+
20+
set(CPM_SOURCE_CACHE
21+
${CPM_SOURCE_CACHE_DEFAULT}
22+
CACHE PATH "Directory to download CPM dependencies"
23+
)
24+
message(STATUS "Using CPM cache folder: ${CPM_SOURCE_CACHE}")

cmake/simple_bvh/simple_bvh_warnings.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if(TARGET simple_bvh::warnings)
77
return()
88
endif()
99

10-
set(SIMPLE_BVH_FLAGS
10+
set(SIMPLE_BVH_WARNING_FLAGS
1111
-Wall
1212
-Wextra
1313
-pedantic
@@ -147,15 +147,15 @@ set(SIMPLE_BVH_FLAGS
147147

148148
# Flags above don't make sense for MSVC
149149
if(MSVC)
150-
set(SIMPLE_BVH_FLAGS)
150+
set(SIMPLE_BVH_WARNING_FLAGS)
151151
endif()
152152

153153
include(CheckCXXCompilerFlag)
154154

155155
add_library(simple_bvh_warnings INTERFACE)
156156
add_library(simple_bvh::warnings ALIAS simple_bvh_warnings)
157157

158-
foreach(FLAG IN ITEMS ${SIMPLE_BVH_FLAGS})
158+
foreach(FLAG IN ITEMS ${SIMPLE_BVH_WARNING_FLAGS})
159159
string(REPLACE "=" "-" FLAG_VAR "${FLAG}")
160160
if(NOT DEFINED IS_SUPPORTED_${FLAG_VAR})
161161
check_cxx_compiler_flag("${FLAG}" IS_SUPPORTED_${FLAG_VAR})

src/BVH.cpp renamed to src/SimpleBVH/BVH.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <BVH.hpp>
2-
#include <Morton.hpp>
1+
#include "BVH.hpp"
2+
#include <SimpleBVH/Morton.hpp>
33

44
#include <iostream>
55

6-
namespace BVH {
6+
namespace SimpleBVH {
77
namespace {
88
bool box_box_intersection(
99
const Eigen::Vector3d& min1,
@@ -201,4 +201,4 @@ bool BVH::box_intersects_box(
201201

202202
return box_box_intersection(bbd0, bbd1, bmin, bmax);
203203
}
204-
} // namespace BVH
204+
} // namespace SimpleBVH

0 commit comments

Comments
 (0)