Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake-build-*/
bench/fcpw/
.idea/
.DS_Store
.DS_Store
build
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
set(MANTIS_TOPLEVEL_PROJECT OFF)
else()
set(MANTIS_TOPLEVEL_PROJECT ON)
endif()

cmake_minimum_required(VERSION 3.26)
project(mantis)

Expand All @@ -7,7 +14,9 @@ include(FetchContent)

option(MANTIS_BUILD_EXAMPLES "Build the examples" OFF)
option(MANTIS_BUILD_BENCH "Build the benchmarks" OFF)
option(MANTIS_BUILD_TESTS "Build the tests" ON)
option(MANTIS_BUILD_TESTS "Build the tests" ${MANTIS_TOPLEVEL_PROJECT})

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")

# This is split out into a separate target to avoid setting compile flags that would
# affect the correctness of geogram's exact predicates.
Expand Down
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.41.0)

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})
45 changes: 45 additions & 0 deletions cmake/recipes/P2M.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# P2M (https://github.com/Martin-JC-Xu/P2M)
# License: AGPL-3.0
if(TARGET P2M::P2M)
return()
endif()

message(STATUS "Third-party: creating target 'P2M::P2M'")

include(CPM)
CPMAddPackage(
URI "gh:Martin-JC-Xu/P2M#ae56568ece94651ff51685d242dae3f3e4a40c26"
DOWNLOAD_ONLY YES
)

add_library(P2M
${P2M_SOURCE_DIR}/KDTree.cpp
${P2M_SOURCE_DIR}/KDTree.h
${P2M_SOURCE_DIR}/Model.cpp
${P2M_SOURCE_DIR}/Model.h
${P2M_SOURCE_DIR}/RTree.cpp
${P2M_SOURCE_DIR}/RTree.h
${P2M_SOURCE_DIR}/tetgen.cpp
${P2M_SOURCE_DIR}/tetgen.h
${P2M_SOURCE_DIR}/VoronoiTetgen.cpp
${P2M_SOURCE_DIR}/VoronoiTetgen.h
)
add_library(P2M::P2M ALIAS P2M)

target_include_directories(P2M PUBLIC "${P2M_SOURCE_DIR}")

# Disable warning: 'sprintf' is deprecated: This function is provided for
# compatibility reasons only. Due to security concerns inherent in the design
# of sprintf(3), it is highly recommended that you use snprintf(3) instead.
target_compile_options(P2M PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-deprecated-declarations>
)

include(eigen)
target_link_libraries(P2M PUBLIC Eigen3::Eigen)

include(onetbb)
target_link_libraries(P2M PUBLIC TBB::tbb)

# Folder name for IDE
set_target_properties(P2M PROPERTIES FOLDER "ThirdParty")
78 changes: 78 additions & 0 deletions cmake/recipes/eigen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 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_DONT_VECTORIZE "Disable Eigen vectorization" OFF)
option(EIGEN_MPL2_ONLY "Enable Eigen MPL2 license only" OFF)

message(STATUS "Third-party: creating target 'Eigen3::Eigen'")

include(CPM)
CPMAddPackage(
URI "gl:libeigen/eigen#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_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

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
)
elseif(APPLE)
find_package(BLAS REQUIRED)
find_library(LAPACKE lapacke PATHS
"/opt/local/lib/lapack"
"/opt/homebrew/opt/lapack/lib"
)
if (NOT LAPACKE)
# BLAS should be available on macOS, but LAPACKE might not be
message(WARNING "LAPACKE library not found (required for EIGEN_USE_LAPACKE on macOS)! "
"Perhaps you need to install it (e.g., brew install lapack). "
"Eigen will be built without LAPACKE support.")
else()
message(STATUS "Found BLAS and LAPACKE. Enabling Eigen LAPACKE support.")
target_link_libraries(Eigen3_Eigen INTERFACE
${BLAS_LIBRARIES} ${LAPACKE}
)
target_compile_definitions(Eigen3_Eigen INTERFACE
EIGEN_USE_BLAS
EIGEN_USE_LAPACKE_STRICT
)
endif()
endif()

# On Windows, enable natvis files to improve debugging experience
if(WIN32 AND eigen_SOURCE_DIR)
target_sources(Eigen3_Eigen INTERFACE $<BUILD_INTERFACE:${eigen_SOURCE_DIR}/debug/msvc/eigen.natvis>)
endif()

# Install rules
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME eigen)
set_target_properties(Eigen3_Eigen PROPERTIES EXPORT_NAME Eigen)
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::)
90 changes: 90 additions & 0 deletions cmake/recipes/onetbb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# oneTBB (https://github.com/oneapi-src/oneTBB)
# License: Apache-2.0
if(TARGET TBB::tbb)
return()
endif()

message(STATUS "Third-party: creating target 'TBB::tbb' (OneTBB)")

# Emscripten sets CMAKE_SYSTEM_PROCESSOR to "x86". Change it to "WASM" to prevent TBB from
# adding machine-specific "-mrtm" and "-mwaitpkg" compile options.
if(EMSCRIPTEN)
set(CMAKE_SYSTEM_PROCESSOR "WASM")
endif()

option(TBB_TEST "Enable testing" OFF)
option(TBB_EXAMPLES "Enable examples" OFF)
option(TBB_STRICT "Treat compiler warnings as errors" OFF)
option(TBB_PREFER_STATIC "Use the static version of TBB for the alias target" ON)
unset(TBB_DIR CACHE)

function(onetbb_import_target)
macro(push_variable var value)
if(DEFINED CACHE{${var}})
set(ONETBB_OLD_${var}_VALUE "${${var}}")
set(ONETBB_OLD_${var}_TYPE CACHE_TYPE)
elseif(DEFINED ${var})
set(ONETBB_OLD_${var}_VALUE "${${var}}")
set(ONETBB_OLD_${var}_TYPE NORMAL_TYPE)
else()
set(ONETBB_OLD_${var}_TYPE NONE_TYPE)
endif()
set(${var} "${value}" CACHE PATH "" FORCE)
endmacro()

macro(pop_variable var)
if(ONETBB_OLD_${var}_TYPE STREQUAL CACHE_TYPE)
set(${var} "${ONETBB_OLD_${var}_VALUE}" CACHE PATH "" FORCE)
elseif(ONETBB_OLD_${var}_TYPE STREQUAL NORMAL_TYPE)
unset(${var} CACHE)
set(${var} "${ONETBB_OLD_${var}_VALUE}")
elseif(ONETBB_OLD_${var}_TYPE STREQUAL NONE_TYPE)
unset(${var} CACHE)
else()
message(FATAL_ERROR "Trying to pop a variable that has not been pushed: ${var}")
endif()
endmacro()

if(TBB_PREFER_STATIC)
push_variable(BUILD_SHARED_LIBS OFF)
else()
push_variable(BUILD_SHARED_LIBS ON)
endif()

set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME tbb)
include(CPM)
CPMAddPackage("gh:uxlfoundation/oneTBB@2022.1.0")

pop_variable(BUILD_SHARED_LIBS)
endfunction()

onetbb_import_target()

if(NOT TARGET TBB::tbb)
message(FATAL_ERROR "TBB::tbb is still not defined!")
endif()

foreach(name IN ITEMS tbb tbbmalloc tbbmalloc_proxy)
if(TARGET ${name})
# Folder name for IDE
set_target_properties(${name} PROPERTIES FOLDER "ThirdParty/tbb")

# Force debug postfix for library name. Our pre-compiled MKL library expects "tbb12.dll" (without postfix).
set_target_properties(${name} PROPERTIES DEBUG_POSTFIX "")

# Without this macro, TBB will explicitly link against "tbb12_debug.lib" in Debug configs.
# This is undesirable, since our pre-compiled version of MKL is linked against "tbb12.dll".
target_compile_definitions(${name} PUBLIC -D__TBB_NO_IMPLICIT_LINKAGE=1)

# Disable some features and avoid processor-specific code paths when compiling with
# Emscripten for WebAssembly.
if(EMSCRIPTEN)
target_compile_definitions(${name} PRIVATE
ITT_ARCH=-1
__TBB_RESUMABLE_TASKS_USE_THREADS=1
__TBB_DYNAMIC_LOAD_ENABLED=0
__TBB_WEAK_SYMBOLS_PRESENT=0
)
endif()
endif()
endforeach()
4 changes: 3 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FetchContent_Declare(
polyscope
GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git)
GIT_REPOSITORY https://github.com/nmwsharp/polyscope.git
GIT_TAG v2.4.0
)

FetchContent_MakeAvailable(polyscope)

Expand Down
12 changes: 5 additions & 7 deletions examples/sdf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

find_package(TBB CONFIG)

add_executable(sdf main.cpp implicit_meshing.cpp implicit_meshing.h)
target_link_libraries(sdf PRIVATE mantis utils polyscope)

if (NOT TARGET TBB::tbb)
target_compile_definitions(sdf PRIVATE USE_SERIAL)
else()
# if (NOT TARGET TBB::tbb)
# target_compile_definitions(sdf PRIVATE USE_SERIAL)
# else()
include(onetbb)
target_link_libraries(sdf PRIVATE TBB::tbb)
target_compile_definitions(sdf PUBLIC USE_TBB)
endif()
# endif()

target_include_directories(sdf PRIVATE external)
target_compile_definitions(sdf PRIVATE ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../assets/")
24 changes: 1 addition & 23 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
)

FetchContent_MakeAvailable(eigen)

add_library(P2M
P2M/KDTree.cpp
P2M/KDTree.h
P2M/Model.cpp
P2M/Model.h
P2M/RTree.cpp
P2M/RTree.h
P2M/tetgen.cpp
P2M/tetgen.h
P2M/VoronoiTetgen.cpp
P2M/VoronoiTetgen.h
)

target_link_libraries(P2M PUBLIC Eigen3::Eigen)
target_include_directories(P2M PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/P2M")

add_executable(tests tests.cpp)

include(P2M)
target_link_libraries(tests PRIVATE mantis P2M)
target_compile_definitions(tests PRIVATE ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../assets/")

Expand Down
Loading