From 5d5e5b57cf8edd9e9ee261b42db6451b3a5624a6 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 2 Jul 2024 14:57:35 +0300 Subject: [PATCH] llvm-openmp: make the wrapper slightly more robust Based on https://github.com/microsoft/vcpkg/pull/39389 --- .../all/cmake/conan-llvm-openmp-vars.cmake.in | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in b/recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in index 869d5bc4efce1..a563629ae8506 100644 --- a/recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in +++ b/recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in @@ -33,9 +33,15 @@ function(_openmp_get_compiler_spec_date) set(BIN_FILE "${BUILD_DIR}/ompver.bin") file(WRITE "${SRC_FILE}" " #include - #define STRINGIFY(x) #x - #define TO_STRING(x) STRINGIFY(x) - const char ompver_str[] = \"INFO:OpenMP-date[\" TO_STRING(_OPENMP) \"]\"; + 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); @@ -45,6 +51,7 @@ function(_openmp_get_compiler_spec_date) try_compile(OpenMP_SPECTEST ${BUILD_DIR} SOURCES "${SRC_FILE}" COMPILE_DEFINITIONS "${OpenMP_C_FLAGS}" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${OpenMP_C_INCLUDE_DIR}" COPY_FILE "${BIN_FILE}" ) if(NOT OpenMP_SPECTEST) @@ -72,6 +79,9 @@ 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" @@ -79,10 +89,15 @@ function(_openmp_set_version_by_spec_date) "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]+)") @@ -103,34 +118,30 @@ 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 from the CMake's FindOpenMP.cmake implementation, -# which checks only the version supported by the compiler, and appears to be an oversight on CMake's part. +# 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@) + 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() + _openmp_set_version_by_spec_date() endif() -set(OpenMP_C_FOUND TRUE) -set(OpenMP_C_SPEC_DATE "${OpenMP_SPEC_DATE}") -set(OpenMP_C_VERSION_MAJOR "${OpenMP_VERSION_MAJOR}") -set(OpenMP_C_VERSION_MINOR "${OpenMP_VERSION_MINOR}") -set(OpenMP_C_VERSION "${OpenMP_VERSION}") - -set(OpenMP_CXX_FOUND TRUE) -set(OpenMP_CXX_SPEC_DATE "${OpenMP_SPEC_DATE}") -set(OpenMP_CXX_VERSION_MAJOR "${OpenMP_VERSION_MAJOR}") -set(OpenMP_CXX_VERSION_MINOR "${OpenMP_VERSION_MINOR}") -set(OpenMP_CXX_VERSION "${OpenMP_VERSION}") +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_C_VERSION + VERSION_VAR OpenMP_VERSION REQUIRED_VARS OpenMP_C_FLAGS OpenMP_C_LIB_NAMES @@ -142,7 +153,6 @@ find_package_handle_standard_args(OpenMP OpenMP_CXX_VERSION HANDLE_COMPONENTS ) - set(OPENMP_FOUND ${OpenMP_FOUND}) set(OpenMP_C_FOUND ${OpenMP_FOUND}) set(OpenMP_CXX_FOUND ${OpenMP_FOUND})