Skip to content

Commit

Permalink
Update the code that import the builtins include
Browse files Browse the repository at this point in the history
Take the change from the woboq codebrowser
  • Loading branch information
ogoffart committed Jan 9, 2018
1 parent b044fd3 commit 89b5e10
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,29 @@ if (APPLE)
endif()



# Embed the clang header into the binary:
exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE LLVM_VERSION )
string(REPLACE "svn" "" LLVM_VERSION "${LLVM_VERSION}")
file(GLOB BUILTINS_HEADERS "${LLVM_BIN_DIR}/../lib/clang/${LLVM_VERSION}/include/*.h")
string(REGEX REPLACE "git.*$" "" LLVM_VERSION "${LLVM_VERSION}")
if(NOT CLANG_BUILTIN_HEADERS_DIR)
set(CLANG_BUILTIN_HEADERS_DIR "${LLVM_BIN_DIR}/../lib/clang/${LLVM_VERSION}/include")
endif()
file(GLOB BUILTINS_HEADERS "${CLANG_BUILTIN_HEADERS_DIR}/*.h")
if(NOT BUILTINS_HEADERS)
message(FATAL_ERROR "Could not find any clang builtins headers in ${CLANG_BUILTIN_HEADERS_DIR}")
endif()
foreach(BUILTIN_HEADER ${BUILTINS_HEADERS})
file(READ ${BUILTIN_HEADER} BINARY_DATA HEX)
string(REGEX REPLACE "(..)" "\\\\x\\1" BINARY_DATA "${BINARY_DATA}")
string(REPLACE "${LLVM_BIN_DIR}/../lib/clang/${LLVM_VERSION}/include/" "/builtins/" FN "${BUILTIN_HEADER}" )
set(EMBEDDED_DATA "${EMBEDDED_DATA} { \"${FN}\" , \"${BINARY_DATA}\" } , ")
#filter files that are way to big
if(NOT BUILTIN_HEADER MATCHES ".*/(arm_neon.h|altivec.h|vecintrin.h|avx512.*intrin.h)")
file(READ ${BUILTIN_HEADER} BINARY_DATA)
string(REPLACE "\\" "\\\\" BINARY_DATA "${BINARY_DATA}")
string(REPLACE "\"" "\\\"" BINARY_DATA "${BINARY_DATA}")
string(REPLACE "\n" "\\n\"\n\"" BINARY_DATA "${BINARY_DATA}")
#workaround the fact that stdint.h includes itself
string(REPLACE "__CLANG_STDINT_H" "__CLANG_STDINT_H2" BINARY_DATA "${BINARY_DATA}")
string(REPLACE "${CLANG_BUILTIN_HEADERS_DIR}/" "/builtins/" FN "${BUILTIN_HEADER}" )
set(EMBEDDED_DATA "${EMBEDDED_DATA} { \"${FN}\" , \"${BINARY_DATA}\" } , \n")
endif()
endforeach()

configure_file(embedded_includes.h.in embedded_includes.h)
Expand Down

0 comments on commit 89b5e10

Please sign in to comment.