Skip to content

Update CMakeLists.txt #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 75 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if (NOT WIN32)
endif()

use_rtti(FALSE)
use_eh(TRUE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only need to enable exception on in opencl-clang tests


if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ADDR 32)
Expand Down Expand Up @@ -284,51 +285,15 @@ else()
)
endif()

add_llvm_library(${TARGET_NAME} SHARED
${TARGET_INCLUDE_FILES}
${TARGET_SOURCE_FILES}
$<TARGET_OBJECTS:cl_headers>
add_library(${TARGET_NAME} SHARED
${TARGET_INCLUDE_FILES}
${TARGET_SOURCE_FILES}
$<TARGET_OBJECTS:cl_headers>
)

DEPENDS CClangCompileOptions
LINK_COMPONENTS
all
LINK_LIBS
${OPENCL_CLANG_LINK_LIBS}
)
add_dependencies(${TARGET_NAME} CClangCompileOptions)

# Configure resource file on Windows
if (WIN32)
# windows_resource_file should be defined by llvm_add_library and should
# contain full patch to a .rc file
# It also might not be defined if this library is built out-of-tree:
# let's use our copy of .rc file from LLVM source tree in that case
if (NOT DEFINED windows_resource_file)
set(windows_resource_file windows_resource_file.rc)
endif(NOT DEFINED windows_resource_file)

set(RC_CHAR_TM "\\231")
set(RC_CHAR_C "\\251")
set(RC_CHAR_R "\\256")

set(RC_FILE_VERSION "${PRODUCT_VER_MAJOR}.${PRODUCT_VER_MINOR}.${LLVM_VER_MAJOR}.${LLVM_VER_MINOR}")
set(RC_PRODUCT_NAME "Intel${RC_CHAR_R} Front-end Library for OpenCL${RC_CHAR_TM} software")

# Adjust content of the resource file by specifying compile definitions
set_property(SOURCE ${windows_resource_file}
PROPERTY COMPILE_DEFINITIONS
"RC_VERSION_FIELD_1=${PRODUCT_VER_MAJOR}"
"RC_VERSION_FIELD_2=${PRODUCT_VER_MINOR}"
"RC_VERSION_FIELD_3=${LLVM_VER_MAJOR}"
"RC_VERSION_FIELD_4=${LLVM_VER_MINOR}"
"RC_COMPANY_NAME=\"Intel Corporation\""
"RC_FILE_DESCRIPTION=\"${RC_PRODUCT_NAME}\""
"RC_FILE_VERSION=\"${RC_FILE_VERSION}\""
"RC_INTERNAL_NAME=\"${TARGET_NAME}\""
"RC_ORIGINAL_FILENAME=\"${TARGET_NAME}.dll\""
"RC_PRODUCT_NAME=\"${RC_PRODUCT_NAME}\""
"RC_PRODUCT_VERSION=\"${RC_FILE_VERSION}\""
"RC_COPYRIGHT=\"Copyright ${RC_CHAR_C} 2018 Intel Corporation. All rights reserved.\"")

# Enable compiler generation of Control Flow Guard security checks.
target_compile_options(${TARGET_NAME} PUBLIC "/guard:cf")
set_property(TARGET ${TARGET_NAME} APPEND_STRING PROPERTY
Expand All @@ -342,10 +307,75 @@ elseif(UNIX)
LINK_FLAGS " -Wl,--no-undefined")
endif(WIN32)

# Enable new IN_LIST operator.
cmake_policy(SET CMP0057 NEW)
set(OTHER_LIBRARIES)
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
list(APPEND OTHER_LIBRARIES LLVMNVPTXCodeGen LLVMNVPTXDesc LLVMNVPTXInfo)
endif()
if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
list(APPEND OTHER_LIBRARIES LLVMAMDGPUCodeGen LLVMAMDGPUAsmParser LLVMAMDGPUDesc LLVMAMDGPUInfo)
endif()

target_link_libraries( ${TARGET_NAME}
LINK_PRIVATE
${OPENCL_CLANG_LINK_LIBS}
LLVMX86CodeGen
LLVMX86AsmParser
LLVMX86Desc
LLVMX86Info
LLVMX86Disassembler
LLVMAnalysis
LLVMCodeGen
LLVMCore
LLVMipo
LLVMInstCombine
LLVMInstrumentation
LLVMMC
LLVMMCParser
LLVMObjCARCOpts
LLVMOption
LLVMScalarOpts
LLVMSupport
LLVMTransformUtils
LLVMVectorize
LLVMAsmPrinter
LLVMSelectionDAG
LLVMMCDisassembler
LLVMProfileData
LLVMObject
LLVMBitWriter
LLVMIRReader
LLVMAsmParser
LLVMTarget
LLVMBitReader
${OTHER_LIBRARIES}
)

install(FILES common_clang.h
DESTINATION include/cclang
COMPONENT ${TARGET_NAME})

SET_LINUX_EXPORTS_FILE( ${TARGET_NAME} common_clang.map )

add_custom_target(deploy DEPENDS install-${TARGET_NAME})
#
# Stripped PDB files
#
if (WIN32)
get_target_property(RT_OUTPUT_DIRECTORY ${TARGET_NAME} RUNTIME_OUTPUT_DIRECTORY)
file(TO_NATIVE_PATH ${RT_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${TARGET_NAME}_stripped.pdb PDB_NAME)
if (${MSVC_VERSION} EQUAL 1500)
# Visual Studio 2008
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "${LINK_FLAGS} /PDBSTRIPPED:${PDB_NAME}")
else (${MSVC_VERSION} EQUAL 1500)
# Visual Studio 2010 (assumed if not Visual Studio 2008)
# This is a fix due to a bug in CMake, Does not add the flag /DEBUG to the linker flags in Release mode.
# The /DEBUG flag is required in order to create stripped pdbs.
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "${LINK_FLAGS_DEBUG} /PDBSTRIPPED:${PDB_NAME}")
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_RELEASE "${LINK_FLAGS_RELEASE} /DEBUG /PDBSTRIPPED:${PDB_NAME}")
endif (${MSVC_VERSION} EQUAL 1500)
if (INSTALL_PDBS)
install(FILES ${RT_OUTPUT_DIRECTORY}/\${BUILD_TYPE}/${TARGET_NAME}.pdb DESTINATION bin)
endif(INSTALL_PDBS)
install(FILES ${RT_OUTPUT_DIRECTORY}/\${BUILD_TYPE}/${TARGET_NAME}_stripped.pdb DESTINATION bin)
else (WIN32)
SET_LINUX_EXPORTS_FILE( ${TARGET_NAME} common_clang.map )
endif(WIN32)
26 changes: 13 additions & 13 deletions cmake/modules/CMakeFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# Set compiler RTTI options according to the given flag
#
macro(use_rtti val)
if( CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if (MSVC)
if( ${val} )
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-fno-rtti" "-frtti")
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR-" "/GR")
else()
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti" )
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-" )
endif()
else(MSVC)
else () # G++ or clang or icx
if( ${val} )
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR-" "/GR")
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-fno-rtti" "-frtti")
else()
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/GR" "/GR-" )
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "-frtti" "-fno-rtti" )
endif()
endif()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE )
Expand All @@ -22,20 +22,20 @@ endmacro(use_rtti)
# Set compiler Exception Handling options according to the given flag
#
macro(use_eh val)
if( CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if( ${val} )
remove_definitions( -fno-exceptions )
else()
add_definitions( -fno-exceptions )
endif()
else(MSVC)
if (MSVC)
if( ${val} )
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/EHs-c-" "/EHsc" )
add_definitions( /D_HAS_EXCEPTIONS=1 )
else()
llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/EHsc" "/EHs-c-")
add_definitions( /D_HAS_EXCEPTIONS=0 )
endif()
else () # G++ or clang or icx
if( ${val} )
remove_definitions( -fno-exceptions )
else()
add_definitions( -fno-exceptions )
endif()
endif()
endmacro(use_eh)

Expand Down
4 changes: 2 additions & 2 deletions common_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static bool GetHeaders(std::vector<Resource> &Result) {
for (auto Header : Headers) {
Resource R = RM.get_resource(Header.Name, Header.ID, "PCM", true);
if (!R) {
assert(0 && "Resource not found");
assert(false && "Resource not found");
return false;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
if (pBinaryResult) {
*pBinaryResult = nullptr;
}
assert(!"Failed to read just compiled LLVM IR!");
assert(false && "Failed to read just compiled LLVM IR!");
return CL_COMPILE_PROGRAM_FAILURE;
}
pResult->getIRBufferRef().clear();
Expand Down
91 changes: 0 additions & 91 deletions windows_resource_file.rc

This file was deleted.