Skip to content

Commit ad8ed72

Browse files
author
Teseo Schneider
committed
geogram bvh refactored
1 parent 6801861 commit ad8ed72

14 files changed

+1209
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/*
2+
3rdparty

CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
################################################################################
2+
cmake_minimum_required(VERSION 3.13)
3+
project(BVH_lib)
4+
################################################################################
5+
6+
# Detects whether this is a top-level project
7+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
8+
set(EBW_TOPLEVEL_PROJECT ON)
9+
else()
10+
set(EBW_TOPLEVEL_PROJECT OFF)
11+
endif()
12+
13+
14+
set(EBW_EXTERNAL ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/)
15+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
16+
17+
18+
# Use C++11/14
19+
include(CXXFeatures)
20+
21+
include(EBWDependencies)
22+
23+
# Sort projects inside the solution
24+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
25+
26+
# Generate position independent code by default
27+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
28+
29+
################################################################################
30+
31+
32+
################################################################################
33+
# Main library
34+
################################################################################
35+
36+
add_library(BVH_lib src/BVH.cpp src/Morton.cpp)
37+
target_include_directories(BVH_lib PUBLIC src)
38+
39+
# Setup dependencies
40+
target_compile_features(BVH_lib PUBLIC ${CXX14_FEATURES})
41+
target_link_libraries(BVH_lib PUBLIC Eigen3::Eigen)
42+
43+
################################################################################
44+
# Subdirectories
45+
################################################################################
46+
47+
# Other sources
48+
# add_subdirectory(src)
49+
50+
# Compile tests only if this is a top-level project
51+
if(EBW_TOPLEVEL_PROJECT)
52+
# Unit tests
53+
include(CTest)
54+
# Catch2
55+
enable_testing()
56+
add_subdirectory(tests)
57+
endif()

cmake/CXXFeatures.cmake

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
################################################################################
2+
3+
if(NOT (${CMAKE_VERSION} VERSION_LESS "3.8.0"))
4+
# For CMake 3.8 and above, we can use meta features directly provided by CMake itself
5+
set(CXX11_FEATURES cxx_std_11)
6+
set(CXX14_FEATURES cxx_std_14)
7+
set(CXX17_FEATURES cxx_std_17)
8+
return()
9+
endif()
10+
11+
################################################################################
12+
13+
set(CXX11_FEATURES
14+
cxx_auto_type
15+
cxx_constexpr
16+
)
17+
18+
set(CXX14_FEATURES
19+
cxx_generic_lambdas
20+
)
21+
22+
set(CXX17_FEATURES
23+
cxx_generic_lambdas
24+
)
25+
26+
################################################################################
27+
28+
# https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
29+
# cxx_aggregate_default_initializers Aggregate default initializers, as defined in N3605.
30+
# cxx_alias_templates Template aliases, as defined in N2258.
31+
# cxx_alignas Alignment control alignas, as defined in N2341.
32+
# cxx_alignof Alignment control alignof, as defined in N2341.
33+
# cxx_attributes Generic attributes, as defined in N2761.
34+
# cxx_attribute_deprecated deprecated]] attribute, as defined in N3760.
35+
# cxx_auto_type Automatic type deduction, as defined in N1984.
36+
# cxx_binary_literals Binary literals, as defined in N3472.
37+
# cxx_constexpr Constant expressions, as defined in N2235.
38+
# cxx_contextual_conversions Contextual conversions, as defined in N3323.
39+
# cxx_decltype_incomplete_return_types Decltype on incomplete return types, as defined in N3276.
40+
# cxx_decltype Decltype, as defined in N2343.
41+
# cxx_decltype_auto decltype(auto) semantics, as defined in N3638.
42+
# cxx_default_function_template_args Default template arguments for function templates, as defined in DR226
43+
# cxx_defaulted_functions Defaulted functions, as defined in N2346.
44+
# cxx_defaulted_move_initializers Defaulted move initializers, as defined in N3053.
45+
# cxx_delegating_constructors Delegating constructors, as defined in N1986.
46+
# cxx_deleted_functions Deleted functions, as defined in N2346.
47+
# cxx_digit_separators Digit separators, as defined in N3781.
48+
# cxx_enum_forward_declarations Enum forward declarations, as defined in N2764.
49+
# cxx_explicit_conversions Explicit conversion operators, as defined in N2437.
50+
# cxx_extended_friend_declarations Extended friend declarations, as defined in N1791.
51+
# cxx_extern_templates Extern templates, as defined in N1987.
52+
# cxx_final Override control final keyword, as defined in N2928, N3206 and N3272.
53+
# cxx_func_identifier Predefined __func__ identifier, as defined in N2340.
54+
# cxx_generalized_initializers Initializer lists, as defined in N2672.
55+
# cxx_generic_lambdas Generic lambdas, as defined in N3649.
56+
# cxx_inheriting_constructors Inheriting constructors, as defined in N2540.
57+
# cxx_inline_namespaces Inline namespaces, as defined in N2535.
58+
# cxx_lambdas Lambda functions, as defined in N2927.
59+
# cxx_lambda_init_captures Initialized lambda captures, as defined in N3648.
60+
# cxx_local_type_template_args Local and unnamed types as template arguments, as defined in N2657.
61+
# cxx_long_long_type long long type, as defined in N1811.
62+
# cxx_noexcept Exception specifications, as defined in N3050.
63+
# cxx_nonstatic_member_init Non-static data member initialization, as defined in N2756.
64+
# cxx_nullptr Null pointer, as defined in N2431.
65+
# cxx_override Override control override keyword, as defined in N2928, N3206 and N3272.
66+
# cxx_range_for Range-based for, as defined in N2930.
67+
# cxx_raw_string_literals Raw string literals, as defined in N2442.
68+
# cxx_reference_qualified_functions Reference qualified functions, as defined in N2439.
69+
# cxx_relaxed_constexpr Relaxed constexpr, as defined in N3652.
70+
# cxx_return_type_deduction Return type deduction on normal functions, as defined in N3386.
71+
# cxx_right_angle_brackets Right angle bracket parsing, as defined in N1757.
72+
# cxx_rvalue_references R-value references, as defined in N2118.
73+
# cxx_sizeof_member Size of non-static data members, as defined in N2253.
74+
# cxx_static_assert Static assert, as defined in N1720.
75+
# cxx_strong_enums Strongly typed enums, as defined in N2347.
76+
# cxx_thread_local Thread-local variables, as defined in N2659.
77+
# cxx_trailing_return_types Automatic function return type, as defined in N2541.
78+
# cxx_unicode_literals Unicode string literals, as defined in N2442.
79+
# cxx_uniform_initialization Uniform intialization, as defined in N2640.
80+
# cxx_unrestricted_unions Unrestricted unions, as defined in N2544.
81+
# cxx_user_literals User-defined literals, as defined in N2765.
82+
# cxx_variable_templates Variable templates, as defined in N3651.
83+
# cxx_variadic_macros Variadic macros, as defined in N1653.
84+
# cxx_variadic_templates Variadic templates, as defined in N2242.
85+
# cxx_template_template_parameters Template template parameters, as defined in ISO/IEC 14882:1998.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Distributed under the OSI-approved MIT License. See accompanying
2+
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
3+
4+
cmake_minimum_required(VERSION 2.8.2)
5+
6+
project(${DL_ARGS_PROJ}-download NONE)
7+
8+
include(ExternalProject)
9+
ExternalProject_Add(${DL_ARGS_PROJ}-download
10+
${DL_ARGS_UNPARSED_ARGUMENTS}
11+
SOURCE_DIR "${DL_ARGS_SOURCE_DIR}"
12+
BINARY_DIR "${DL_ARGS_BINARY_DIR}"
13+
CONFIGURE_COMMAND ""
14+
BUILD_COMMAND ""
15+
INSTALL_COMMAND ""
16+
TEST_COMMAND ""
17+
)

cmake/DownloadProject.cmake

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Distributed under the OSI-approved MIT License. See accompanying
2+
# file LICENSE or https://github.com/Crascit/DownloadProject for details.
3+
#
4+
# MODULE: DownloadProject
5+
#
6+
# PROVIDES:
7+
# download_project( PROJ projectName
8+
# [PREFIX prefixDir]
9+
# [DOWNLOAD_DIR downloadDir]
10+
# [SOURCE_DIR srcDir]
11+
# [BINARY_DIR binDir]
12+
# [QUIET]
13+
# ...
14+
# )
15+
#
16+
# Provides the ability to download and unpack a tarball, zip file, git repository,
17+
# etc. at configure time (i.e. when the cmake command is run). How the downloaded
18+
# and unpacked contents are used is up to the caller, but the motivating case is
19+
# to download source code which can then be included directly in the build with
20+
# add_subdirectory() after the call to download_project(). Source and build
21+
# directories are set up with this in mind.
22+
#
23+
# The PROJ argument is required. The projectName value will be used to construct
24+
# the following variables upon exit (obviously replace projectName with its actual
25+
# value):
26+
#
27+
# projectName_SOURCE_DIR
28+
# projectName_BINARY_DIR
29+
#
30+
# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically
31+
# need to be provided. They can be specified if you want the downloaded source
32+
# and build directories to be located in a specific place. The contents of
33+
# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the
34+
# locations used whether you provide SOURCE_DIR/BINARY_DIR or not.
35+
#
36+
# The DOWNLOAD_DIR argument does not normally need to be set. It controls the
37+
# location of the temporary CMake build used to perform the download.
38+
#
39+
# The PREFIX argument can be provided to change the base location of the default
40+
# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments
41+
# are provided, then PREFIX will have no effect. The default value for PREFIX is
42+
# CMAKE_BINARY_DIR.
43+
#
44+
# The QUIET option can be given if you do not want to show the output associated
45+
# with downloading the specified project.
46+
#
47+
# In addition to the above, any other options are passed through unmodified to
48+
# ExternalProject_Add() to perform the actual download, patch and update steps.
49+
# The following ExternalProject_Add() options are explicitly prohibited (they
50+
# are reserved for use by the download_project() command):
51+
#
52+
# CONFIGURE_COMMAND
53+
# BUILD_COMMAND
54+
# INSTALL_COMMAND
55+
# TEST_COMMAND
56+
#
57+
# Only those ExternalProject_Add() arguments which relate to downloading, patching
58+
# and updating of the project sources are intended to be used. Also note that at
59+
# least one set of download-related arguments are required.
60+
#
61+
# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to
62+
# prevent a check at the remote end for changes every time CMake is run
63+
# after the first successful download. See the documentation of the ExternalProject
64+
# module for more information. It is likely you will want to use this option if it
65+
# is available to you. Note, however, that the ExternalProject implementation contains
66+
# bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when
67+
# using the URL download method or when specifying a SOURCE_DIR with no download
68+
# method. Fixes for these have been created, the last of which is scheduled for
69+
# inclusion in CMake 3.8.0. Details can be found here:
70+
#
71+
# https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c
72+
# https://gitlab.kitware.com/cmake/cmake/issues/16428
73+
#
74+
# If you experience build errors related to the update step, consider avoiding
75+
# the use of UPDATE_DISCONNECTED.
76+
#
77+
# EXAMPLE USAGE:
78+
#
79+
# include(DownloadProject)
80+
# download_project(PROJ googletest
81+
# GIT_REPOSITORY https://github.com/google/googletest.git
82+
# GIT_TAG master
83+
# UPDATE_DISCONNECTED 1
84+
# QUIET
85+
# )
86+
#
87+
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
88+
#
89+
#========================================================================================
90+
91+
92+
set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}")
93+
94+
include(CMakeParseArguments)
95+
96+
function(download_project)
97+
98+
set(options QUIET)
99+
set(oneValueArgs
100+
PROJ
101+
PREFIX
102+
DOWNLOAD_DIR
103+
SOURCE_DIR
104+
BINARY_DIR
105+
# Prevent the following from being passed through
106+
CONFIGURE_COMMAND
107+
BUILD_COMMAND
108+
INSTALL_COMMAND
109+
TEST_COMMAND
110+
)
111+
set(multiValueArgs "")
112+
113+
cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
114+
115+
# Hide output if requested
116+
if (DL_ARGS_QUIET)
117+
set(OUTPUT_QUIET "OUTPUT_QUIET")
118+
else()
119+
unset(OUTPUT_QUIET)
120+
message(STATUS "Downloading/updating ${DL_ARGS_PROJ}")
121+
endif()
122+
123+
# Set up where we will put our temporary CMakeLists.txt file and also
124+
# the base point below which the default source and binary dirs will be.
125+
# The prefix must always be an absolute path.
126+
if (NOT DL_ARGS_PREFIX)
127+
set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}")
128+
else()
129+
get_filename_component(DL_ARGS_PREFIX "${DL_ARGS_PREFIX}" ABSOLUTE
130+
BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
131+
endif()
132+
if (NOT DL_ARGS_DOWNLOAD_DIR)
133+
set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download")
134+
endif()
135+
136+
# Ensure the caller can know where to find the source and build directories
137+
if (NOT DL_ARGS_SOURCE_DIR)
138+
set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src")
139+
endif()
140+
if (NOT DL_ARGS_BINARY_DIR)
141+
set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build")
142+
endif()
143+
set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE)
144+
set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE)
145+
146+
# The way that CLion manages multiple configurations, it causes a copy of
147+
# the CMakeCache.txt to be copied across due to it not expecting there to
148+
# be a project within a project. This causes the hard-coded paths in the
149+
# cache to be copied and builds to fail. To mitigate this, we simply
150+
# remove the cache if it exists before we configure the new project. It
151+
# is safe to do so because it will be re-generated. Since this is only
152+
# executed at the configure step, it should not cause additional builds or
153+
# downloads.
154+
file(REMOVE "${DL_ARGS_DOWNLOAD_DIR}/CMakeCache.txt")
155+
156+
# Create and build a separate CMake project to carry out the download.
157+
# If we've already previously done these steps, they will not cause
158+
# anything to be updated, so extra rebuilds of the project won't occur.
159+
# Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
160+
# has this set to something not findable on the PATH.
161+
configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in"
162+
"${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt")
163+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
164+
-D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}"
165+
.
166+
RESULT_VARIABLE result
167+
${OUTPUT_QUIET}
168+
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
169+
)
170+
if(result)
171+
message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}")
172+
endif()
173+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
174+
RESULT_VARIABLE result
175+
${OUTPUT_QUIET}
176+
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
177+
)
178+
if(result)
179+
message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}")
180+
endif()
181+
182+
endfunction()

cmake/EBWDependencies.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set(EBW_ROOT "${CMAKE_CURRENT_LIST_DIR}/..")
2+
3+
# Download and update 3rdparty libraries
4+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
5+
list(REMOVE_DUPLICATES CMAKE_MODULE_PATH)
6+
include(EBWDownloadExternal)
7+
8+
# Eigen
9+
if(NOT TARGET Eigen3::Eigen)
10+
ebw_download_eigen()
11+
add_library(ebw_eigen INTERFACE)
12+
target_include_directories(ebw_eigen INTERFACE ${EBW_EXTERNAL}/eigen)
13+
set_property(TARGET ebw_eigen PROPERTY EXPORT_NAME Eigen3::Eigen)
14+
add_library(Eigen3::Eigen ALIAS ebw_eigen)
15+
endif()
16+
17+
18+

0 commit comments

Comments
 (0)