From 1905eb344228d63fe1642e19eae302e1dc8e2ab4 Mon Sep 17 00:00:00 2001 From: Shreyas Atre Date: Sat, 3 Feb 2024 23:49:37 -0600 Subject: [PATCH] Enable correct prefix for TestSharedLib directory Signed-off-by: Shreyas Atre --- unittests/CppInterOp/CMakeLists.txt | 6 +++++- .../CppInterOp/DynamicLibraryManagerTest.cpp | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/unittests/CppInterOp/CMakeLists.txt b/unittests/CppInterOp/CMakeLists.txt index 75dccf556..19d41d813 100644 --- a/unittests/CppInterOp/CMakeLists.txt +++ b/unittests/CppInterOp/CMakeLists.txt @@ -22,12 +22,16 @@ export_executable_symbols(CppInterOpTests) unset(LLVM_LINK_COMPONENTS) -add_cppinterop_unittest(DynamicLibraryManagerTests DynamicLibraryManagerTest.cpp) +add_cppinterop_unittest(DynamicLibraryManagerTests DynamicLibraryManagerTest.cpp ${LLVM_OPTIONAL_SOURCES}) target_link_libraries(DynamicLibraryManagerTests PRIVATE clangCppInterOp ) +target_compile_definitions(DynamicLibraryManagerTests + PRIVATE CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX=${CMAKE_BINARY_DIR}/unittests/bin/$/ +) + set_output_directory(DynamicLibraryManagerTests BINARY_DIR ${CMAKE_BINARY_DIR}/unittests/bin/$/) add_dependencies(DynamicLibraryManagerTests TestSharedLib) diff --git a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp index 61af2303d..816f83c9c 100644 --- a/unittests/CppInterOp/DynamicLibraryManagerTest.cpp +++ b/unittests/CppInterOp/DynamicLibraryManagerTest.cpp @@ -7,6 +7,9 @@ #include "../../lib/Interpreter/Paths.h" +#define XCPP_INTEROP_STRINGIFY(x) #x +#define CPP_INTEROP_STRINGIFY(x) XCPP_INTEROP_STRINGIFY(x) + // This function isn't referenced outside its translation unit, but it // can't use the "static" keyword because its address is used for // GetMainExecutable (since some platforms don't support taking the @@ -59,15 +62,23 @@ TEST(DynamicLibraryManagerTest, Sanity) { TEST(UtilsPlatform, DLTest) { std::string err = ""; + // CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX specified by cmake though target + // definitions #if defined(__APPLE__) auto dlopen_handle = Cpp::utils::platform::DLOpen( - "./libTestSharedLib.dylib", err); + CPP_INTEROP_STRINGIFY( + CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX) "./libTestSharedLib.dylib", + err); #elif defined(_WIN32) auto dlopen_handle = Cpp::utils::platform::DLOpen( - "./libTestSharedLib.dll", err); + CPP_INTEROP_STRINGIFY( + CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX) "./libTestSharedLib.dll", + err); #else - auto dlopen_handle = - Cpp::utils::platform::DLOpen("../bin/libTestSharedLib.so", err); + auto dlopen_handle = Cpp::utils::platform::DLOpen( + CPP_INTEROP_STRINGIFY( + CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX) "./libTestSharedLib.so", + err); #endif EXPECT_TRUE(dlopen_handle); EXPECT_TRUE(err.empty());