Skip to content

Commit 1976d0c

Browse files
committed
Enable correct prefix for TestSharedLib directory
Signed-off-by: Shreyas Atre <[email protected]>
1 parent 17b5925 commit 1976d0c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

unittests/CppInterOp/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ export_executable_symbols(CppInterOpTests)
2222

2323
unset(LLVM_LINK_COMPONENTS)
2424

25-
add_cppinterop_unittest(DynamicLibraryManagerTests DynamicLibraryManagerTest.cpp)
25+
add_cppinterop_unittest(DynamicLibraryManagerTests DynamicLibraryManagerTest.cpp ${CMAKE_SOURCE_DIR}/lib/Interpreter/Paths.cpp)
2626
target_link_libraries(DynamicLibraryManagerTests
2727
PRIVATE
2828
clangCppInterOp
2929
)
3030

31+
target_compile_definitions(DynamicLibraryManagerTests
32+
PRIVATE CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX=${CMAKE_BINARY_DIR}/unittests/bin/$<CONFIG>/
33+
)
34+
3135
set_output_directory(DynamicLibraryManagerTests BINARY_DIR ${CMAKE_BINARY_DIR}/unittests/bin/$<CONFIG>/)
3236

3337
add_dependencies(DynamicLibraryManagerTests TestSharedLib)

unittests/CppInterOp/DynamicLibraryManagerTest.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include "../../lib/Interpreter/Paths.h"
99

10+
#define XCPP_INTEROP_STRINGIFY(x) #x
11+
#define CPP_INTEROP_STRINGIFY(x) XCPP_INTEROP_STRINGIFY(x)
12+
1013
// This function isn't referenced outside its translation unit, but it
1114
// can't use the "static" keyword because its address is used for
1215
// GetMainExecutable (since some platforms don't support taking the
@@ -59,15 +62,23 @@ TEST(DynamicLibraryManagerTest, Sanity) {
5962

6063
TEST(UtilsPlatform, DLTest) {
6164
std::string err = "";
65+
// CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX specified by cmake though target
66+
// definitions
6267
#if defined(__APPLE__)
6368
auto dlopen_handle = Cpp::utils::platform::DLOpen(
64-
"./libTestSharedLib.dylib", err);
69+
CPP_INTEROP_STRINGIFY(
70+
CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX) "./libTestSharedLib.dylib",
71+
err);
6572
#elif defined(_WIN32)
6673
auto dlopen_handle = Cpp::utils::platform::DLOpen(
67-
"./libTestSharedLib.dll", err);
74+
CPP_INTEROP_STRINGIFY(
75+
CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX) "./libTestSharedLib.dll",
76+
err);
6877
#else
69-
auto dlopen_handle =
70-
Cpp::utils::platform::DLOpen("../bin/libTestSharedLib.so", err);
78+
auto dlopen_handle = Cpp::utils::platform::DLOpen(
79+
CPP_INTEROP_STRINGIFY(
80+
CPPINTEROP_LIB_TestSharedLib_DIR_PREFIX) "./libTestSharedLib.so",
81+
err);
7182
#endif
7283
EXPECT_TRUE(dlopen_handle);
7384
EXPECT_TRUE(err.empty());

0 commit comments

Comments
 (0)