Skip to content

Commit

Permalink
Enable correct prefix for TestSharedLib directory
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas Atre <[email protected]>
  • Loading branch information
SAtacker committed Feb 4, 2024
1 parent 17b5925 commit 1905eb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion unittests/CppInterOp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/$<CONFIG>/
)

set_output_directory(DynamicLibraryManagerTests BINARY_DIR ${CMAKE_BINARY_DIR}/unittests/bin/$<CONFIG>/)

add_dependencies(DynamicLibraryManagerTests TestSharedLib)
Expand Down
19 changes: 15 additions & 4 deletions unittests/CppInterOp/DynamicLibraryManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 1905eb3

Please sign in to comment.