-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
llvm-openmp: fix incompatibilities with official FindOpenMP
, add v18.1.8, simplify patches, add MSVC support
#24584
Open
valgur
wants to merge
35
commits into
conan-io:master
Choose a base branch
from
valgur:bugfix/llvm-openmp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a447807
llvm-openmp: fix missing FindOpenMP.cmake, check _OPENMP define
valgur e456670
llvm-openmp: improve exported compiler flags
valgur 6fb0dd2
llvm-openmp: print runtime library info in test_package
valgur 2cb443d
llvm-openmp: match the output of FindOpenMP.cmake
valgur c404d92
llvm-openmp: add MSVC support
valgur 7b5356b
llvm-openmp: mention potential cause of the armv8 Debug issues
valgur f57b467
llvm-openmp: add a comment
valgur 2a7cf6e
llvm-openmp: move omp to a separate component
valgur 8a83eb1
llvm-openmp: add Conan v1 support
valgur 73c3994
llvm-openmp: drop v10 and lower
valgur 1e01abf
llvm-openmp: patches can be dropped
valgur fc7bdb5
llvm-openmp: libomptarget is not available on macOS and Windows
valgur e7e762a
llvm-openmp: fix CMake 3.15 incompatibility
valgur bc021ce
llvm-openmp: .get_safe("build_libomptarget")
valgur ea9eaf2
llvm-openmp: don't use a target for linking in the module
valgur 9fc21e7
llvm-openmp: restore the v11 macOS armv8 patch
valgur a2fe32a
llvm-openmp: add psapi system lib dep on Windows
valgur adecb64
llvm-openmp: OpenMP version and spec date version can be determined d…
valgur c4bb7ca
llvm-openmp: add v18.1.3
valgur 4144399
llvm-openmp: print even more details in test_package
valgur 0a4c71e
llvm-openmp: set OpenMP version to the minimum of compiler and runtim…
valgur ae6714b
llvm-openmp: add all spec date versions
valgur e930782
llvm-openmp: set shared=True by default on Windows
valgur 3c5b269
llvm-openmp: force shared=True on Windows
valgur 59df6b9
llvm-openmp: fix try_compile() on CXX-only projects
valgur 74cabe3
llvm-openmp: bump to v18.1.6
valgur d04ab65
llvm-openmp: bump to v18.1.8
valgur 5d5e5b5
llvm-openmp: make the wrapper slightly more robust
valgur ee2352f
llvm-openmp: don't change the Windows omp library name
valgur e4327f7
llvm-openmp: default to shared=True
valgur c634b1e
llvm-openmp: add CMake's copyright notice, mention OpenMP_RUNTIME_MSVC
valgur 330e462
llvm-openmp: adjust the default shared=True handling
valgur 0fa4469
Merge remote-tracking branch 'upstream/master' into bugfix/llvm-openmp
valgur d21c689
llvm-openmp: prohibit the use of OpenMP_C_FLAGS/OpenMP_CXX_FLAGS
valgur 6d2542a
llvm-openmp: check that the correct OpenMP runtime is being used
valgur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
199 changes: 199 additions & 0 deletions
199
recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
# Reproduces the output of https://github.com/Kitware/CMake/blob/v3.30.2/Modules/FindOpenMP.cmake | ||
|
||
# The OpenMP_RUNTIME_MSVC input variable is ignored and always set to 'llvm' for the llvm-openmp package. | ||
|
||
# The _openmp_get_compiler_spec_date() and _openmp_set_version_by_spec_date() functions are adapted from CMake's FindOpenMP.cmake module, | ||
# which is distributed under the following BSD 3-Clause license: | ||
# | ||
# Copyright 2000-2024 Kitware, Inc. and Contributors | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# * Neither the name of Kitware, Inc. nor the names of Contributors | ||
# may be used to endorse or promote products derived from this | ||
# software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# For Conan v1 compatibility | ||
foreach(_suffix RELEASE DEBUG RELWITHDEBINFO MINSIZEREL) | ||
if(DEFINED OpenMP_OpenMP_INCLUDE_DIRS_${_suffix}) | ||
set(_v1_suffix _${_suffix}) | ||
endif() | ||
endforeach() | ||
|
||
# Due to a non-global library location, the library cannot be consumed via OpenMP_C_FLAGS/OpenMP_CXX_FLAGS alone. | ||
# The OpenMP::OpenMP_C and OpenMP::OpenMP_CXX targets must be used instead. | ||
# Setting the flags for internal use only. | ||
set(_OpenMP_FLAGS "@OpenMP_FLAGS@") | ||
|
||
set(OpenMP_C_FLAGS "--dont-use-OpenMP_C_FLAGS--use-OpenMP::OpenMP_C-target-instead") | ||
set(OpenMP_C_INCLUDE_DIR "${OpenMP_INCLUDE_DIR${_v1_suffix}}") | ||
set(OpenMP_C_INCLUDE_DIRS "${OpenMP_INCLUDE_DIRS${_v1_suffix}}") | ||
set(OpenMP_C_LIB_NAMES OpenMP::OpenMP_C) | ||
set(OpenMP_C_LIBRARIES OpenMP::OpenMP_C) | ||
set(OpenMP_C_DEFINITIONS "${OpenMP_DEFINITIONS${_v1_suffix}}") | ||
|
||
set(OpenMP_CXX_FLAGS "--dont-use-OpenMP_CXX_FLAGS--use-OpenMP::OpenMP_CXX-target-instead") | ||
set(OpenMP_CXX_INCLUDE_DIR "${OpenMP_C_INCLUDE_DIR}") | ||
set(OpenMP_CXX_INCLUDE_DIRS "${OpenMP_C_INCLUDE_DIRS}") | ||
set(OpenMP_CXX_LIB_NAMES OpenMP::OpenMP_CXX) | ||
set(OpenMP_CXX_LIBRARIES OpenMP::OpenMP_CXX) | ||
set(OpenMP_CXX_DEFINITIONS "${OpenMP_C_DEFINITIONS}") | ||
|
||
set(OpenMP_omp_LIBRARY OpenMP::OpenMP) | ||
|
||
# Determine OpenMP specification date and version supported by the compiler. | ||
function(_openmp_get_compiler_spec_date) | ||
set(BUILD_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindOpenMP") | ||
set(SRC_FILE "${BUILD_DIR}/ompver.c") | ||
if(NOT CMAKE_C_COMPILER_LOADED) | ||
set(SRC_FILE "${BUILD_DIR}/ompver.cpp") | ||
endif() | ||
set(BIN_FILE "${BUILD_DIR}/ompver.bin") | ||
file(WRITE "${SRC_FILE}" " | ||
#include <stdio.h> | ||
const char ompver_str[] = { 'I', 'N', 'F', 'O', ':', 'O', 'p', 'e', 'n', 'M', | ||
'P', '-', 'd', 'a', 't', 'e', '[', | ||
('0' + ((_OPENMP/100000)%10)), | ||
('0' + ((_OPENMP/10000)%10)), | ||
('0' + ((_OPENMP/1000)%10)), | ||
('0' + ((_OPENMP/100)%10)), | ||
('0' + ((_OPENMP/10)%10)), | ||
('0' + ((_OPENMP/1)%10)), | ||
']', '\\0' }; | ||
int main(void) | ||
{ | ||
puts(ompver_str); | ||
return 0; | ||
} | ||
") | ||
try_compile(OpenMP_SPECTEST ${BUILD_DIR} | ||
SOURCES "${SRC_FILE}" | ||
COMPILE_DEFINITIONS "${_OpenMP_FLAGS}" | ||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${OpenMP_C_INCLUDE_DIR}" | ||
COPY_FILE "${BIN_FILE}" | ||
) | ||
if(NOT OpenMP_SPECTEST) | ||
if(OpenMP_FIND_REQUIRED) | ||
message(FATAL_ERROR "Failed to build OpenMP test executable for specification date detection") | ||
elseif(NOT OpenMP_FIND_QUIETLY) | ||
message(SEND_ERROR "Failed to build OpenMP test executable for specification date detection") | ||
endif() | ||
return() | ||
endif() | ||
file(STRINGS ${BIN_FILE} specstr LIMIT_COUNT 1 REGEX "INFO:OpenMP-date") | ||
if(specstr MATCHES ".*INFO:OpenMP-date\\[0*([^]]*)\\].*") | ||
set(OpenMP_SPEC_DATE ${CMAKE_MATCH_1} PARENT_SCOPE) | ||
else() | ||
if(OpenMP_FIND_REQUIRED) | ||
message(FATAL_ERROR "Failed to detect OpenMP specification date") | ||
elseif(NOT OpenMP_FIND_QUIETLY) | ||
message(SEND_ERROR "Failed to detect OpenMP specification date") | ||
endif() | ||
return() | ||
endif() | ||
endfunction() | ||
|
||
function(_openmp_set_version_by_spec_date) | ||
set(OpenMP_SPEC_DATE_MAP | ||
"202111=5.2" | ||
"202011=5.1" | ||
# Preview versions | ||
"201611=5.0" # OpenMP 5.0 preview 1 | ||
# Combined versions, 2.5 onwards | ||
"201811=5.0" | ||
"201611=5.0" | ||
"201511=4.5" | ||
"201307=4.0" | ||
"201107=3.1" | ||
"200805=3.0" | ||
"200505=2.5" | ||
# C/C++ version 2.0 | ||
"200203=2.0" | ||
# Fortran version 2.0 | ||
"200011=2.0" | ||
# Fortran version 1.1 | ||
"199911=1.1" | ||
# C/C++ version 1.0 (there's no 1.1 for C/C++) | ||
"199810=1.0" | ||
# Fortran version 1.0 | ||
"199710=1.0" | ||
) | ||
if(OpenMP_SPEC_DATE_MAP MATCHES "${OpenMP_SPEC_DATE}=([0-9]+)\\.([0-9]+)") | ||
set(major "${CMAKE_MATCH_1}") | ||
set(minor "${CMAKE_MATCH_2}") | ||
else() | ||
if(OpenMP_FIND_REQUIRED) | ||
message(FATAL_ERROR "Failed to detect OpenMP specification version") | ||
elseif(NOT OpenMP_FIND_QUIETLY) | ||
message(SEND_ERROR "Failed to detect OpenMP specification version") | ||
endif() | ||
return() | ||
endif() | ||
set(OpenMP_VERSION_MAJOR "${major}" PARENT_SCOPE) | ||
set(OpenMP_VERSION_MINOR "${minor}" PARENT_SCOPE) | ||
set(OpenMP_VERSION "${major}.${minor}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Compare the OpenMP API version supported by the compiler to | ||
# the version supported by the LLVM OMP runtime and use the lower of the two. | ||
# Note that this differs slightly from the CMake's FindOpenMP.cmake implementation, | ||
# which checks only the version supported by the compiler. | ||
_openmp_get_compiler_spec_date() | ||
if(OpenMP_SPEC_DATE GREATER @OpenMP_SPEC_DATE@) | ||
set(OpenMP_SPEC_DATE @OpenMP_SPEC_DATE@) | ||
set(OpenMP_VERSION_MAJOR @OpenMP_VERSION_MAJOR@) | ||
set(OpenMP_VERSION_MINOR @OpenMP_VERSION_MINOR@) | ||
set(OpenMP_VERSION @OpenMP_VERSION@) | ||
else() | ||
_openmp_set_version_by_spec_date() | ||
endif() | ||
|
||
foreach(_lang C CXX) | ||
set(OpenMP_${_lang}_FOUND TRUE) | ||
set(OpenMP_${_lang}_SPEC_DATE "${OpenMP_SPEC_DATE}") | ||
set(OpenMP_${_lang}_VERSION_MAJOR "${OpenMP_VERSION_MAJOR}") | ||
set(OpenMP_${_lang}_VERSION_MINOR "${OpenMP_VERSION_MINOR}") | ||
set(OpenMP_${_lang}_VERSION "${OpenMP_VERSION}") | ||
endforeach() | ||
|
||
# Check specification version against the requested min version, validate components | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(OpenMP | ||
VERSION_VAR OpenMP_VERSION | ||
REQUIRED_VARS | ||
OpenMP_C_FLAGS | ||
OpenMP_C_LIB_NAMES | ||
OpenMP_C_SPEC_DATE | ||
OpenMP_C_VERSION | ||
OpenMP_CXX_FLAGS | ||
OpenMP_CXX_LIB_NAMES | ||
OpenMP_CXX_SPEC_DATE | ||
OpenMP_CXX_VERSION | ||
OpenMP_omp_LIBRARY | ||
HANDLE_COMPONENTS | ||
) | ||
set(OPENMP_FOUND ${OpenMP_FOUND}) | ||
set(OpenMP_C_FOUND ${OpenMP_FOUND}) | ||
set(OpenMP_CXX_FOUND ${OpenMP_FOUND}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly, but a potential alternative of passing the appropriate
-I
/-L
paths together with-fopenmp
did not work due to the-L
flag not getting propagated to the linker when passed viaCMAKE_C_FLAGS
, which is how this is typically used.Fortunately, most modern CMake projects use the OpenMP targets instead and the rest can be patched quite easily. Here's a list of such projects (ticked ones have a patch available): https://gist.github.com/valgur/cbd1a856a2eb42c285a2360ecceb0405
The only project that truly needed the flags variable instead of CMake targets was VTKm: https://gitlab.kitware.com/vtk/vtk-m/-/blob/master/CMake/VTKmDeviceAdapters.cmake#L64