diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b9fd9ec..0143d92c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ if (NOT WIN32) endif() use_rtti(FALSE) +use_eh(TRUE) if (CMAKE_SIZEOF_VOID_P EQUAL 4) set(ADDR 32) @@ -284,51 +285,15 @@ else() ) endif() -add_llvm_library(${TARGET_NAME} SHARED - ${TARGET_INCLUDE_FILES} - ${TARGET_SOURCE_FILES} - $ +add_library(${TARGET_NAME} SHARED + ${TARGET_INCLUDE_FILES} + ${TARGET_SOURCE_FILES} + $ +) - 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 @@ -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) diff --git a/cmake/modules/CMakeFunctions.cmake b/cmake/modules/CMakeFunctions.cmake index 858e01a8..c15afee5 100644 --- a/cmake/modules/CMakeFunctions.cmake +++ b/cmake/modules/CMakeFunctions.cmake @@ -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 ) @@ -22,13 +22,7 @@ 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 ) @@ -36,6 +30,12 @@ macro(use_eh val) 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) diff --git a/common_clang.cpp b/common_clang.cpp index 279ff99c..0fd1b2ab 100644 --- a/common_clang.cpp +++ b/common_clang.cpp @@ -135,7 +135,7 @@ static bool GetHeaders(std::vector &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; } @@ -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(); diff --git a/windows_resource_file.rc b/windows_resource_file.rc deleted file mode 100644 index 6a0ca8de..00000000 --- a/windows_resource_file.rc +++ /dev/null @@ -1,91 +0,0 @@ -// This file was copied from LLVM_SOURCE_DIR/resources/windows_version_resource.rc - -// Microsoft Visual C++ resource script for embedding version information. -// The format is described at: -// http://msdn.microsoft.com/en-gb/library/windows/desktop/aa380599(v=vs.85).aspx -// The VERSIONINFO resource is described at: -// https://msdn.microsoft.com/en-gb/library/windows/desktop/aa381058(v=vs.85).aspx - - -// Default values for required fields. - -#ifndef RC_VERSION_FIELD_1 -#define RC_VERSION_FIELD_1 0 -#endif - -#ifndef RC_VERSION_FIELD_2 -#define RC_VERSION_FIELD_2 0 -#endif - -#ifndef RC_VERSION_FIELD_3 -#define RC_VERSION_FIELD_3 0 -#endif - -#ifndef RC_VERSION_FIELD_4 -#define RC_VERSION_FIELD_4 0 -#endif - -#ifndef RC_COMPANY_NAME -#define RC_COMPANY_NAME "" -#endif - -#ifndef RC_FILE_DESCRIPTION -#define RC_FILE_DESCRIPTION "" -#endif - -#ifndef RC_FILE_VERSION -#define RC_FILE_VERSION "" -#endif - -#ifndef RC_INTERNAL_NAME -#define RC_INTERNAL_NAME "" -#endif - -#ifndef RC_ORIGINAL_FILENAME -#define RC_ORIGINAL_FILENAME "" -#endif - -#ifndef RC_PRODUCT_NAME -#define RC_PRODUCT_NAME "" -#endif - -#ifndef RC_PRODUCT_VERSION -#define RC_PRODUCT_VERSION "" -#endif - - -1 VERSIONINFO -FILEVERSION RC_VERSION_FIELD_1,RC_VERSION_FIELD_2,RC_VERSION_FIELD_3,RC_VERSION_FIELD_4 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904B0" - BEGIN - // Required strings - VALUE "CompanyName", RC_COMPANY_NAME - VALUE "FileDescription", RC_FILE_DESCRIPTION - VALUE "FileVersion", RC_FILE_VERSION - VALUE "InternalName", RC_INTERNAL_NAME - VALUE "OriginalFilename", RC_ORIGINAL_FILENAME - VALUE "ProductName", RC_PRODUCT_NAME - VALUE "ProductVersion", RC_PRODUCT_VERSION - - // Optional strings -#ifdef RC_COMMENTS - VALUE "Comments", RC_COMMENTS -#endif - -#ifdef RC_COPYRIGHT - VALUE "LegalCopyright", RC_COPYRIGHT -#endif - END - END - - BLOCK "VarFileInfo" - BEGIN - // The translation must correspond to the above BLOCK inside StringFileInfo - // langID 0x0409 U.S. English - // charsetID 0x04B0 Unicode - VALUE "Translation", 0x0409, 0x04B0 - END -END \ No newline at end of file