Skip to content

Commit adcec91

Browse files
authored
Fix cross build issues (#346)
Use llvm_create_cross_target only when opencl-clang is not build inside of llvm. Call build_native_tool to use self-build clang to build PCH on in-tree build mode. Signed-off-by: haonanya <[email protected]>
1 parent e287ee5 commit adcec91

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
project( common_clang )
21
cmake_minimum_required(VERSION 3.4.3)
32

3+
if(NOT DEFINED BASE_LLVM_VERSION)
4+
set(BASE_LLVM_VERSION 12.0.0)
5+
endif(NOT DEFINED BASE_LLVM_VERSION)
6+
set(OPENCL_CLANG_VERSION ${BASE_LLVM_VERSION}.0)
7+
8+
if(NOT DEFINED OPENCL_CLANG_BUILD_EXTERNAL)
9+
# check if we build inside llvm or not
10+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
11+
set(OPENCL_CLANG_BUILD_EXTERNAL YES)
12+
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
13+
endif(NOT DEFINED OPENCL_CLANG_BUILD_EXTERNAL)
14+
15+
if(OPENCL_CLANG_BUILD_EXTERNAL)
16+
project(OPENCL_CLANG
17+
VERSION
18+
${OPENCL_CLANG_VERSION}
19+
LANGUAGES
20+
CXX
21+
C
22+
)
23+
endif()
24+
425
# Do not omit TARGET_OBJECTS expression from the SOURCES target
526
# property
627
# `cmake --help-policy CMP0051` for details.
@@ -14,7 +35,7 @@ set(CMAKE_MODULE_PATH
1435

1536
include(CMakeFunctions)
1637

17-
if(LLVM_USE_HOST_TOOLS)
38+
if(LLVM_USE_HOST_TOOLS AND OPENCL_CLANG_BUILD_EXTERNAL)
1839
include(CrossCompile)
1940
llvm_create_cross_target(${PROJECT_NAME} NATIVE "" Release)
2041
endif()

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ To build opencl-clang as a standalone project, you need to obtain pre-built LLVM
5252
and SPIR-V Translator libraries. **Note:** currently this kind of build is
5353
supported on Linux only.
5454

55+
If opencl-clang is used as part of another CMake project, you will need to define `OPENCL_CLANG_BUILD_EXTERNAL`.
56+
5557
Integration with pre-built LLVM is done using standard `find_package` way as
5658
documented in [Embedding LLVM in your project](https://llvm.org/docs/CMake.html#embedding-llvm-in-your-project).
5759

cl_headers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(CL_HEADERS_LIB cl_headers)
22
set(CLANG_COMMAND $<TARGET_FILE:clang> )
3-
if(LLVM_USE_HOST_TOOLS)
3+
if(LLVM_USE_HOST_TOOLS AND NOT OPENCL_CLANG_BUILD_EXTERNAL)
44
build_native_tool(clang CLANG_COMMAND)
55
endif()
66

0 commit comments

Comments
 (0)