[Beignet] [PATCH] GBE: fix relocatable issue for pch file.
Zhigang Gong
zhigang.gong at intel.com
Mon Nov 10 21:59:52 PST 2014
When we use pch file, we need to provide the orignal header files.
Otherwise, clang may complain errors. Clang provide a compile option
--relocatable-pch to enable pch/header files relocation. We have to
use this option when we want to install the header files/pch file
into system diretory.
Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
backend/src/CMakeLists.txt | 20 ++++++------
backend/src/libocl/CMakeLists.txt | 64 ++++++++++++++++++++++-----------------
2 files changed, 47 insertions(+), 37 deletions(-)
diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index dacc3a1..b4555f1 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -1,21 +1,21 @@
set (OCL_BITCODE_BIN "${BEIGNET_INSTALL_DIR}beignet.bc")
-set (OCL_HEADER_DIR "${CMAKE_INSTALL_PREFIX}/include/CL/ocl/")
+set (OCL_HEADER_DIR "${BEIGNET_INSTALL_DIR}/include")
set (OCL_PCH_OBJECT "${BEIGNET_INSTALL_DIR}beignet.pch")
set (GBE_OBJECT_DIR "${BEIGNET_INSTALL_DIR}/libgbe.so")
set (INTERP_OBJECT_DIR "${BEIGNET_INSTALL_DIR}/libgbeinterp.so")
-set (LOCAL_GBE_OBJECT_DIR "${CMAKE_CURRENT_BINARY_DIR}/libgbe.so" PARENT_SCOPE)
-set (LOCAL_OCL_BITCODE_BIN "${CMAKE_CURRENT_BINARY_DIR}/libocl/lib/beignet.bc" PARENT_SCOPE)
-set (LOCAL_OCL_HEADER_DIR "${CMAKE_CURRENT_BINARY_DIR}/libocl/include/" PARENT_SCOPE)
-set (LOCAL_OCL_PCH_OBJECT "${CMAKE_CURRENT_BINARY_DIR}/libocl/lib/beignet.pch" PARENT_SCOPE)
-set (LOCAL_INTERP_OBJECT_DIR "${CMAKE_CURRENT_BINARY_DIR}/libgbeinterp.so" PARENT_SCOPE)
-
configure_file (
"GBEConfig.h.in"
"GBEConfig.h"
)
add_subdirectory(libocl)
+set (LOCAL_GBE_OBJECT_DIR "${CMAKE_CURRENT_BINARY_DIR}/libgbe.so" PARENT_SCOPE)
+set (LOCAL_INTERP_OBJECT_DIR "${CMAKE_CURRENT_BINARY_DIR}/libgbeinterp.so" PARENT_SCOPE)
+set (LOCAL_OCL_BITCODE_BIN "${OCL_OBJECT_DIR}/beignet.bc" PARENT_SCOPE)
+set (LOCAL_OCL_HEADER_DIR "${OCL_OBJECT_DIR}/include/" PARENT_SCOPE)
+set (LOCAL_OCL_PCH_OBJECT "${OCL_OBJECT_DIR}/beignet.local.pch" PARENT_SCOPE)
+
add_dependencies(beignet_bitcode libocl)
set (GBE_SRC
@@ -154,6 +154,6 @@ TARGET_LINK_LIBRARIES(gbe_bin_generater gbe)
install (TARGETS gbe LIBRARY DESTINATION ${BEIGNET_INSTALL_DIR})
install (TARGETS gbeinterp LIBRARY DESTINATION ${BEIGNET_INSTALL_DIR})
-install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libocl/lib/beignet.bc DESTINATION ${BEIGNET_INSTALL_DIR})
-install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libocl/lib/beignet.pch DESTINATION ${BEIGNET_INSTALL_DIR})
-install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libocl/include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/CL/ocl/ PATTERN *.h)
+install (FILES ${OCL_OBJECT_DIR}/beignet.bc DESTINATION ${BEIGNET_INSTALL_DIR})
+install (FILES ${OCL_OBJECT_DIR}/beignet.pch DESTINATION ${BEIGNET_INSTALL_DIR})
+install (FILES ${OCL_HEADER_FILES} DESTINATION ${BEIGNET_INSTALL_DIR}/include)
diff --git a/backend/src/libocl/CMakeLists.txt b/backend/src/libocl/CMakeLists.txt
index b0074b3..3e0938a 100644
--- a/backend/src/libocl/CMakeLists.txt
+++ b/backend/src/libocl/CMakeLists.txt
@@ -1,14 +1,14 @@
PROJECT(LIBOCL)
-
-SET (OCL_HEADER_FILES ${LIBOCL_BINARY_DIR}/include/ocl_defines.h)
+SET (OCL_OBJECT_DIR ${LIBOCL_BINARY_DIR}/${BEIGNET_INSTALL_DIR})
+SET (OCL_HEADER_FILES ${OCL_OBJECT_DIR}/include/ocl_defines.h)
SET (OCL_SOURCE_FILES "")
-ADD_CUSTOM_COMMAND(OUTPUT ${LIBOCL_BINARY_DIR}/include/ocl_defines.h
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/include/
+ADD_CUSTOM_COMMAND(OUTPUT ${OCL_OBJECT_DIR}/include/ocl_defines.h
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}/include/
# COMMAND echo "cat ${LIBOCL_SOURCE_DIR}/tmpl/ocl_defines.tmpl.h \\> ${LIBOCL_BINARY_DIR}/include/ocl_defines.h"
- COMMAND cat ${LIBOCL_SOURCE_DIR}/tmpl/ocl_defines.tmpl.h > ${LIBOCL_BINARY_DIR}/include/ocl_defines.h
+ COMMAND cat ${LIBOCL_SOURCE_DIR}/tmpl/ocl_defines.tmpl.h > ${OCL_OBJECT_DIR}/include/ocl_defines.h
# COMMAND echo "cat ${LIBOCL_SOURCE_DIR}/../ocl_common_defines.h \\>\\> ${LIBOCL_BINARY_DIR}/include/ocl_defines.h"
- COMMAND cat ${LIBOCL_SOURCE_DIR}/../ocl_common_defines.h >> ${LIBOCL_BINARY_DIR}/include/ocl_defines.h
+ COMMAND cat ${LIBOCL_SOURCE_DIR}/../ocl_common_defines.h >> ${OCL_OBJECT_DIR}/include/ocl_defines.h
DEPENDS ${LIBOCL_SOURCE_DIR}/tmpl/ocl_defines.tmpl.h ${LIBOCL_SOURCE_DIR}/../ocl_common_defines.h
COMMENT "Generate the header: ${LIBOCL_BINARY_DIR}/include/ocl_defines.h"
)
@@ -16,13 +16,13 @@ ADD_CUSTOM_COMMAND(OUTPUT ${LIBOCL_BINARY_DIR}/include/ocl_defines.h
#other module just copy.
MACRO(COPY_THE_HEADER _mod)
# Use the python script to generate the header files.
- STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_BINARY_DIR}/include/\\1.h" output_name ${_mod})
+ STRING(REGEX REPLACE "\(o.*\)" "${OCL_OBJECT_DIR}/include/\\1.h" output_name ${_mod})
STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_SOURCE_DIR}/include/\\1.h" orgin_name ${_mod})
SET(OCL_HEADER_FILES ${OCL_HEADER_FILES} ${output_name})
IF(orgin_name STREQUAL output_name)
ELSE(orgin_name STREQUAL output_name)
ADD_CUSTOM_COMMAND(OUTPUT ${output_name}
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/include/
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}/include/
#COMMAND echo "cp ${orgin_name} ${output_name}"
COMMAND cp ${orgin_name} ${output_name}
DEPENDS ${orgin_name}
@@ -60,12 +60,12 @@ ENDFOREACH(M)
MACRO(GENERATE_HEADER_PY _mod)
- STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_BINARY_DIR}/include/\\1.h" output_name ${_mod})
+ STRING(REGEX REPLACE "\(o.*\)" "${OCL_OBJECT_DIR}/include/\\1.h" output_name ${_mod})
STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_SOURCE_DIR}/tmpl/\\1.tmpl.h" tmpl_name ${_mod})
STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_SOURCE_DIR}/script/\\1.def" def_name ${_mod})
SET(OCL_HEADER_FILES ${OCL_HEADER_FILES} ${output_name})
ADD_CUSTOM_COMMAND(OUTPUT ${output_name}
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/include/
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}/include/
#COMMAND echo "cat ${tmpl_name} \\> ${output_name}"
COMMAND cat ${tmpl_name} > ${output_name}
#COMMAND echo "${LIBOCL_SOURCE_DIR}/script/gen_vector.py ${def_name} ${output_name} 1"
@@ -99,11 +99,11 @@ ENDFOREACH(M)
MACRO(GENERATE_HEADER_BASH _mod)
# Use the python script to generate the header files.
- STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_BINARY_DIR}/include/\\1.h" output_name ${_mod})
+ STRING(REGEX REPLACE "\(o.*\)" "${OCL_OBJECT_DIR}/include/\\1.h" output_name ${_mod})
STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_SOURCE_DIR}/script/\\1.sh" sh_name ${_mod})
SET(OCL_HEADER_FILES ${OCL_HEADER_FILES} ${output_name})
ADD_CUSTOM_COMMAND(OUTPUT ${output_name}
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/include/
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}/include/
COMMAND ${sh_name} -p > ${output_name}
DEPENDS ${sh_name}
COMMENT "Generate the header by script: ${output_name}"
@@ -132,11 +132,11 @@ ENDFOREACH(M)
SET (CLANG_OCL_FLAGS -fno-builtin -ffp-contract=off -cl-kernel-arg-info -DGEN7_SAMPLER_CLAMP_BORDER_WORKAROUND "-cl-std=CL1.2")
MACRO(ADD_CL_TO_BC_TARGET _file)
# CMake seems can not add pattern rule, use MACRO to replace.
- STRING(REGEX REPLACE "${LIBOCL_BINARY_DIR}/src/\(o.*\)\\.cl" "${LIBOCL_BINARY_DIR}/lib/\\1.bc" output_name ${_file})
+ STRING(REGEX REPLACE "${LIBOCL_BINARY_DIR}/src/\(o.*\)\\.cl" "${OCL_OBJECT_DIR}/\\1.bc" output_name ${_file})
ADD_CUSTOM_COMMAND(OUTPUT ${output_name}
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/lib/
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}/
#COMMAND echo ${LLVM_INSTALL_DIR}clang -cc1 ${CLANG_OCL_FLAGS} -I ${LIBOCL_BINARY_DIR}/include/ -emit-llvm-bc -triple spir -o ${output_name} -x cl ${_file}
- COMMAND ${LLVM_INSTALL_DIR}clang -cc1 ${CLANG_OCL_FLAGS} -I ${LIBOCL_BINARY_DIR}/include/ -emit-llvm-bc -triple spir -o ${output_name} -x cl ${_file}
+ COMMAND ${LLVM_INSTALL_DIR}clang -cc1 ${CLANG_OCL_FLAGS} -I ${OCL_OBJECT_DIR}/include/ -emit-llvm-bc -triple spir -o ${output_name} -x cl ${_file}
DEPENDS ${_file} ${OCL_HEADER_FILES}
COMMENT "Compiling ${_file}"
)
@@ -148,7 +148,7 @@ FOREACH(f ${OCL_SOURCE_FILES})
ENDFOREACH(f)
FOREACH(f ${OCL_SOURCE_FILES})
- STRING(REGEX REPLACE "${LIBOCL_BINARY_DIR}/src/\(o.*\)\\.cl" "${LIBOCL_BINARY_DIR}/lib/\\1.bc" bc_name ${f})
+ STRING(REGEX REPLACE "${LIBOCL_BINARY_DIR}/src/\(o.*\)\\.cl" "${OCL_OBJECT_DIR}/\\1.bc" bc_name ${f})
SET(OCL_BC_FILES ${OCL_BC_FILES} ${bc_name})
ENDFOREACH(f)
@@ -170,10 +170,10 @@ MACRO(COPY_THE_LL _mod)
ENDIF(orgin_name STREQUAL output_name)
ENDMACRO(COPY_THE_LL)
MACRO(ADD_LL_TO_BC_TARGET M)
- STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_BINARY_DIR}/lib/\\1.bc" output_name ${M})
+ STRING(REGEX REPLACE "\(o.*\)" "${OCL_OBJECT_DIR}/\\1.bc" output_name ${M})
STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_BINARY_DIR}/src/\\1.ll" srcll_name ${M})
ADD_CUSTOM_COMMAND(OUTPUT ${output_name}
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/lib/
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}/
#COMMAND echo ${LLVM_INSTALL_DIR}llvm-as -o ${output_name} ${srcll_name}
COMMAND ${LLVM_INSTALL_DIR}llvm-as -o ${output_name} ${srcll_name}
DEPENDS ${srcll_name}
@@ -185,24 +185,34 @@ SET (OCL_LL_MODULES ocl_barrier ocl_memcpy ocl_memset)
FOREACH(f ${OCL_LL_MODULES})
COPY_THE_LL(${f})
ADD_LL_TO_BC_TARGET(${f})
- STRING(REGEX REPLACE "\(o.*\)" "${LIBOCL_BINARY_DIR}/lib/\\1.bc" bc_name ${f})
+ STRING(REGEX REPLACE "\(o.*\)" "${OCL_OBJECT_DIR}/\\1.bc" bc_name ${f})
SET(OCL_BC_FILES ${OCL_BC_FILES} ${bc_name})
ENDFOREACH(f)
-ADD_CUSTOM_COMMAND(OUTPUT ${LIBOCL_BINARY_DIR}/lib/beignet.bc
+ADD_CUSTOM_COMMAND(OUTPUT ${OCL_OBJECT_DIR}/beignet.bc
COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/lib/
#COMMAND echo llvm-link -o ${LIBOCL_BINARY_DIR}/lib/beignet.bc ${OCL_BC_FILES}
- COMMAND ${LLVM_INSTALL_DIR}llvm-link -o ${LIBOCL_BINARY_DIR}/lib/beignet.bc ${OCL_BC_FILES}
+ COMMAND ${LLVM_INSTALL_DIR}llvm-link -o ${OCL_OBJECT_DIR}/beignet.bc ${OCL_BC_FILES}
DEPENDS ${OCL_BC_FILES}
- COMMENT "Generate the bitcode file: ${LIBOCL_BINARY_DIR}/lib/beignet.bc"
+ COMMENT "Generate the bitcode file: ${OCL_OBJECT_DIR}/beignet.bc"
)
-ADD_CUSTOM_COMMAND(OUTPUT ${LIBOCL_BINARY_DIR}/lib/beignet.pch
- COMMAND mkdir -p ${LIBOCL_BINARY_DIR}/lib/
- COMMAND ${LLVM_INSTALL_DIR}clang -cc1 ${CLANG_OCL_FLAGS} -triple spir -I ${LIBOCL_BINARY_DIR}/include/ -emit-pch -x cl ${LIBOCL_BINARY_DIR}/include/ocl.h -o ${LIBOCL_BINARY_DIR}/lib/beignet.pch
+ADD_CUSTOM_COMMAND(OUTPUT ${OCL_OBJECT_DIR}/beignet.pch
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}
+ COMMAND ${LLVM_INSTALL_DIR}clang -cc1 ${CLANG_OCL_FLAGS} -triple spir -I ${OCL_OBJECT_DIR}/include/ -emit-pch -x cl ${OCL_OBJECT_DIR}/include/ocl.h -o ${OCL_OBJECT_DIR}/beignet.pch
+ DEPENDS ${OCL_HEADER_FILES}
+ COMMENT "Generate the pch file: ${OCL_OBJECT_DIR}/beignet.pch"
+ )
+
+ADD_CUSTOM_COMMAND(OUTPUT ${OCL_OBJECT_DIR}/beignet.local.pch
+ COMMAND mkdir -p ${OCL_OBJECT_DIR}
+ COMMAND ${LLVM_INSTALL_DIR}clang -cc1 ${CLANG_OCL_FLAGS} -triple spir -I ${OCL_OBJECT_DIR}/include/ --relocatable-pch -emit-pch -isysroot ${LIBOCL_BINARY_DIR} -x cl ${OCL_OBJECT_DIR}/include/ocl.h -o ${OCL_OBJECT_DIR}/beignet.local.pch
DEPENDS ${OCL_HEADER_FILES}
- COMMENT "Generate the pch file: ${LIBOCL_BINARY_DIR}/lib/beignet.pch"
+ COMMENT "Generate the pch file: ${OCL_OBJECT_DIR}/beignet.local.pch"
)
-add_custom_target(beignet_bitcode ALL DEPENDS ${LIBOCL_BINARY_DIR}/lib/beignet.bc ${LIBOCL_BINARY_DIR}/lib/beignet.pch)
+
+add_custom_target(beignet_bitcode ALL DEPENDS ${OCL_OBJECT_DIR}/beignet.bc ${OCL_OBJECT_DIR}/beignet.pch ${OCL_OBJECT_DIR}/beignet.local.pch)
+SET (OCL_OBJECT_DIR ${OCL_OBJECT_DIR} PARENT_SCOPE)
+SET (OCL_HEADER_FILES ${OCL_HEADER_FILES} PARENT_SCOPE)
--
1.8.3.2
More information about the Beignet
mailing list