From ab20923726cf24bfe17d5ccdfe98879b72935fb1 Mon Sep 17 00:00:00 2001 From: Patrick Stotko Date: Tue, 1 Jun 2021 17:29:55 +0200 Subject: [PATCH] Add Clang 12 detection for Filament dependency (#3522) * Add Clang 12 detection for Filament dependency * Fix parallelstl include if compiler has parallel algorithms support --- 3rdparty/find_dependencies.cmake | 12 +++--------- cpp/open3d/utility/ParallelScan.h | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/3rdparty/find_dependencies.cmake b/3rdparty/find_dependencies.cmake index 40784b371fa..e0035c9b97f 100644 --- a/3rdparty/find_dependencies.cmake +++ b/3rdparty/find_dependencies.cmake @@ -917,8 +917,8 @@ if(BUILD_GUI) endif() # If the default version is not sufficient, look for some specific versions if(NOT FILAMENT_C_COMPILER OR NOT FILAMENT_CXX_COMPILER) - find_program(CLANG_VERSIONED_CC NAMES clang-11 clang-10 clang-9 clang-8 clang-7) - find_program(CLANG_VERSIONED_CXX NAMES clang++11 clang++-10 clang++-9 clang++-8 clang++-7) + find_program(CLANG_VERSIONED_CC NAMES clang-12 clang-11 clang-10 clang-9 clang-8 clang-7) + find_program(CLANG_VERSIONED_CXX NAMES clang++-12 clang++11 clang++-10 clang++-9 clang++-8 clang++-7) if (CLANG_VERSIONED_CC AND CLANG_VERSIONED_CXX) set(FILAMENT_C_COMPILER "${CLANG_VERSIONED_CC}") set(FILAMENT_CXX_COMPILER "${CLANG_VERSIONED_CXX}") @@ -969,19 +969,13 @@ if(BUILD_GUI) # Find CLANG_LIBDIR if it is not defined. Mutiple paths will be searched. if (NOT CLANG_LIBDIR) find_library(CPPABI_LIBRARY c++abi PATH_SUFFIXES - llvm-11/lib llvm-10/lib llvm-9/lib llvm-8/lib llvm-7/lib + llvm-12/lib llvm-11/lib llvm-10/lib llvm-9/lib llvm-8/lib llvm-7/lib REQUIRED) get_filename_component(CLANG_LIBDIR ${CPPABI_LIBRARY} DIRECTORY) endif() # Find clang libraries at the exact path ${CLANG_LIBDIR}. find_library(CPP_LIBRARY c++ PATHS ${CLANG_LIBDIR} REQUIRED NO_DEFAULT_PATH) find_library(CPPABI_LIBRARY c++abi PATHS ${CLANG_LIBDIR} REQUIRED NO_DEFAULT_PATH) - if(CPP_LIBRARY-NOTFOUND) - message(FATAL_ERROR "CPP_LIBRARY-NOTFOUND") - endif() - if(CPPABI_LIBRARY-NOTFOUND) - message(FATAL_ERROR "CPPABI_LIBRARY-NOTFOUND") - endif() # Ensure that libstdc++ gets linked first target_link_libraries(3rdparty_filament INTERFACE -lstdc++ ${CPP_LIBRARY} ${CPPABI_LIBRARY}) diff --git a/cpp/open3d/utility/ParallelScan.h b/cpp/open3d/utility/ParallelScan.h index 8d263ffcb2e..1d31724c506 100644 --- a/cpp/open3d/utility/ParallelScan.h +++ b/cpp/open3d/utility/ParallelScan.h @@ -28,9 +28,28 @@ #include #include + #if TBB_INTERFACE_VERSION >= 10000 + +// Check if the C++ standard library implements parallel algorithms +// and use this over parallelstl to avoid conflicts. +// Clang does not implement it so far, so checking for C++17 is not sufficient. +#ifdef __cpp_lib_parallel_algorithm +#include +#include +#else #include #include + +// parallelstl incorrectly assumes MSVC to unconditionally implement +// parallel algorithms even if __cpp_lib_parallel_algorithm is not defined. +// So manually include the header which pulls all "pstl::execution" definitions +// into the "std" namespace. +#if __PSTL_CPP17_EXECUTION_POLICIES_PRESENT +#include +#endif + +#endif #endif namespace open3d { @@ -66,7 +85,7 @@ template void InclusivePrefixSum(const Tin* first, const Tin* last, Tout* out) { #if TBB_INTERFACE_VERSION >= 10000 // use parallelstl if we have TBB 2018 or later - std::inclusive_scan(pstl::execution::par_unseq, first, last, out); + std::inclusive_scan(std::execution::par_unseq, first, last, out); #else ScanSumBody body(out, first); size_t n = std::distance(first, last);