Exported target for `vtkm::openmp` points to nonexistent files in MSYS2
I'm working on a software that uses VTK and I'm having issues building it in the MSYS2 environment. We installed VTK using the official MSYS2-provided package (https://packages.msys2.org/base/mingw-w64-vtk) which includes VTK-m, among other things.
We have had build failures for our project for targets that link with VTK because the build system was looking for files that don't exist, namely D:/a/msys64/mingw64/lib/libgomp.dll.a
, D:/a/msys64/mingw64/lib/libmingwthrd.a
, and D:/a/msys64/mingw64/lib/libmingwthrd.a
. I believe these paths come from the CI environment that is used to generate the MSYS2 packages. The contents of the package (e.g.: https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-vtk-9.3.0-6-any.pkg.tar.zst) have references to these files in /msys64/lib/cmake/vtk/vtkm/VTKmTargets.cmake
:
# Create imported target vtkm::openmp
add_library(vtkm::openmp INTERFACE IMPORTED)
set_target_properties(vtkm::openmp PROPERTIES
INTERFACE_COMPILE_OPTIONS "\$<\$<COMPILE_LANGUAGE:CXX>:-fopenmp>"
INTERFACE_LINK_LIBRARIES "D:/a/msys64/mingw64/lib/libgomp.dll.a;D:/a/msys64/mingw64/lib/libmingwthrd.a;D:/a/msys64/mingw64/lib/libmingwthrd.a"
)
And substituting the paths in the INTERFACE_LINK_LIBRARIES
line for OpenMP::OpenMP_CXX
seems to solve the issue.
I think these lines are generated based on commands in CMake/VTKmDeviceAdapters.cmake#L57-77 and that the following change to line 74 might be all that is needed to fix my issue:
if(OpenMP_CXX_LIBRARIES)
set_target_properties(vtkm_openmp PROPERTIES
- INTERFACE_LINK_LIBRARIES "${OpenMP_CXX_LIBRARIES}")
+ INTERFACE_LINK_LIBRARIES OpenMP::OpenMP_CXX)
endif()
install(TARGETS vtkm_openmp EXPORT ${VTKm_EXPORT_NAME})
I can create a MR if that change seems reasonable. However, it might be possible to simplify the code for OpenMP in this file and make it more similar to the code for TBB at the same time? Maybe something like this:
if(VTKm_ENABLE_OPENMP AND NOT (TARGET vtkm_openmp OR TARGET vtkm::openmp))
find_package(OpenMP 4.0 REQUIRED COMPONENTS CXX QUIET)
add_library(vtkm_openmp INTERFACE)
target_link_libraries(vtkm_openmp INTERFACE OpenMP::OpenMP_CXX)
target_compile_options(vtkm_openmp INTERFACE $<$<COMPILE_LANGUAGE:CXX>:${OpenMP_CXX_FLAGS}>)
if(VTKm_ENABLE_CUDA)
string(REPLACE ";" "," openmp_cuda_flags "-Xcompiler=${OpenMP_CXX_FLAGS}")
target_compile_options(vtkm_openmp INTERFACE $<$<COMPILE_LANGUAGE:CUDA>:${openmp_cuda_flags}>)
endif()
set_target_properties(vtkm_openmp PROPERTIES EXPORT_NAME openmp)
install(TARGETS vtkm_openmp EXPORT ${VTKm_EXPORT_NAME})
endif()
My CMake skills are limited so these changes might have more of an impact that I know.