Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the openmp deps detection #1750

Merged
merged 7 commits into from
Dec 22, 2024
Merged
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 ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
## Bug fixes

- *General*
- Fix cmake CGAL 6.0 breaking change. (David Coeurjolly, [#1745](https://github.com/DGtal-team/DGtal/pull/1745))
- Fixing cmake CGAL 6.0 breaking change. (David Coeurjolly, [#1745](https://github.com/DGtal-team/DGtal/pull/1745))
- Adding a new `DGTAL_REMOVE_UNINSTALL` cmake option to disable the `uninstall` target. (David Coeurjolly, [#1746](https://github.com/DGtal-team/DGtal/pull/1746)
- Using the `dcoeurjo/GeometryProcessing-cmake-recipes` openmp recipe to detect openmp (David Coeurjolly, [#1750](https://github.com/DGtal-team/DGtal/pull/1750))

- *Geometry*
- Bug fix in ArithmeticalDSSComputerOnSurfels (Tristan Roussillon, [#1742](https://github.com/DGtal-team/DGtal/pull/1742))
Expand Down
44 changes: 4 additions & 40 deletions cmake/CheckDGtalOptionalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -288,46 +288,10 @@ endif()
# -----------------------------------------------------------------------------
set(OPENMP_FOUND_DGTAL 0)
if(WITH_OPENMP)
if(APPLE)
message("-- Setting OpenMP flags on MacOs. Assuming `brew install libomp`")
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
IF(EXISTS "/opt/homebrew/")
message(STATUS "Using M1/Homebrew C paths")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/include" CACHE INTERNAL "OpenMP flags for #Xcode toolchain.")
set(OpenMP_C_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/opt/homebrew/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
else()
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_C_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
IF(EXISTS "/opt/homebrew/")
message(STATUS "Using M1/Homebrew C++ paths")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_CXX_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/opt/homebrew/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
else()
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_CXX_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
endif()
endif()
endif()

find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(OPENMP_FOUND_DGTAL 1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
target_link_libraries(DGtal PUBLIC ${OpenMP_CXX_LIBRARIES})
set(DGtalLibDependencies ${DGtalLibDependencies} ${OpenMP_CXX_LIBRARIES})
target_compile_definitions(DGtal PUBLIC -DWITH_OPENMP)
message(STATUS "OpenMP found. Libs: ${OpenMP_CXX_LIBRARIES}")
else()
message(FATAL_ERROR "OpenMP support not available.")
endif()
include(openmp)
set(DGtalLibDependencies ${DGtalLibDependencies} OpenMP::OpenMP_CXX)
set(OPENMP_FOUND_DGTAL 1)
set(WITH_OPENMP 1)
endif()

# -----------------------------------------------------------------------------
Expand Down
32 changes: 2 additions & 30 deletions cmake/DGtalConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,8 @@ if (@QT5_FOUND_DGTAL@) #if QT5_FOUND_DGTAL
endif (@QT5_FOUND_DGTAL@)

if(@OPENMP_FOUND_DGTAL@) #if OPENMP_FOUND_DGTAL
if(APPLE)
message("-- Setting OpenMP flags on MacOs. Assuming `brew install libomp`")
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
IF(EXISTS "/opt/homebrew/")
message(STATUS "Using M1/Homebrew C paths")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/include" CACHE INTERNAL "OpenMP flags for #Xcode toolchain.")
set(OpenMP_C_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/opt/homebrew/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
else()
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_C_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
IF(EXISTS "/opt/homebrew/")
message(STATUS "Using M1/Homebrew C++ paths")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_CXX_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/opt/homebrew/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
else()
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_CXX_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
endif()
endif()
endif()
find_dependency(OpenMP REQUIRED
@OpenMP_HINTS@
)
include(openmp)
set(DGtalLibDependencies ${DGtalLibDependencies} OpenMP::OpenMP_CXX)
set(WITH_OPENMP 1)
endif()

Expand Down
3 changes: 2 additions & 1 deletion cmake/DGtalConfigGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export(TARGETS DGtal FILE ${dgtal_export_file})
# is ON. Disable it when deploying.
set(_dependencies_list
Boost ZLIB
GMP ITK Cairo HDF5 QGLVIEWER Qt5 OpenMP Eigen3::Eigen CGAL FFTW3
GMP ITK Cairo HDF5 QGLVIEWER Qt5 OpenMP Eigen3::Eigen CGAL FFTW3 OpenMP::OpenMPCXX
)
foreach(dep ${_dependencies_list})
if(DGTAL_CONFIG_HINTS)
Expand Down Expand Up @@ -60,6 +60,7 @@ set(_find_cmake_files
"${PROJECT_SOURCE_DIR}/cmake/FindGMP.cmake"
"${PROJECT_SOURCE_DIR}/cmake/deps/eigen.cmake"
"${PROJECT_SOURCE_DIR}/cmake/deps/libigl.cmake"
"${PROJECT_SOURCE_DIR}/cmake/deps/openmp.cmake"
"${PROJECT_SOURCE_DIR}/cmake/CPM.cmake"
)
file(COPY ${_find_cmake_files}
Expand Down
30 changes: 30 additions & 0 deletions cmake/deps/openmp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

if(APPLE)
message("-- Setting OpenMP flags on MacOs. Assuming `brew install libomp`")
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
IF(EXISTS "/opt/homebrew/")
message(STATUS "[openmp] Using M1-M2/Homebrew C paths (-I/opt/homebrew/opt/libomp/include)")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include" CACHE INTERNAL "OpenMP flags for #Xcode toolchain.")
set(OpenMP_C_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/opt/homebrew/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
else()
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_C_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
IF(EXISTS "/opt/homebrew/")
message(STATUS "[openmp] Using M1-M2/Homebrew C++ paths ( -I/opt/homebrew/opt/libomp/include)")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_CXX_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/opt/homebrew/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
else()
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include" CACHE INTERNAL "OpenMP flags for Xcode toolchain.")
set(OpenMP_CXX_LIB_NAMES "omp" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
set(OpenMP_omp_LIBRARY "/usr/local/opt/libomp/lib/libomp.dylib" CACHE INTERNAL "OpenMP lib name for Xcode toolchain.")
endif()
endif()
endif()

find_package(OpenMP REQUIRED)
2 changes: 1 addition & 1 deletion src/DGtal/topology/HalfEdgeDataStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace DGtal
/// because there was link error with gcc 4.8.4 for all variants
/// within HalfEdgeDataStructure (e.g. BOOST_STATIC_CONSTANT, c++
/// constexpr, c++ constexpr with const reference).
static std::size_t const HALF_EDGE_INVALID_INDEX = boost::integer_traits<std::size_t>::const_max;
static std::size_t const HALF_EDGE_INVALID_INDEX = std::numeric_limits<std::size_t>::max();

/////////////////////////////////////////////////////////////////////////////
// class HalfEdgeDataStructure
Expand Down
1 change: 0 additions & 1 deletion src/DGtal/topology/VoxelComplex.ih
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <boost/property_map/property_map.hpp>
#include <iostream>
#ifdef WITH_OPENMP
// #include <experimental/algorithm>
#include <omp.h>
#endif
//////////////////////////////////////////////////////////////////////////////
Expand Down
Loading