|
| 1 | +# Location of the isl submodule. |
| 2 | +SET(ISL_DIR "${PROJECT_SOURCE_DIR}/third-party/islpp") |
| 3 | +# Location of extract_interface source files. |
| 4 | +SET(ISL_INTERFACE_DIR "${ISL_DIR}/interface") |
| 5 | + |
| 6 | +add_definitions(-DCLANG_PREFIX="${CLANG_PREFIX}") |
| 7 | + |
| 8 | +# Hard-coded defines for LLVM/clang 5.0.0 |
| 9 | +add_definitions(-DADDPATH_TAKES_4_ARGUMENTS) |
| 10 | +add_definitions(-DCREATETARGETINFO_TAKES_SHARED_PTR) |
| 11 | +add_definitions(-DCREATEPREPROCESSOR_TAKES_TUKIND) |
| 12 | +add_definitions(-DHAVE_BASIC_DIAGNOSTICOPTIONS_H) |
| 13 | +add_definitions(-DHAVE_LEX_PREPROCESSOROPTIONS_H) |
| 14 | +add_definitions(-DHAVE_SETMAINFILEID) |
| 15 | +add_definitions(-DSETINVOCATION_TAKES_SHARED_PTR) |
| 16 | +add_definitions(-DSETLANGDEFAULTS_TAKES_5_ARGUMENTS) |
| 17 | +add_definitions(-DUSE_ARRAYREF) |
| 18 | +add_definitions(-DgetNumArgs=getNumParams) |
| 19 | +add_definitions(-DgetArgType=getParamType) |
| 20 | +add_definitions(-DHandleTopLevelDeclReturn=bool) |
| 21 | +add_definitions(-DHandleTopLevelDeclContinue=true) |
| 22 | +add_definitions(-DIK_C=InputKind::C) |
| 23 | + |
| 24 | +find_library(CLANG_FRONTEND_LIB REQUIRED clangFrontend |
| 25 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 26 | +find_library(CLANG_SERIALIZATION_LIB REQUIRED clangSerialization |
| 27 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 28 | +find_library(CLANG_PARSE_LIB REQUIRED clangParse |
| 29 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 30 | +find_library(CLANG_SEMA_LIB REQUIRED clangSema |
| 31 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 32 | +find_library(CLANG_EDIT_LIB REQUIRED clangEdit |
| 33 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 34 | +find_library(CLANG_ANALYSIS_LIB REQUIRED clangAnalysis |
| 35 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 36 | +find_library(CLANG_AST_LIB REQUIRED clangAST |
| 37 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 38 | +find_library(CLANG_LEX_LIB REQUIRED clangLex |
| 39 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 40 | +find_library(CLANG_BASIC_LIB REQUIRED clangBasic |
| 41 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 42 | +find_library(CLANG_DRIVER_LIB REQUIRED clangDriver |
| 43 | + ${CLANG_PREFIX} PATH_SUFFIXES lib) |
| 44 | + |
| 45 | +SET(CLANG_LIBRARIES |
| 46 | + "${CLANG_FRONTEND_LIB}" |
| 47 | + "${CLANG_SERIALIZATION_LIB}" |
| 48 | + "${CLANG_PARSE_LIB}" |
| 49 | + "${CLANG_SEMA_LIB}" |
| 50 | + "${CLANG_EDIT_LIB}" |
| 51 | + "${CLANG_ANALYSIS_LIB}" |
| 52 | + "${CLANG_AST_LIB}" |
| 53 | + "${CLANG_LEX_LIB}" |
| 54 | + "${CLANG_BASIC_LIB}" |
| 55 | + "${CLANG_DRIVER_LIB}" |
| 56 | +) |
| 57 | + |
| 58 | +find_program(LLVM_CONFIG_BIN llvm-config PATHS ${CLANG_PREFIX} |
| 59 | + PATH_SUFFIXES bin |
| 60 | + NO_DEFAULT_PATH) |
| 61 | + |
| 62 | +# The process of finding the right libraries to link against |
| 63 | +# is based on isl's m4/ax_detect_clang.m4. |
| 64 | +execute_process(COMMAND |
| 65 | + "${LLVM_CONFIG_BIN}" --targets-built |
| 66 | + OUTPUT_VARIABLE LLVM_TARGETS OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 67 | +SET(LLVM_COMPONENTS ${LLVM_TARGETS} asmparser bitreader support mc option) |
| 68 | +execute_process(COMMAND |
| 69 | + "${LLVM_CONFIG_BIN}" --libs ${LLVM_COMPONENTS} |
| 70 | + OUTPUT_VARIABLE LLVM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 71 | +execute_process(COMMAND |
| 72 | + "${LLVM_CONFIG_BIN}" --system-libs |
| 73 | + OUTPUT_VARIABLE LLVM_SYSTEM_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 74 | + |
| 75 | +# Add current directory for mock isl_config.h |
| 76 | +include_directories(.) |
| 77 | +add_executable(extract_isl_interface |
| 78 | + ${ISL_INTERFACE_DIR}/cpp.cc |
| 79 | + ${ISL_INTERFACE_DIR}/extract_interface.cc |
| 80 | + ${ISL_INTERFACE_DIR}/generator.cc |
| 81 | + ${ISL_INTERFACE_DIR}/python.cc |
| 82 | +) |
| 83 | +target_link_libraries(extract_isl_interface |
| 84 | + "${CLANG_LIBRARIES}" ${LLVM_LIBS} ${LLVM_SYSTEM_LIBS}) |
| 85 | + |
| 86 | +# Dummy library to ensure that C++ bindings depend on contents of header files. |
| 87 | +add_library(isl_all_h_dep STATIC ${ISL_DIR}/all.c) |
| 88 | + |
| 89 | +SET(ISL_CPP_H "${CMAKE_CURRENT_LIST_DIR}/include/isl/cpp.h") |
| 90 | +add_custom_command( |
| 91 | + OUTPUT ${ISL_CPP_H} |
| 92 | + DEPENDS isl_all_h_dep |
| 93 | + DEPENDS ${ISL_DIR}/cpp/cpp.h.top |
| 94 | + DEPENDS ${ISL_DIR}/cpp/cpp.h.pre |
| 95 | + DEPENDS ${ISL_DIR}/all.h |
| 96 | + DEPENDS ${ISL_DIR}/cpp/cpp.h.bot |
| 97 | + COMMAND mkdir -p ${CMAKE_CURRENT_LIST_DIR}/include/isl |
| 98 | + COMMAND cat ${ISL_DIR}/cpp/cpp.h.top > ${ISL_CPP_H} || exit 1 |
| 99 | + # Turn off reformatting on this generated file. |
| 100 | + COMMAND echo "// clang-format off" >> ${ISL_CPP_H} || exit 1 |
| 101 | + COMMAND cat ${ISL_DIR}/all.h >> ${ISL_CPP_H} || exit 1 |
| 102 | + COMMAND cat ${ISL_DIR}/cpp/cpp.h.pre >> ${ISL_CPP_H} || exit 1 |
| 103 | + COMMAND extract_isl_interface --language=cpp |
| 104 | + -I${ISL_DIR}/include ${ISL_DIR}/all.h |
| 105 | + -I${CMAKE_CURRENT_LIST_DIR} >> ${ISL_CPP_H} || exit 1 |
| 106 | + COMMAND cat ${ISL_DIR}/cpp/cpp.h.bot >> ${ISL_CPP_H} || exit 1 |
| 107 | + DEPENDS extract_isl_interface |
| 108 | +) |
| 109 | +# generate_isl_cpp_h is the dependency that should be used |
| 110 | +# by code that depends on the isl C++ bindings. |
| 111 | +add_custom_target(generate_isl_cpp_h DEPENDS ${ISL_CPP_H}) |
0 commit comments