Skip to content

Commit

Permalink
llvm-openmp: make the wrapper slightly more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 2, 2024
1 parent af7f463 commit 35fdf5e
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions recipes/llvm-openmp/all/cmake/conan-llvm-openmp-vars.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ function(_openmp_get_compiler_spec_date)
set(BIN_FILE "${BUILD_DIR}/ompver.bin")
file(WRITE "${SRC_FILE}" "
#include <stdio.h>
#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);
Expand All @@ -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)
Expand Down Expand Up @@ -72,17 +79,25 @@ 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]+)")
Expand All @@ -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
Expand All @@ -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})

0 comments on commit 35fdf5e

Please sign in to comment.