Skip to content

Commit

Permalink
Use different muparserx library in linux depending on the ABI (#561)
Browse files Browse the repository at this point in the history
* Use different muparserx library in linux depending on the ABI supported by the compiler

* _C++_ var names to _CXX_ names. Remove old code. Add comments.
  • Loading branch information
vvilpas committed Jan 30, 2020
1 parent 230193b commit d445d01
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Expand Up @@ -200,16 +200,8 @@ else()
endif()

message(STATUS "Uncompressing muparserx static library...")
if(MSVC)
set(PLATFORM "win64")
elseif(APPLE)
set(PLATFORM "macos")
elseif(UNIX)
set(PLATFORM "linux")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xvfj" "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${PLATFORM}/lib/muparserx.7z"
WORKING_DIRECTORY "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${PLATFORM}/lib/")
set(MUPARSERX_LIB_PATH "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${PLATFORM}/lib")

uncompress_muparsersx_lib()

find_library(MUPARSERX_LIB NAMES libmuparserx.a muparserx HINTS ${MUPARSERX_LIB_PATH})
if(${MUPARSERX_LIB} MATCHES "MUPARSERX_LIB-NOTFOUND")
Expand Down
32 changes: 31 additions & 1 deletion cmake/compiler_utils.cmake
Expand Up @@ -56,4 +56,34 @@ function(get_muparserx_source_code)
Please download MuparserX library from https://github.com/beltoforion/muparserx.git \
and checkout latest stable release")
endif()
endfunction()
endfunction()

function(check_compiler_cpp11_abi)
# This is needed in case the compiler doesn't work with the new C++11 ABI,
# is the case of GCC in RHEL6 and RHEL7
# https://bugzilla.redhat.com/show_bug.cgi?id=1546704
# Consider also if -D_GLIBCXX_USE_CXX11_ABI has been passed as flag
string(REGEX MATCH "-D_GLIBCXX_USE_CXX11_ABI=[(A-z)|(a-z)|(0-9)]+" CUSTOM_PREP_FLAGS ${CMAKE_CXX_FLAGS})
# Preprocessor run to check if CXX11_ABI is set
execute_process(COMMAND echo "#include <string>" COMMAND ${CMAKE_CXX_COMPILER} ${CUSTOM_PREP_FLAGS} -x c++ -E -dM - COMMAND fgrep _GLIBCXX_USE_CXX11_ABI OUTPUT_VARIABLE CXX11_ABI_OUT OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "#define _GLIBCXX_USE_CXX11_ABI " "" CXX11_ABI "${CXX11_ABI_OUT}")
set(CXX11_ABI ${CXX11_ABI} PARENT_SCOPE)
endfunction()

function(uncompress_muparsersx_lib)
if(MSVC)
set(PLATFORM "win64")
elseif(APPLE)
set(PLATFORM "macos")
elseif(UNIX)
check_compiler_cpp11_abi()
if(CXX11_ABI EQUAL "0")
set(MUPARSER_ABI_PREFIX oldabi_)
endif()
set(PLATFORM "linux")
endif()

execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xvfj" "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${PLATFORM}/lib/${MUPARSER_ABI_PREFIX}muparserx.7z"
WORKING_DIRECTORY "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${PLATFORM}/lib/")
set(MUPARSERX_LIB_PATH "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${PLATFORM}/lib" PARENT_SCOPE)
endfunction()
Binary file added src/third-party/linux/lib/oldabi_muparserx.7z
Binary file not shown.

0 comments on commit d445d01

Please sign in to comment.