From b090bd193711cdcc31efdb36f820536452b9c0fe Mon Sep 17 00:00:00 2001 From: "Hochsteger, Matthias" Date: Wed, 20 Mar 2024 18:30:17 +0100 Subject: [PATCH] Propagate -fabi-version=xx when compiling with GCC --- libsrc/core/CMakeLists.txt | 24 ++++++++++++++++++++-- libsrc/core/_get_glibcxx_use_cxx11_abi.cpp | 13 ++++++++++++ libsrc/core/_get_gxx_abi.cpp | 7 +++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 libsrc/core/_get_glibcxx_use_cxx11_abi.cpp create mode 100644 libsrc/core/_get_gxx_abi.cpp diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index d91a1bbe..d6a2eef8 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -23,8 +23,28 @@ if(EMSCRIPTEN) target_compile_options(ngcore PUBLIC -sNO_DISABLE_EXCEPTION_CATCHING) endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9) - target_link_libraries(ngcore PUBLIC stdc++fs) +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + # Python packages on Linux are compiled with the old ABI, + # make sure that the same ABI is used in plugins aswell + try_run( + ret_val can_compile + ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/_get_glibcxx_use_cxx11_abi.cpp + RUN_OUTPUT_VARIABLE use_glibcxx_cxx11_abi + ) + target_compile_definitions(ngcore PUBLIC -D_GLIBCXX_USE_CXX11_ABI=${use_glibcxx_cxx11_abi}) + if(USE_PYTHON) + try_run( + ret_val can_compile + ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/_get_gxx_abi.cpp + RUN_OUTPUT_VARIABLE cxx_abi_version + ) + if(${can_compile} AND (${ret_val} EQUAL 0)) + # Different python modules using pybind11 need to use the same C++ ABI version + # for compatibility + message(STATUS "GNU C++ ABI version: ${cxx_abi_version}") + target_compile_options(ngcore PUBLIC "-fabi-version=${cxx_abi_version}") + endif() + endif(USE_PYTHON) endif() if(USE_PYTHON) diff --git a/libsrc/core/_get_glibcxx_use_cxx11_abi.cpp b/libsrc/core/_get_glibcxx_use_cxx11_abi.cpp new file mode 100644 index 00000000..63588187 --- /dev/null +++ b/libsrc/core/_get_glibcxx_use_cxx11_abi.cpp @@ -0,0 +1,13 @@ +#include + +int main() { + #ifdef _GLIBCXX_USE_CXX11_ABI + if(_GLIBCXX_USE_CXX11_ABI) + std::cout << 1; + else + std::cout << 0; + #else // _GLIBCXX_USE_CXX11_ABI + std::cout << 0; + #endif // _GLIBCXX_USE_CXX11_ABI + return 0; +} diff --git a/libsrc/core/_get_gxx_abi.cpp b/libsrc/core/_get_gxx_abi.cpp new file mode 100644 index 00000000..ac1579f0 --- /dev/null +++ b/libsrc/core/_get_gxx_abi.cpp @@ -0,0 +1,7 @@ +#include + +int main() { + if (__GXX_ABI_VERSION >= 2000 || __GXX_ABI_VERSION < 1000) return 1; + std::cout << (__GXX_ABI_VERSION % 100); + return 0; +}