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

llvm-openmp: fix incompatibilities with official FindOpenMP, add v18.1.8, simplify patches, add MSVC support #24584

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 Jan 15, 2024
e456670
llvm-openmp: improve exported compiler flags
valgur Jan 15, 2024
6fb0dd2
llvm-openmp: print runtime library info in test_package
valgur Jan 16, 2024
2cb443d
llvm-openmp: match the output of FindOpenMP.cmake
valgur Jan 16, 2024
c404d92
llvm-openmp: add MSVC support
valgur Jan 17, 2024
7b5356b
llvm-openmp: mention potential cause of the armv8 Debug issues
valgur Jan 18, 2024
f57b467
llvm-openmp: add a comment
valgur Jan 18, 2024
2a7cf6e
llvm-openmp: move omp to a separate component
valgur Jan 18, 2024
8a83eb1
llvm-openmp: add Conan v1 support
valgur Jan 18, 2024
73c3994
llvm-openmp: drop v10 and lower
valgur Jan 18, 2024
1e01abf
llvm-openmp: patches can be dropped
valgur Jan 18, 2024
fc7bdb5
llvm-openmp: libomptarget is not available on macOS and Windows
valgur Jan 18, 2024
e7e762a
llvm-openmp: fix CMake 3.15 incompatibility
valgur Jan 18, 2024
bc021ce
llvm-openmp: .get_safe("build_libomptarget")
valgur Jan 18, 2024
ea9eaf2
llvm-openmp: don't use a target for linking in the module
valgur Jan 18, 2024
9fc21e7
llvm-openmp: restore the v11 macOS armv8 patch
valgur Jan 18, 2024
a2fe32a
llvm-openmp: add psapi system lib dep on Windows
valgur Jan 18, 2024
adecb64
llvm-openmp: OpenMP version and spec date version can be determined d…
valgur Apr 1, 2024
c4bb7ca
llvm-openmp: add v18.1.3
valgur Apr 15, 2024
4144399
llvm-openmp: print even more details in test_package
valgur Apr 16, 2024
0a4c71e
llvm-openmp: set OpenMP version to the minimum of compiler and runtim…
valgur Apr 16, 2024
ae6714b
llvm-openmp: add all spec date versions
valgur Apr 16, 2024
e930782
llvm-openmp: set shared=True by default on Windows
valgur Apr 21, 2024
3c5b269
llvm-openmp: force shared=True on Windows
valgur Apr 21, 2024
59df6b9
llvm-openmp: fix try_compile() on CXX-only projects
valgur Apr 28, 2024
74cabe3
llvm-openmp: bump to v18.1.6
valgur May 25, 2024
d04ab65
llvm-openmp: bump to v18.1.8
valgur Jul 2, 2024
5d5e5b5
llvm-openmp: make the wrapper slightly more robust
valgur Jul 2, 2024
ee2352f
llvm-openmp: don't change the Windows omp library name
valgur Aug 6, 2024
e4327f7
llvm-openmp: default to shared=True
valgur Aug 6, 2024
c634b1e
llvm-openmp: add CMake's copyright notice, mention OpenMP_RUNTIME_MSVC
valgur Aug 6, 2024
330e462
llvm-openmp: adjust the default shared=True handling
valgur Aug 6, 2024
0fa4469
Merge remote-tracking branch 'upstream/master' into bugfix/llvm-openmp
valgur Aug 23, 2024
d21c689
llvm-openmp: prohibit the use of OpenMP_C_FLAGS/OpenMP_CXX_FLAGS
valgur Aug 23, 2024
6d2542a
llvm-openmp: check that the correct OpenMP runtime is being used
valgur Sep 19, 2024
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
199 changes: 199 additions & 0 deletions recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in
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")
Copy link
Contributor Author

@valgur valgur Aug 29, 2024

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 via CMAKE_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

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})
55 changes: 7 additions & 48 deletions recipes/llvm-openmp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
sources:
"18.1.8":
openmp:
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/openmp-18.1.8.src.tar.xz"
sha256: "60ed57245e73894e4a2a89b15889f367bd906abfe6d3f92e1718223d4b496150"
cmake:
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/cmake-18.1.8.src.tar.xz"
sha256: "59badef592dd34893cd319d42b323aaa990b452d05c7180ff20f23ab1b41e837"
"17.0.6":
openmp:
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/openmp-17.0.6.src.tar.xz"
Expand Down Expand Up @@ -39,56 +46,8 @@ sources:
"11.1.0":
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.1.0/openmp-11.1.0.src.tar.xz"
sha256: "d187483b75b39acb3ff8ea1b7d98524d95322e3cb148842957e9b0fbb866052e"
"10.0.0":
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/openmp-10.0.0.src.tar.xz"
sha256: "3b9ff29a45d0509a1e9667a0feb43538ef402ea8cfc7df3758a01f20df08adfa"
"9.0.1":
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-9.0.1/openmp-9.0.1.src.tar.xz"
sha256: "5c94060f846f965698574d9ce22975c0e9f04c9b14088c3af5f03870af75cace"
"8.0.1":
url: "https://github.com/llvm/llvm-project/releases/download/llvmorg-8.0.1/openmp-8.0.1.src.tar.xz"
sha256: "3e85dd3cad41117b7c89a41de72f2e6aa756ea7b4ef63bb10dcddf8561a7722c"
patches:
"17.0.4":
- patch_file: "patches/17/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"16.0.6":
- patch_file: "patches/16/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"15.0.7":
- patch_file: "patches/15/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"14.0.6":
- patch_file: "patches/14/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"13.0.1":
- patch_file: "patches/13/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"12.0.1":
- patch_file: "patches/12/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"11.1.0":
- patch_file: "patches/11/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
- patch_file: "patches/11/0002-fix-armv8-build.patch"
patch_description: "Fix build issues on armv8 architecture"
patch_type: "portability"
"10.0.0":
- patch_file: "patches/10/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"9.0.1":
- patch_file: "patches/8/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
"8.0.1":
- patch_file: "patches/8/0001-disable-build-testing.patch"
patch_description: "Disable building of tools, gdb-plugin, tests and docs"
patch_type: "conan"
Loading
Loading