@@ -39,6 +39,48 @@ find_package(IntelDPCPP REQUIRED)
39
39
set (clangxx_cmd "${CMAKE_CXX_COMPILER} " )
40
40
set (clangxx_arg "--version" )
41
41
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
+
42
84
# Check if dpcpp is available
43
85
execute_process (
44
86
COMMAND ${clangxx_cmd} ${clangxx_arg}
@@ -84,14 +126,16 @@ endif()
84
126
85
127
# Check if a specific version of DPCPP is requested.
86
128
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 (
90
131
${IntelSycl_VERSION}
91
- VERSION_MATCH
132
+ ${IntelSycl_FIND_VERSION}
133
+ VERSION_GT_FIND_VERSION
92
134
)
93
- if (VERSION_MATCH )
135
+ if (VERSION_GT_FIND_VERSION )
94
136
set (IntelSycl_FOUND TRUE )
137
+ else ()
138
+ set (IntelSycl_FOUND FALSE )
95
139
endif ()
96
140
else ()
97
141
set (IntelSycl_FOUND TRUE )
0 commit comments