Skip to content

Commit c1e8e0a

Browse files
dmitryryinteligcbot
authored andcommitted
moving opencl-clang discovery code to outer scope
to make it available for VC
1 parent 64bd4c3 commit c1e8e0a

File tree

3 files changed

+149
-123
lines changed

3 files changed

+149
-123
lines changed

IGC/BiFModule/CMakeLists.txt

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -34,129 +34,6 @@ if(NOT DEFINED VME_TYPES_DEFINED)
3434
set(VME_TYPES_DEFINED TRUE)
3535
endif()
3636

37-
# Order of chosing way how to take opencl-clang
38-
#1. CCLANG_FROM_SYSTEM - use installed on system opencl-clang toolchain
39-
#2. CCLANG_BUILD_PREBUILDS - use prebuilded opencl-clang toolchain
40-
# CCLANG_BUILD_PREBUILDS_DIR - set path to prebuilt cclang folder
41-
#3. CCLANG_BUILD_INTREE_LLVM - use sources of opencl-clang toolchain
42-
43-
find_library(CCLANG_FROM_SYSTEM ${COMMON_CLANG_LIBRARY_NAME})
44-
45-
### Check if user manual setup some of flag
46-
if(NOT CCLANG_BUILD_PREBUILDS)
47-
set(CCLANG_BUILD_PREBUILDS FALSE)
48-
else()
49-
set(CCLANG_FROM_SYSTEM FALSE)
50-
set(CCLANG_BUILD_INTREE_LLVM FALSE)
51-
endif()
52-
53-
if(NOT CCLANG_BUILD_INTREE_LLVM)
54-
set(CCLANG_BUILD_INTREE_LLVM FALSE)
55-
else()
56-
set(CCLANG_BUILD_PREBUILDS FALSE)
57-
set(CCLANG_FROM_SYSTEM FALSE)
58-
endif()
59-
###
60-
61-
### Check by order first available way to link with opencl-clang
62-
if(NOT CCLANG_FROM_SYSTEM)
63-
if(NOT CCLANG_BUILD_PREBUILDS_DIR)
64-
# Detect CPU architecture
65-
igc_arch_get_cpu(cpuSuffix)
66-
set(CCLANG_BUILD_PREBUILDS_DIR "${IGC_BUILD__GFX_DEV_SRC_DIR}/../../prebuild-opencl-clang/Release/${cpuSuffix}")
67-
68-
if(NOT EXISTS ${CCLANG_BUILD_PREBUILDS_DIR})
69-
set(CCLANG_BUILD_PREBUILDS_DIR "${IGC_BUILD__GFX_DEV_SRC_DIR}/../prebuild-opencl-clang/Release/${cpuSuffix}")
70-
endif()
71-
endif()
72-
set(CCLANG_BUILD_INTREE_LLVM_DIR ${LLVM_SOURCE_DIR}/projects/opencl-clang)
73-
### Check if user by choosing some way of linking with opencl-clang provided required folders
74-
if(${CCLANG_BUILD_PREBUILDS})
75-
if(NOT EXISTS ${CCLANG_BUILD_PREBUILDS_DIR})
76-
message(FATAL_ERROR "[IGC\\BiFModule] : User setup to use prebuilded opencl-clang but not found folder : ${CCLANG_BUILD_PREBUILDS_DIR}")
77-
set(CCLANG_BUILD_PREBUILDS FALSE)
78-
endif()
79-
elseif(${CCLANG_BUILD_INTREE_LLVM})
80-
if(NOT EXISTS ${CCLANG_BUILD_INTREE_LLVM_DIR})
81-
message(FATAL_ERROR "[IGC\\BiFModule] : User setup to use sources of opencl-clang but not found folder : ${CCLANG_BUILD_INTREE_LLVM_DIR}")
82-
set(CCLANG_BUILD_INTREE_LLVM FALSE)
83-
endif()
84-
###
85-
### User didn't define nothing, then pick the method 2 or 3.
86-
elseif(EXISTS ${CCLANG_BUILD_PREBUILDS_DIR})
87-
set(CCLANG_BUILD_PREBUILDS TRUE)
88-
elseif(EXISTS ${CCLANG_BUILD_INTREE_LLVM_DIR})
89-
message(STATUS "[IGC\\BiFModule] : opencl-clang will be taken from sources")
90-
set(CCLANG_BUILD_INTREE_LLVM TRUE)
91-
else()
92-
message(FATAL_ERROR "[IGC\\BiFModule] : Cannot find opencl-clang tool-chain, please provide sources or install it on system.")
93-
endif()
94-
###
95-
96-
endif()
97-
###
98-
99-
#1. CCLANG_FROM_SYSTEM - use installed on system opencl-clang toolchain
100-
if(CCLANG_FROM_SYSTEM)
101-
message(STATUS "[IGC\\BiFModule] : opencl-clang will be taken from system")
102-
103-
find_library(SYSTEM_COMMON_CLANG ${COMMON_CLANG_LIBRARY_NAME})
104-
105-
add_library(opencl-clang-lib SHARED IMPORTED GLOBAL)
106-
set_property(TARGET opencl-clang-lib PROPERTY "IMPORTED_LOCATION" "${SYSTEM_COMMON_CLANG}")
107-
find_program(CLANG_GE7 clang-${LLVM_VERSION_MAJOR})
108-
if(CLANG_GE7)
109-
message(STATUS "[IGC\\BiFModule] Found clang-${LLVM_VERSION_MAJOR} executable: ${CLANG_GE7}")
110-
111-
add_executable(clang-tool IMPORTED GLOBAL)
112-
set_property(TARGET clang-tool PROPERTY "IMPORTED_LOCATION" "${CLANG_GE7}")
113-
set(CL_OPTIONS "-finclude-default-header")
114-
if(LLVM_VERSION_MAJOR VERSION_EQUAL 7)
115-
message(WARNING "[IGC\\BiFModule] : clang-7 should be patched with VME patch (https://reviews.llvm.org/D51484). Assuming that it is. If not, please add -DVME_TYPES_DEFINED=FALSE.")
116-
endif()
117-
else(CLANG_GE7)
118-
message(FATAL_ERROR "[IGC\\BiFModule] : Couldn't find clang-${LLVM_VERSION_MAJOR} executable, please install it.")
119-
endif(CLANG_GE7)
120-
###
121-
#2. CCLANG_BUILD_PREBUILDS - use prebuilded opencl-clang toolchain
122-
elseif(${CCLANG_BUILD_PREBUILDS})
123-
message(STATUS "[IGC\\BiFModule] : opencl-clang will be taken from prebuilds")
124-
125-
set(CLANG_TOOL_PATH "${CCLANG_BUILD_PREBUILDS_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")
126-
set(LLVM_PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
127-
128-
# Get clang-tool version
129-
execute_process(
130-
COMMAND ${CLANG_TOOL_PATH} -v
131-
ERROR_VARIABLE CLANG_TOOL_V_CALL)
132-
string(REGEX MATCH "clang version ([0-9]*\\.[0-9]*\\.[0-9]*[a-zA-Z0-9]*)" CLANG_TOOL_VERSION "${CLANG_TOOL_V_CALL}")
133-
set(CLANG_TOOL_VERSION "${CMAKE_MATCH_1}")
134-
135-
# Check if llvm version for IGC is newer or equal with the clang-tool version
136-
if(${LLVM_PACKAGE_VERSION} VERSION_GREATER ${CLANG_TOOL_VERSION} OR
137-
${LLVM_PACKAGE_VERSION} EQUAL ${CLANG_TOOL_VERSION})
138-
add_library(opencl-clang-lib SHARED IMPORTED GLOBAL)
139-
set_property(TARGET opencl-clang-lib PROPERTY "IMPORTED_LOCATION" "${CCLANG_BUILD_PREBUILDS_DIR}/${COMMON_CLANG_LIB_FULL_NAME}")
140-
141-
add_executable(clang-tool IMPORTED GLOBAL)
142-
set_property(TARGET clang-tool PROPERTY "IMPORTED_LOCATION" "${CLANG_TOOL_PATH}")
143-
144-
set(opencl-header "${CCLANG_BUILD_PREBUILDS_DIR}/opencl-c.h")
145-
else()
146-
message(FATAL_ERROR "[IGC\\BiFModule] : The clang-tool(${CLANG_TOOL_VERSION}) from prebuilts is newer than llvm(${LLVM_PACKAGE_VERSION}) version for IGC.")
147-
endif()
148-
###
149-
#3. CCLANG_BUILD_INTREE_LLVM - use sources of opencl-clang toolchain
150-
elseif(${CCLANG_BUILD_INTREE_LLVM})
151-
message(STATUS "[IGC\\BiFModule] : opencl-clang will be taken from sources")
152-
153-
add_library(opencl-clang-lib ALIAS ${COMMON_CLANG_LIBRARY_NAME})
154-
add_executable(clang-tool ALIAS clang)
155-
get_target_property(CLANG_SOURCE_DIR clang SOURCE_DIR)
156-
set(opencl-header "${CLANG_SOURCE_DIR}/../../lib/Headers/opencl-c.h")
157-
endif()
158-
###
159-
16037
if(UNIX)
16138
if(NOT ${CCLANG_BUILD_INTREE_LLVM})
16239
# Get common clang library soname

IGC/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,6 +3338,9 @@ if(LLVM_ON_WIN32
33383338
endif()
33393339

33403340

3341+
3342+
include(${IGC_SOURCE_DIR}/cmake/find_opencl_clang.cmake)
3343+
33413344
if(IGC_BUILD__VC_ENABLED)
33423345
add_subdirectory(CMFE)
33433346
endif()

IGC/cmake/find_opencl_clang.cmake

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#=========================== begin_copyright_notice ============================
2+
#
3+
# Copyright (c) 2014-2021 Intel Corporation
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"),
7+
# to deal in the Software without restriction, including without limitation
8+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
# and/or sell copies of the Software, and to permit persons to whom
10+
# the Software is furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included
13+
# in all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21+
# IN THE SOFTWARE.
22+
#
23+
#============================ end_copyright_notice =============================
24+
25+
# Order of chosing way how to take opencl-clang
26+
#1. CCLANG_FROM_SYSTEM - use installed on system opencl-clang toolchain
27+
#2. CCLANG_BUILD_PREBUILDS - use prebuilded opencl-clang toolchain
28+
# CCLANG_BUILD_PREBUILDS_DIR - set path to prebuilt cclang folder
29+
#3. CCLANG_BUILD_INTREE_LLVM - use sources of opencl-clang toolchain
30+
31+
find_library(CCLANG_FROM_SYSTEM ${COMMON_CLANG_LIBRARY_NAME})
32+
33+
### Check if user manual setup some of flag
34+
if(NOT CCLANG_BUILD_PREBUILDS)
35+
set(CCLANG_BUILD_PREBUILDS FALSE)
36+
else()
37+
set(CCLANG_FROM_SYSTEM FALSE)
38+
set(CCLANG_BUILD_INTREE_LLVM FALSE)
39+
endif()
40+
41+
if(NOT CCLANG_BUILD_INTREE_LLVM)
42+
set(CCLANG_BUILD_INTREE_LLVM FALSE)
43+
else()
44+
set(CCLANG_BUILD_PREBUILDS FALSE)
45+
set(CCLANG_FROM_SYSTEM FALSE)
46+
endif()
47+
###
48+
49+
### Check by order first available way to link with opencl-clang
50+
if(NOT CCLANG_FROM_SYSTEM)
51+
if(NOT CCLANG_BUILD_PREBUILDS_DIR)
52+
# Detect CPU architecture
53+
igc_arch_get_cpu(cpuSuffix)
54+
set(CCLANG_BUILD_PREBUILDS_DIR "${IGC_BUILD__GFX_DEV_SRC_DIR}/../../prebuild-opencl-clang/Release/${cpuSuffix}")
55+
56+
if(NOT EXISTS ${CCLANG_BUILD_PREBUILDS_DIR})
57+
set(CCLANG_BUILD_PREBUILDS_DIR "${IGC_BUILD__GFX_DEV_SRC_DIR}/../prebuild-opencl-clang/Release/${cpuSuffix}")
58+
endif()
59+
endif()
60+
set(CCLANG_BUILD_INTREE_LLVM_DIR ${LLVM_SOURCE_DIR}/projects/opencl-clang)
61+
### Check if user by choosing some way of linking with opencl-clang provided required folders
62+
if(${CCLANG_BUILD_PREBUILDS})
63+
if(NOT EXISTS ${CCLANG_BUILD_PREBUILDS_DIR})
64+
message(FATAL_ERROR "[IGC] : User setup to use prebuilded opencl-clang but not found folder : ${CCLANG_BUILD_PREBUILDS_DIR}")
65+
set(CCLANG_BUILD_PREBUILDS FALSE)
66+
endif()
67+
elseif(${CCLANG_BUILD_INTREE_LLVM})
68+
if(NOT EXISTS ${CCLANG_BUILD_INTREE_LLVM_DIR})
69+
message(FATAL_ERROR "[IGC] : User setup to use sources of opencl-clang but not found folder : ${CCLANG_BUILD_INTREE_LLVM_DIR}")
70+
set(CCLANG_BUILD_INTREE_LLVM FALSE)
71+
endif()
72+
###
73+
### User didn't define nothing, then pick the method 2 or 3.
74+
elseif(EXISTS ${CCLANG_BUILD_PREBUILDS_DIR})
75+
set(CCLANG_BUILD_PREBUILDS TRUE)
76+
elseif(EXISTS ${CCLANG_BUILD_INTREE_LLVM_DIR})
77+
message(STATUS "[IGC] : opencl-clang will be taken from sources")
78+
set(CCLANG_BUILD_INTREE_LLVM TRUE)
79+
else()
80+
message(FATAL_ERROR "[IGC] : Cannot find opencl-clang tool-chain, please provide sources or install it on system.")
81+
endif()
82+
###
83+
84+
endif()
85+
###
86+
87+
#1. CCLANG_FROM_SYSTEM - use installed on system opencl-clang toolchain
88+
if(CCLANG_FROM_SYSTEM)
89+
message(STATUS "[IGC] : opencl-clang will be taken from system")
90+
91+
find_library(SYSTEM_COMMON_CLANG ${COMMON_CLANG_LIBRARY_NAME})
92+
93+
add_library(opencl-clang-lib SHARED IMPORTED GLOBAL)
94+
set_property(TARGET opencl-clang-lib PROPERTY "IMPORTED_LOCATION" "${SYSTEM_COMMON_CLANG}")
95+
find_program(CLANG_GE7 clang-${LLVM_VERSION_MAJOR})
96+
if(CLANG_GE7)
97+
message(STATUS "[IGC] Found clang-${LLVM_VERSION_MAJOR} executable: ${CLANG_GE7}")
98+
99+
add_executable(clang-tool IMPORTED GLOBAL)
100+
set_property(TARGET clang-tool PROPERTY "IMPORTED_LOCATION" "${CLANG_GE7}")
101+
set(CL_OPTIONS "-finclude-default-header")
102+
if(LLVM_VERSION_MAJOR VERSION_EQUAL 7)
103+
message(WARNING "[IGC] : clang-7 should be patched with VME patch (https://reviews.llvm.org/D51484). Assuming that it is. If not, please add -DVME_TYPES_DEFINED=FALSE.")
104+
endif()
105+
else(CLANG_GE7)
106+
message(FATAL_ERROR "[IGC] : Couldn't find clang-${LLVM_VERSION_MAJOR} executable, please install it.")
107+
endif(CLANG_GE7)
108+
###
109+
#2. CCLANG_BUILD_PREBUILDS - use prebuilded opencl-clang toolchain
110+
elseif(${CCLANG_BUILD_PREBUILDS})
111+
message(STATUS "[IGC] : opencl-clang will be taken from prebuilds")
112+
113+
set(CLANG_TOOL_PATH "${CCLANG_BUILD_PREBUILDS_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")
114+
set(LLVM_PACKAGE_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
115+
116+
# Get clang-tool version
117+
execute_process(
118+
COMMAND ${CLANG_TOOL_PATH} -v
119+
ERROR_VARIABLE CLANG_TOOL_V_CALL)
120+
string(REGEX MATCH "clang version ([0-9]*\\.[0-9]*\\.[0-9]*[a-zA-Z0-9]*)" CLANG_TOOL_VERSION "${CLANG_TOOL_V_CALL}")
121+
set(CLANG_TOOL_VERSION "${CMAKE_MATCH_1}")
122+
123+
# Check if llvm version for IGC is newer or equal with the clang-tool version
124+
if(${LLVM_PACKAGE_VERSION} VERSION_GREATER ${CLANG_TOOL_VERSION} OR
125+
${LLVM_PACKAGE_VERSION} EQUAL ${CLANG_TOOL_VERSION})
126+
add_library(opencl-clang-lib SHARED IMPORTED GLOBAL)
127+
set_property(TARGET opencl-clang-lib PROPERTY "IMPORTED_LOCATION" "${CCLANG_BUILD_PREBUILDS_DIR}/${COMMON_CLANG_LIB_FULL_NAME}")
128+
129+
add_executable(clang-tool IMPORTED GLOBAL)
130+
set_property(TARGET clang-tool PROPERTY "IMPORTED_LOCATION" "${CLANG_TOOL_PATH}")
131+
132+
set(opencl-header "${CCLANG_BUILD_PREBUILDS_DIR}/opencl-c.h")
133+
else()
134+
message(FATAL_ERROR "[IGC] : The clang-tool(${CLANG_TOOL_VERSION}) from prebuilts is newer than llvm(${LLVM_PACKAGE_VERSION}) version for IGC.")
135+
endif()
136+
###
137+
#3. CCLANG_BUILD_INTREE_LLVM - use sources of opencl-clang toolchain
138+
elseif(${CCLANG_BUILD_INTREE_LLVM})
139+
message(STATUS "[IGC] : opencl-clang will be taken from sources")
140+
141+
add_library(opencl-clang-lib ALIAS ${COMMON_CLANG_LIBRARY_NAME})
142+
add_executable(clang-tool ALIAS clang)
143+
get_target_property(CLANG_SOURCE_DIR clang SOURCE_DIR)
144+
set(opencl-header "${CLANG_SOURCE_DIR}/../../lib/Headers/opencl-c.h")
145+
endif()
146+
###

0 commit comments

Comments
 (0)