Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ else()
endif()

target_compile_definitions(cppyy-backend PRIVATE
CPPINTEROP_DIR="${_interop_install_dir}"
CPPINTEROP_BIN_DIR="${_interop_install_dir}"
CMAKE_SHARED_LIBRARY_SUFFIX="${CMAKE_SHARED_LIBRARY_SUFFIX}"
)

Expand Down
45 changes: 40 additions & 5 deletions clingwrapper/src/clingwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,50 @@ bool is_integral(std::string& s)
s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
}

// CppInterOp artifacts prefix (the directory containing lib/ and include/):
// the CPPINTEROP_BIN_DIR environment variable overrides the compile-time
// default.
static inline
std::string cppinterop_dir()
{
if (const char* env = getenv("CPPINTEROP_BIN_DIR"))
return env;
#ifdef CPPINTEROP_BIN_DIR
return CPPINTEROP_BIN_DIR;
#else
return "";
#endif
}

static inline
std::string cppinterop_lib_path()
{
std::string dir = cppinterop_dir();
if (dir.empty())
return "";
#ifdef CMAKE_SHARED_LIBRARY_SUFFIX
// CMake sets the correct per-platform suffix (.so/.dylib/.dll).
return dir + "/lib/libclangCppInterOp" CMAKE_SHARED_LIBRARY_SUFFIX;
#else
// Non-CMake builds (no suffix defined): default to .so.
return dir + "/lib/libclangCppInterOp.so";
#endif
}

class ApplicationStarter {
Cppyy::TInterp_t Interp;
public:
ApplicationStarter() {
std::lock_guard<std::recursive_mutex> Lock(InterOpMutex);
if (!Cpp::LoadDispatchAPI(
CPPINTEROP_DIR
"/lib/libclangCppInterOp" CMAKE_SHARED_LIBRARY_SUFFIX)) {
std::cerr << "[cppyy-backend] Failed to load CppInterOp" << std::endl;
const std::string lib_path = cppinterop_lib_path();
if (lib_path.empty()) {
std::cerr << "[cppyy-backend] CppInterOp location unknown: set the"
" CPPINTEROP_BIN_DIR environment variable" << std::endl;
return;
}
if (!Cpp::LoadDispatchAPI(lib_path.c_str())) {
std::cerr << "[cppyy-backend] Failed to load CppInterOp from "
<< lib_path << std::endl;
return;
}
// Check if somebody already loaded CppInterOp and created an
Expand Down Expand Up @@ -185,7 +220,7 @@ class ApplicationStarter {
Cpp::AddIncludePath((ClingSrc + "/tools/cling/include").c_str());
Cpp::AddIncludePath((ClingSrc + "/include").c_str());
Cpp::AddIncludePath((ClingBuildDir + "/include").c_str());
Cpp::AddIncludePath((std::string(CPPINTEROP_DIR) + "/include").c_str());
Cpp::AddIncludePath((cppinterop_dir() + "/include").c_str());
Cpp::LoadLibrary("libstdc++", /* lookup= */ true);

// load frequently used headers
Expand Down
Loading