Skip to content

Commit

Permalink
unittests/ThunkLibs: Specify clang resource directory when compiling …
Browse files Browse the repository at this point in the history
…test code
  • Loading branch information
neobrain committed Oct 2, 2023
1 parent 9ebbb17 commit 36fedfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ThunkLibs/Generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
find_package(Clang REQUIRED CONFIG)
find_package(OpenSSL REQUIRED COMPONENTS Crypto)

add_library(thunkgenlib analysis.cpp data_layout.cpp gen.cpp)
target_include_directories(thunkgenlib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(thunkgenlib SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
target_link_libraries(thunkgenlib PUBLIC clang-cpp LLVM)
target_link_libraries(thunkgenlib PRIVATE OpenSSL::Crypto)
target_link_libraries(thunkgenlib PRIVATE fmt::fmt)

# Query clang's global resource directory for system include directories
if (NOT CLANG_RESOURCE_DIR)
find_program(CLANG_EXEC_PATH clang REQUIRED)
Expand All @@ -18,6 +11,13 @@ if (NOT CLANG_RESOURCE_DIR)
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

add_library(thunkgenlib analysis.cpp data_layout.cpp gen.cpp)
target_include_directories(thunkgenlib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(thunkgenlib SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
target_link_libraries(thunkgenlib PUBLIC clang-cpp LLVM)
target_link_libraries(thunkgenlib PRIVATE OpenSSL::Crypto)
target_link_libraries(thunkgenlib PRIVATE fmt::fmt)
target_compile_definitions(thunkgenlib INTERFACE -DCLANG_RESOURCE_DIR="${CLANG_RESOURCE_DIR}")

add_executable(thunkgen main.cpp)
target_link_libraries(thunkgen PRIVATE thunkgenlib)
target_compile_definitions(thunkgen PRIVATE -DCLANG_RESOURCE_DIR="${CLANG_RESOURCE_DIR}")
4 changes: 4 additions & 0 deletions unittests/ThunkLibs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ inline void run_tool(clang::tooling::ToolAction& action, std::string_view code,
const char* memory_filename = "gen_input.cpp";
auto adjuster = clang::tooling::getClangStripDependencyFileAdjuster();
std::vector<std::string> args = { "clang-tool", "-fsyntax-only", "-std=c++17", "-Werror", "-I.", memory_filename };
if (CLANG_RESOURCE_DIR[0] != 0) {
args.push_back("-resource-dir");
args.push_back(CLANG_RESOURCE_DIR);
}
if (guest_abi == GuestABI::X86_64) {
args.push_back("-target");
args.push_back("x86_64-linux-gnu");
Expand Down

0 comments on commit 36fedfd

Please sign in to comment.