Skip to content

Commit f0a4f63

Browse files
author
Diptorup Deb
authored
Improves the logic to implement IntelSycl version requirement. (#832)
1 parent 3358d2c commit f0a4f63

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

libsyclinterface/cmake/modules/FindIntelSycl.cmake

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,48 @@ find_package(IntelDPCPP REQUIRED)
3939
set(clangxx_cmd "${CMAKE_CXX_COMPILER}")
4040
set(clangxx_arg "--version")
4141

42+
# Compares the two version string that are supposed to be in x.y.z format
43+
# and reports if the argument VERSION_STR1 is greater than or equal than
44+
# version_str2. The strings are compared lexicographically after conversion to
45+
# lists of equal lengths, with the shorter string getting zero-padded.
46+
function(versions_greater_equal VERSION_STR1 VERSION_STR2 OUTPUT)
47+
# Convert the strings to list
48+
string(REPLACE "." ";" VL1 ${VERSION_STR1})
49+
string(REPLACE "." ";" VL2 ${VERSION_STR2})
50+
# get lengths of both lists
51+
list(LENGTH VL1 VL1_LEN)
52+
list(LENGTH VL2 VL2_LEN)
53+
set(LEN ${VL1_LEN})
54+
# If they differ in size pad the shorter list with 0s
55+
if(VL1_LEN GREATER VL2_LEN)
56+
math(EXPR DIFF "${VL1_LEN} - ${VL2_LEN}" OUTPUT_FORMAT DECIMAL)
57+
foreach(IDX RANGE 1 ${DIFF} 1)
58+
list(APPEND VL2 "0")
59+
endforeach()
60+
elseif(VL2_LEN GREATER VL2_LEN)
61+
math(EXPR DIFF "${VL1_LEN} - ${VL2_LEN}" OUTPUT_FORMAT DECIMAL)
62+
foreach(IDX RANGE 1 ${DIFF} 1)
63+
list(APPEND VL2 "0")
64+
endforeach()
65+
set(LEN ${VL2_LEN})
66+
endif()
67+
math(EXPR LEN_SUB_ONE "${LEN}-1")
68+
foreach(IDX RANGE 0 ${LEN_SUB_ONE} 1)
69+
list(GET VL1 ${IDX} VAL1)
70+
list(GET VL2 ${IDX} VAL2)
71+
72+
if(${VAL1} GREATER ${VAL2})
73+
set(${OUTPUT} TRUE PARENT_SCOPE)
74+
break()
75+
elseif(${VAL1} LESS ${VAL2})
76+
set(${OUTPUT} FALSE PARENT_SCOPE)
77+
break()
78+
else()
79+
set(${OUTPUT} TRUE PARENT_SCOPE)
80+
endif()
81+
endforeach()
82+
endfunction(compare_versions)
83+
4284
# Check if dpcpp is available
4385
execute_process(
4486
COMMAND ${clangxx_cmd} ${clangxx_arg}
@@ -84,14 +126,16 @@ endif()
84126

85127
# Check if a specific version of DPCPP is requested.
86128
if(IntelSycl_FIND_VERSION AND (DEFINED IntelSycl_VERSION))
87-
string(COMPARE
88-
LESS_EQUAL
89-
${IntelSycl_FIND_VERSION}
129+
set(VERSION_GT_FIND_VERSION FALSE)
130+
versions_greater_equal(
90131
${IntelSycl_VERSION}
91-
VERSION_MATCH
132+
${IntelSycl_FIND_VERSION}
133+
VERSION_GT_FIND_VERSION
92134
)
93-
if(VERSION_MATCH)
135+
if(VERSION_GT_FIND_VERSION)
94136
set(IntelSycl_FOUND TRUE)
137+
else()
138+
set(IntelSycl_FOUND FALSE)
95139
endif()
96140
else()
97141
set(IntelSycl_FOUND TRUE)

0 commit comments

Comments
 (0)