Skip to content

Commit

Permalink
cmake: Fix FindOpenMP with Flang
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiChinoune committed Dec 2, 2024
1 parent 500f82e commit ffc67fd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--- a/Modules/FindOpenMP.cmake
+++ b/Modules/FindOpenMP.cmake
@@ -150,6 +150,7 @@ function(_OPENMP_FLAG_CANDIDATES LANG)
set(OMP_FLAG_NVHPC "-mp")
set(OMP_FLAG_PGI "-mp")
set(OMP_FLAG_Flang "-fopenmp")
+ set(OMP_FLAG_LLVMFlang "-fopenmp")
set(OMP_FLAG_SunPro "-xopenmp")
set(OMP_FLAG_XL "-qsmp=omp")
# Cray compiler activate OpenMP with -h omp, which is enabled by default.
@@ -377,6 +378,43 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR)
break()
endif()
endif()
+ elseif(CMAKE_${LANG}_COMPILER_ID STREQUAL "LLVMFlang" AND WIN32)
+ find_library(OpenMP_libomp_LIBRARY
+ NAMES omp
+ HINTS ${CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES}
+ )
+ mark_as_advanced(OpenMP_libomp_LIBRARY)
+
+ if(OpenMP_libomp_LIBRARY)
+ # Try without specifying include directory first. We only want to
+ # explicitly add a search path if the header can't be found on the
+ # default header search path already.
+ try_compile( OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG}
+ SOURCE_FROM_VAR "${_OPENMP_TEST_SRC_NAME}" _OPENMP_TEST_SRC_CONTENT
+ LOG_DESCRIPTION "Trying ${LANG} OpenMP compiler with '${OpenMP_libomp_LIBRARY}'"
+ COMPILE_DEFINITIONS ${OPENMP_FLAG}
+ LINK_LIBRARIES ${OpenMP_libomp_LIBRARY}
+ )
+ if(NOT OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG})
+ find_path(OpenMP_${LANG}_INCLUDE_DIR omplib.mod)
+ mark_as_advanced(OpenMP_${LANG}_INCLUDE_DIR)
+ set(OpenMP_${LANG}_INCLUDE_DIR "${OpenMP_${LANG}_INCLUDE_DIR}" PARENT_SCOPE)
+ if(OpenMP_${LANG}_INCLUDE_DIR)
+ try_compile( OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG}
+ SOURCE_FROM_VAR "${_OPENMP_TEST_SRC_NAME}" _OPENMP_TEST_SRC_CONTENT
+ LOG_DESCRIPTION "Trying ${LANG} OpenMP compiler with '${OpenMP_libomp_LIBRARY}' and '${OpenMP_${LANG}_INCLUDE_DIR}'"
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${OpenMP_${LANG}_INCLUDE_DIR}"
+ COMPILE_DEFINITIONS ${OPENMP_FLAG}
+ LINK_LIBRARIES ${OpenMP_libomp_LIBRARY}
+ )
+ endif()
+ endif()
+ if(OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG})
+ set("${OPENMP_FLAG_VAR}" "${OPENMP_FLAG}" PARENT_SCOPE)
+ set("${OPENMP_LIB_NAMES_VAR}" "libomp" PARENT_SCOPE)
+ break()
+ endif()
+ endif()
elseif(CMAKE_${LANG}_COMPILER_ID STREQUAL "Clang" AND WIN32)
# Check for separate OpenMP library for Clang on Windows
find_library(OpenMP_libomp_LIBRARY
8 changes: 7 additions & 1 deletion mingw-w64-cmake/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.31.1
_rc=""
_pkgver=${pkgver}${_rc}
pkgrel=1
pkgrel=2
pkgdesc="A cross-platform open-source make system"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
Expand Down Expand Up @@ -51,11 +51,13 @@ source=("https://github.com/Kitware/CMake/releases/download/v${_pkgver}/${_realn
"0001-Disable-response-files-for-MSYS-Generator.patch"
"0002-Do-not-install-Qt-bundle-in-cmake-gui.patch"
"0003-fix-find-python-on-mingw-aarch64.patch"
"0004-fix-find-openmp-with-llvm-flang-on-windows.patch"
"0005-Default-to-ninja-generator.patch")
sha256sums=('c4fc2a9bd0cd5f899ccb2fb81ec422e175090bc0de5d90e906dd453b53065719'
'25793edcbac05bb6d17fa9947b52ace4a6b5ccccf7758e22ae9ae022ed089061'
'f6cf6a6f2729db2b9427679acd09520af2cd79fc26900b19a49cead05a55cd1a'
'557b5cbc05d4d50b3a67a7892391fcaa5cd95c492cdb4338d86305d1f4a3b88a'
'b806fdac74a52b177276b948d7f3bbbbc03ef2984adec11a1c7c05b4ff57bcc5'
'426818278090704d2a12f62ef3dfd94c47b11fa2784bb842989b7f6a09ee7aa2')

# Helper macros to help make tasks easier #
Expand Down Expand Up @@ -84,6 +86,10 @@ prepare() {
0002-Do-not-install-Qt-bundle-in-cmake-gui.patch \
0003-fix-find-python-on-mingw-aarch64.patch

# https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10052
apply_patch_with_msg \
0004-fix-find-openmp-with-llvm-flang-on-windows.patch

# We want cmake to default to something useful and not MSVC
apply_patch_with_msg \
0005-Default-to-ninja-generator.patch
Expand Down

0 comments on commit ffc67fd

Please sign in to comment.