diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 2ee0dd5b1b7..e60018e6a0d 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -104,6 +104,13 @@ if(APPLE) set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress") endif() +# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO +# build might work on ELF but fail on MachO/COFF. +if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32)) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") +endif() + + function(append value) foreach(variable ${ARGN}) set(${variable} "${${variable}} ${value}" PARENT_SCOPE) diff --git a/utils/unittest/CMakeLists.txt b/utils/unittest/CMakeLists.txt index b6d2d6d9e0e..7ac894dff14 100644 --- a/utils/unittest/CMakeLists.txt +++ b/utils/unittest/CMakeLists.txt @@ -38,11 +38,20 @@ if(MSVC AND MSVC_VERSION EQUAL 1700) add_definitions(-D_VARIADIC_MAX=10) endif () +set(LIBS + LLVMSupport # Depends on llvm::raw_ostream +) + +find_library(PTHREAD_LIBRARY_PATH pthread) +if (PTHREAD_LIBRARY_PATH) + list(APPEND LIBS pthread) +endif() + add_llvm_library(gtest googletest/src/gtest-all.cc LINK_LIBS - LLVMSupport # Depends on llvm::raw_ostream - ) + ${LIBS} +) add_subdirectory(UnitTestMain)