Index: cmake/modules/CheckCXXSharedLibrary.cmake =================================================================== --- /dev/null +++ cmake/modules/CheckCXXSharedLibrary.cmake @@ -0,0 +1,73 @@ +# Check if C++ library is a shared library. +function(check_cxx_shared_library output) + cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN}) + if(NOT ARG_SOURCE) + set(ARG_SOURCE "int main() { return 0; }\n") + endif() + + string(RANDOM TARGET_NAME) + set(TARGET_NAME "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cmTC_${TARGET_NAME}.dir") + file(MAKE_DIRECTORY ${TARGET_NAME}) + + file(WRITE "${TARGET_NAME}/CheckCXXSharedLibrary.cpp" "${ARG_SOURCE}\n") + + string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions + ${CMAKE_CXX_LINK_EXECUTABLE}) + + set(try_link_flags "${ARG_FLAGS}") + if(CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET) + list(APPEND try_link_flags "--target=${CMAKE_CXX_COMPILER_TARGET}") + endif() + if(CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_SYSROOT) + list(APPEND try_link_flags "--sysroot=${CMAKE_SYSROOT}") + endif() + + string(REPLACE ";" " " extra_flags "${try_link_flags}") + + set(test_link_command "${CMAKE_CXX_LINK_EXECUTABLE}") + foreach(substitution ${substitutions}) + if(substitution STREQUAL "") + string(REPLACE "" "${CMAKE_CXX_COMPILER}" + test_link_command ${test_link_command}) + elseif(substitution STREQUAL "") + string(REPLACE "" "${TARGET_NAME}/CheckCXXSharedLibrary.cpp" + test_link_command ${test_link_command}) + elseif(substitution STREQUAL "") + string(REPLACE "" "${TARGET_NAME}/CheckCXXSharedLibrary" + test_link_command ${test_link_command}) + elseif(substitution STREQUAL "") + string(REPLACE "" "${CMAKE_CXX_FLAGS}" + test_link_command ${test_link_command}) + elseif(substitution STREQUAL "") + string(REPLACE "" "${CMAKE_EXE_LINKER_FLAGS} ${extra_flags}" + test_link_command ${test_link_command}) + else() + string(REPLACE "${substitution}" "" test_link_command + ${test_link_command}) + endif() + endforeach() + + string(REPLACE " " ";" test_link_command "${test_link_command}") + + execute_process( + COMMAND ${test_link_command} + RESULT_VARIABLE LINK_RESULT + OUTPUT_VARIABLE LINK_OUTPUT + ERROR_VARIABLE LINK_ERROR + ) + + execute_process( + COMMAND ${CMAKE_OBJDUMP} -p "${TARGET_NAME}/CheckCXXSharedLibrary" + RESULT_VARIABLE CHECK_RESULT + OUTPUT_VARIABLE CHECK_OUTPUT + ERROR_VARIABLE CHECK_ERROR + ) + + if(CHECK_OUTPUT MATCHES "lib(std)?c\\+\\+") + set(${output} TRUE PARENT_SCOPE) + else() + set(${output} FALSE PARENT_SCOPE) + endif() + + file(REMOVE_RECURSE ${TARGET_NAME}) +endfunction() Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -1,3 +1,7 @@ +include(CheckCXXSharedLibrary) + +check_cxx_shared_library(HAVE_CXX_SHARED_LIBRARY) + llvm_canonicalize_cmake_booleans( LLVM_TOOL_LTO_BUILD HAVE_OCAMLOPT @@ -10,6 +14,7 @@ LLVM_ENABLE_FFI BUILD_SHARED_LIBS LLVM_LINK_LLVM_DYLIB + HAVE_CXX_SHARED_LIBRARY ) configure_lit_site_cfg( Index: test/ExecutionEngine/MCJIT/eh-lg-pic.ll =================================================================== --- test/ExecutionEngine/MCJIT/eh-lg-pic.ll +++ test/ExecutionEngine/MCJIT/eh-lg-pic.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -relocation-model=pic -code-model=large %s ; XFAIL: cygwin, win32, mingw, mips-, mipsel-, i686, i386, aarch64, arm declare i8* @__cxa_allocate_exception(i64) Index: test/ExecutionEngine/MCJIT/eh.ll =================================================================== --- test/ExecutionEngine/MCJIT/eh.ll +++ test/ExecutionEngine/MCJIT/eh.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli %s ; XFAIL: arm, cygwin, win32, mingw declare i8* @__cxa_allocate_exception(i64) Index: test/ExecutionEngine/MCJIT/multi-module-eh-a.ll =================================================================== --- test/ExecutionEngine/MCJIT/multi-module-eh-a.ll +++ test/ExecutionEngine/MCJIT/multi-module-eh-a.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -extra-module=%p/Inputs/multi-module-eh-b.ll %s ; XFAIL: arm, cygwin, win32, mingw declare i8* @__cxa_allocate_exception(i64) Index: test/ExecutionEngine/MCJIT/remote/eh.ll =================================================================== --- test/ExecutionEngine/MCJIT/remote/eh.ll +++ test/ExecutionEngine/MCJIT/remote/eh.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -remote-mcjit -mcjit-remote-process=lli-child-target%exeext %s ; XFAIL: arm, cygwin, win32, mingw ; UNSUPPORTED: powerpc64-unknown-linux-gnu Index: test/ExecutionEngine/OrcMCJIT/eh-lg-pic.ll =================================================================== --- test/ExecutionEngine/OrcMCJIT/eh-lg-pic.ll +++ test/ExecutionEngine/OrcMCJIT/eh-lg-pic.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -jit-kind=orc-mcjit -relocation-model=pic -code-model=large %s ; XFAIL: cygwin, win32, mingw, mips-, mipsel-, i686, i386, aarch64, arm declare i8* @__cxa_allocate_exception(i64) Index: test/ExecutionEngine/OrcMCJIT/eh.ll =================================================================== --- test/ExecutionEngine/OrcMCJIT/eh.ll +++ test/ExecutionEngine/OrcMCJIT/eh.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -jit-kind=orc-mcjit %s ; XFAIL: arm, cygwin, win32, mingw declare i8* @__cxa_allocate_exception(i64) Index: test/ExecutionEngine/OrcMCJIT/multi-module-eh-a.ll =================================================================== --- test/ExecutionEngine/OrcMCJIT/multi-module-eh-a.ll +++ test/ExecutionEngine/OrcMCJIT/multi-module-eh-a.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -jit-kind=orc-mcjit -extra-module=%p/Inputs/multi-module-eh-b.ll %s ; XFAIL: arm, cygwin, win32, mingw declare i8* @__cxa_allocate_exception(i64) Index: test/ExecutionEngine/OrcMCJIT/remote/eh.ll =================================================================== --- test/ExecutionEngine/OrcMCJIT/remote/eh.ll +++ test/ExecutionEngine/OrcMCJIT/remote/eh.ll @@ -1,3 +1,4 @@ +; REQUIRES: cxx-shared-library ; RUN: %lli -remote-mcjit -mcjit-remote-process=lli-child-target%exeext %s ; XFAIL: arm, cygwin, win32, mingw ; UNSUPPORTED: powerpc64-unknown-linux-gnu Index: test/lit.cfg.py =================================================================== --- test/lit.cfg.py +++ test/lit.cfg.py @@ -194,6 +194,9 @@ if not config.build_shared_libs and not config.link_llvm_dylib: config.available_features.add('static-libs') +if config.have_cxx_shared_library: + config.available_features.add('cxx-shared-library') + # Direct object generation if not 'hexagon' in config.target_triple: config.available_features.add('object-emission') Index: test/lit.site.cfg.py.in =================================================================== --- test/lit.site.cfg.py.in +++ test/lit.site.cfg.py.in @@ -44,6 +44,7 @@ config.llvm_host_triple = '@LLVM_HOST_TRIPLE@' config.host_arch = "@HOST_ARCH@" config.have_opt_viewer_modules = @LLVM_HAVE_OPT_VIEWER_MODULES@ +config.have_cxx_shared_library = @HAVE_CXX_SHARED_LIBRARY@ # Support substitution of the tools_dir with user parameters. This is # used when we can't determine the tool dir at configuration time.