Index: llvm/CMakeLists.txt =================================================================== --- llvm/CMakeLists.txt +++ llvm/CMakeLists.txt @@ -513,6 +513,10 @@ option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF) endif() +if(NOT WIN32) + option(LLVM_BUILD_CET_ENABLE "Build executables and libraries with CET enabled." OFF) +endif() + # Define the default arguments to use with 'lit', and an option for the user to # override. set(LIT_ARGS_DEFAULT "-sv") Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -366,6 +366,17 @@ endif( LLVM_BUILD_32_BITS ) endif( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 ) +# To enable CET in compilation, "-fcf-protection=full" should +# be added. Currently, CET has been implemented in x86 GNU/Linux target. +if(NOT WIN32) + if( LLVM_BUILD_CET_ENABLE) + add_flag_if_supported("-fcf-protection=full" CET) + if((NOT C_SUPPORTS_CET) OR (NOT CXX_SUPPORTS_CET)) + message(FATAL_ERROR "The compiler used for building doesn't support CET!") + endif() + endif( LLVM_BUILD_CET_ENABLE) +endif() + # If building on a GNU specific 32-bit system, make sure off_t is 64 bits # so that off_t can stored offset > 2GB. # Android until version N (API 24) doesn't support it. Index: llvm/cmake/modules/LLVMConfig.cmake.in =================================================================== --- llvm/cmake/modules/LLVMConfig.cmake.in +++ llvm/cmake/modules/LLVMConfig.cmake.in @@ -74,6 +74,8 @@ set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@) +set(LLVM_BUILD_CET_ENABLE @LLVM_BUILD_CET_ENABLE@) + if (NOT "@LLVM_PTHREAD_LIB@" STREQUAL "") set(LLVM_PTHREAD_LIB "@LLVM_PTHREAD_LIB@") endif() Index: llvm/docs/CMake.rst =================================================================== --- llvm/docs/CMake.rst +++ llvm/docs/CMake.rst @@ -250,6 +250,10 @@ Build 32-bit executables and libraries on 64-bit systems. This option is available only on some 64-bit Unix systems. Defaults to OFF. +**LLVM_BUILD_CET_ENABLE**:BOOL + Build executables and libraries with CET enabled. CET is currently implemented + in x86 GNU/Linux target. Defaults to OFF. + **LLVM_BUILD_BENCHMARKS**:BOOL Adds benchmarks to the list of default targets. Defaults to OFF.