labath created this revision. labath added reviewers: krytarowski, zturner. Herald added a subscriber: mgorny.
This patch consists of two relatively independent changes: - first, I teach the standalone build to detect the case when llvm was built in the shared mode and set the appropriate cmake variables to make the add_llvm_*** family of functions link against the shared library. Without these, the we would end up linking against the constituent .a files while other parts of the build (e.g. clang) would pull in the libllvm.so, which resulted in multiply defined symbols. - second, I add detection code for pthread and dl libraries. This is necessary, because we have direct calls to these libraries (instead of going through llvm) and in the standalone build we cannot rely on llvm to detect these for us. In a standalone non-dylib build this was accidentaly working because these libraries were pulled in as an interface dependency of the .a files, but in a dylib build these are no longer part of the link interface, and so we need to add them explicitly. https://reviews.llvm.org/D44379 Files: cmake/modules/LLDBConfig.cmake cmake/modules/LLDBStandalone.cmake Index: cmake/modules/LLDBStandalone.cmake =================================================================== --- cmake/modules/LLDBStandalone.cmake +++ cmake/modules/LLDBStandalone.cmake @@ -17,7 +17,9 @@ "--includedir" "--prefix" "--src-root" - "--cmakedir") + "--cmakedir" + "--shared-mode" + ) execute_process( COMMAND ${CONFIG_COMMAND} RESULT_VARIABLE HAD_ERROR @@ -44,6 +46,7 @@ list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT) list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR) list(GET CONFIG_OUTPUT 6 LLVM_CMAKE_PATH) + list(GET CONFIG_OUTPUT 7 SHARED_MODE) if(NOT MSVC_IDE) set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS} @@ -72,6 +75,11 @@ message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}") endif() + if(SHARED_MODE STREQUAL "shared") + set(LLVM_LINK_LLVM_DYLIB ON) + set(LLVM_DYLIB_COMPONENTS all) + endif() + # They are used as destination of target generators. set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) Index: cmake/modules/LLDBConfig.cmake =================================================================== --- cmake/modules/LLDBConfig.cmake +++ cmake/modules/LLDBConfig.cmake @@ -346,12 +346,15 @@ endif() -if (HAVE_LIBPTHREAD) - list(APPEND system_libs pthread) -endif(HAVE_LIBPTHREAD) - -if (HAVE_LIBDL) - list(APPEND system_libs ${CMAKE_DL_LIBS}) +if(UNIX) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + find_package(Threads REQUIRED) + list(APPEND system_libs ${CMAKE_THREAD_LIBS_INIT}) + + check_library_exists(dl dlopen "" HAVE_LIBDL) + if (HAVE_LIBDL) + list(APPEND system_libs ${CMAKE_DL_LIBS}) + endif() endif() # Figure out if lldb could use lldb-server. If so, then we'll
Index: cmake/modules/LLDBStandalone.cmake =================================================================== --- cmake/modules/LLDBStandalone.cmake +++ cmake/modules/LLDBStandalone.cmake @@ -17,7 +17,9 @@ "--includedir" "--prefix" "--src-root" - "--cmakedir") + "--cmakedir" + "--shared-mode" + ) execute_process( COMMAND ${CONFIG_COMMAND} RESULT_VARIABLE HAD_ERROR @@ -44,6 +46,7 @@ list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT) list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR) list(GET CONFIG_OUTPUT 6 LLVM_CMAKE_PATH) + list(GET CONFIG_OUTPUT 7 SHARED_MODE) if(NOT MSVC_IDE) set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS} @@ -72,6 +75,11 @@ message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}") endif() + if(SHARED_MODE STREQUAL "shared") + set(LLVM_LINK_LLVM_DYLIB ON) + set(LLVM_DYLIB_COMPONENTS all) + endif() + # They are used as destination of target generators. set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) Index: cmake/modules/LLDBConfig.cmake =================================================================== --- cmake/modules/LLDBConfig.cmake +++ cmake/modules/LLDBConfig.cmake @@ -346,12 +346,15 @@ endif() -if (HAVE_LIBPTHREAD) - list(APPEND system_libs pthread) -endif(HAVE_LIBPTHREAD) - -if (HAVE_LIBDL) - list(APPEND system_libs ${CMAKE_DL_LIBS}) +if(UNIX) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + find_package(Threads REQUIRED) + list(APPEND system_libs ${CMAKE_THREAD_LIBS_INIT}) + + check_library_exists(dl dlopen "" HAVE_LIBDL) + if (HAVE_LIBDL) + list(APPEND system_libs ${CMAKE_DL_LIBS}) + endif() endif() # Figure out if lldb could use lldb-server. If so, then we'll
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits