Skip to content

Commit 9261a88

Browse files
committed
add clang and sys includes file
1 parent a2c93b0 commit 9261a88

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(CMAKE_BUILD_TYPE Debug)
66
set(CMAKE_CXX_STANDARD 14)
77

88
find_package(LLVM 3.9 REQUIRED CONFIG)
9+
find_package(Clang REQUIRED CONFIG)
10+
911
find_package(PythonLibs 2.7)
1012

1113
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} @ ${LLVM_DIR}")
@@ -41,13 +43,22 @@ if (${PYTHONLIBS_FOUND})
4143
COMMAND clang -E ${LLVM_DEFINITIONS} -isystem ${LLVM_INCLUDE_DIRS} "${LLVM_INCLUDE_DIRS}/llvm-c/Core.h" | python "${CMAKE_SOURCE_DIR}/fcd/python/bindings.py" > ${pythonbindingsfile})
4244
endif()
4345

46+
### header search paths file ###
47+
execute_process(COMMAND clang++ -E -x c++ -v /dev/null OUTPUT_VARIABLE dummy ERROR_VARIABLE defaultHeaderSearchPathList)
48+
string(REGEX REPLACE ".*#include <...> search starts here:\n(.+)\nEnd of search list.*" "\\1" defaultHeaderSearchPathList "${defaultHeaderSearchPathList}")
49+
string(REGEX REPLACE " (/[^\n]+)" "\"\\1\"," defaultHeaderSearchPathList "${defaultHeaderSearchPathList}")
50+
set(defaultFrameworkSearchPathList)
51+
configure_file(fcd/systemIncludePath.c.tmpl "${CMAKE_CURRENT_BINARY_DIR}/systemIncludePath.c")
52+
53+
4454
# collect files
4555
file(GLOB_RECURSE sources fcd/*.cpp)
4656
file(GLOB_RECURSE headers fcd/*.h)
57+
4758
# remove emulators
4859
string(REGEX REPLACE "[^;]+.emulator.cpp;?" "" sources "${sources}")
4960

50-
add_executable(fcd ${sources} ${headers} $<TARGET_OBJECTS:emu> ${pythonbindingsfile})
61+
add_executable(fcd ${sources} ${headers} $<TARGET_OBJECTS:emu> ${pythonbindingsfile} "${CMAKE_CURRENT_BINARY_DIR}/systemIncludePath.c")
5162

5263
# NDEBUG must match llvm's build or it will crash
5364
if (${LLVM_ENABLE_ASSERTIONS})
@@ -64,7 +75,7 @@ target_compile_options(fcd PRIVATE -Wall -Werror=conversion -Wno-error=sign-conv
6475
target_compile_options(fcd PRIVATE -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections)
6576

6677
llvm_map_components_to_libnames(llvm_libs core analysis instcombine ipo irreader scalaropts transformutils vectorize support)
67-
target_link_libraries(fcd ${llvm_libs} capstone -Wl,--gc-sections)
78+
target_link_libraries(fcd ${llvm_libs} clangIndex clangCodeGen libclang capstone -Wl,--gc-sections)
6879

6980
if (${PYTHONLIBS_FOUND})
7081
set_source_files_properties(${pythonbindingsfile} PROPERTIES COMPILE_FLAGS -w)

fcd/systemIncludePath.c.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const char* defaultHeaderSearchPathList[] = {
2+
${defaultHeaderSearchPathList}
3+
0
4+
};
5+
const char* defaultFrameworkSearchPathList[] = {
6+
${defaultFrameworkSearchPathList}
7+
0
8+
};

0 commit comments

Comments
 (0)