Update CMake to use OpenMP via built-in support (#112)

This commit is contained in:
Chuck Walbourn 2023-05-01 10:41:59 -07:00 committed by GitHub
parent e94f3d3495
commit 70b9b272ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View File

@ -133,6 +133,15 @@ target_include_directories(${PROJECT_NAME} PUBLIC
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
if(UVATLAS_USE_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
else()
set(UVATLAS_USE_OPENMP OFF)
endif()
endif()
target_include_directories(${PROJECT_NAME} PRIVATE UVAtlas UVAtlas/geodesics UVAtlas/isochart)
if(NOT MINGW)
@ -251,6 +260,10 @@ if(BUILD_TOOLS AND WIN32)
Microsoft::DirectXMesh::Utilities)
source_group(uvatlastool REGULAR_EXPRESSION UVAtlasTool/*.*)
if(UVATLAS_USE_OPENMP)
target_link_libraries(uvatlastool OpenMP::OpenMP_CXX)
endif()
if(directxmath_FOUND)
target_link_libraries(uvatlastool Microsoft::DirectXMath)
endif()
@ -367,8 +380,9 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
endif()
if(UVATLAS_USE_OPENMP)
# OpenMP in MSVC is not compatible with /permissive- unless you disable two-phase lookup
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE /openmp /Zc:twoPhase-)
target_compile_options(${t} PRIVATE /Zc:twoPhase-)
endforeach()
endif()

View File

@ -311,9 +311,9 @@ HRESULT CIsochartEngine::ParameterizeChartsInHeapParallelized(
for (int n = 0; n < static_cast<int>(parent.size()); ++n)
{
if (FAILED(hrOut)) // for the other threads
break;
continue;
auto pChart = parent[n];
auto pChart = parent[static_cast<size_t>(n)];
assert(pChart != nullptr);
_Analysis_assume_(pChart != nullptr);
@ -323,7 +323,7 @@ HRESULT CIsochartEngine::ParameterizeChartsInHeapParallelized(
if (FAILED(hr))
{
hrOut = hr; // doesn't need pragma atomic as all changes to hrOut are to set it to FAILED
break;
continue;
}
// If current chart has been partitoned, just children add to heap to be

View File

@ -3,10 +3,9 @@
include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)
include(CMakeFindDependencyMacro)
set(BUILD_TOOLS @BUILD_TOOLS@)
if(BUILD_TOOLS AND WIN32 AND (NOT WINDOWS_STORE))
find_dependency(directxmesh)
find_dependency(directxtex)
set(UVATLAS_USE_OPENMP @UVATLAS_USE_OPENMP@)
if(UVATLAS_USE_OPENMP)
find_dependency(OpenMP)
endif()
set(ENABLE_USE_EIGEN @ENABLE_USE_EIGEN@)