Skip to content

[CMake] Auto-detect C++ ABI version #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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 multipy/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ message(STATUS "CMAKE_BUILD_TYPE - ${CMAKE_BUILD_TYPE}" )
set(DEPLOY_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
get_filename_component(MULTIPY_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fabi-version=11 -fno-lto -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto -fPIC")
include(${DEPLOY_DIR}/utils.cmake)

add_subdirectory(interpreter)
Expand Down
18 changes: 17 additions & 1 deletion multipy/runtime/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@ if (NOT DEFINED _GLIBCXX_USE_CXX11_ABI)
message(FATAL_ERROR "Failed to detect ABI version")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI}")
string(APPEND CMAKE_CXX_FLAGS " -D_GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI}")
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI})
message(STATUS "_GLIBCXX_USE_CXX11_ABI - ${_GLIBCXX_USE_CXX11_ABI}")

if (NOT DEFINED _CXX_ABI_VERSION)
# infer the ABI setting from the installed version of PyTorch
execute_process(
COMMAND python -c "import torch; print(torch._C._PYBIND11_BUILD_ABI[-2:])"
OUTPUT_VARIABLE _CXX_ABI_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE ret
)
if(ret EQUAL "1")
message(WARNING "Failed to detect ABI version, reseting to 11")
set(_CXX_ABI_VERSION 11)
endif()
endif()
string(APPEND CMAKE_CXX_FLAGS " -fabi-version=${_CXX_ABI_VERSION}")
message(STATUS "_CXX_ABI_VERSION - ${_CXX_ABI_VERSION}")

set(Python3_FIND_STRATEGY LOCATION)

find_package (Python3 COMPONENTS Interpreter Development)
Expand Down