diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -3,6 +3,7 @@ include(LLVMProcessSources) include(LLVM-Config) include(DetermineGCCCompatible) +include(CheckLibraryExists) function(llvm_update_compile_flags name) get_property(sources TARGET ${name} PROPERTY SOURCES) @@ -683,6 +684,12 @@ set(libtype PRIVATE) endif() + # Many LLVM libs require libm, so do this globally. + check_library_exists(m ceil "" HAVE_LIBM) + if(HAVE_LIBM) + set_target_properties(${name} PROPERTIES INTERFACE_LINK_LIBRARIES m) + endif() + if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN)) # On DLL platforms symbols are imported from the tool by linking against it. set(llvm_libs ${ARG_PLUGIN_TOOL}) diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt --- a/llvm/lib/TargetParser/CMakeLists.txt +++ b/llvm/lib/TargetParser/CMakeLists.txt @@ -8,6 +8,11 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=global-constructors") endif() +# Solaris code uses kstat, so specify dependency explicitly for shared builds. +if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + set(system_libs kstat) +endif() + add_llvm_component_library(LLVMTargetParser AArch64TargetParser.cpp ARMTargetParserCommon.cpp @@ -25,6 +30,9 @@ Unix Windows + LINK_LIBS + ${system_libs} + LINK_COMPONENTS Support diff --git a/third-party/benchmark/CMakeLists.txt b/third-party/benchmark/CMakeLists.txt --- a/third-party/benchmark/CMakeLists.txt +++ b/third-party/benchmark/CMakeLists.txt @@ -129,6 +129,7 @@ include(CheckLibraryExists) check_library_exists(rt shm_open "" HAVE_LIB_RT) +check_library_exists(m ceil "" HAVE_LIB_M) if (BENCHMARK_BUILD_32_BITS) add_required_cxx_compiler_flag(-m32) diff --git a/third-party/benchmark/src/CMakeLists.txt b/third-party/benchmark/src/CMakeLists.txt --- a/third-party/benchmark/src/CMakeLists.txt +++ b/third-party/benchmark/src/CMakeLists.txt @@ -42,6 +42,9 @@ target_link_libraries(benchmark PRIVATE rt) endif(HAVE_LIB_RT) +if(HAVE_LIB_M) + target_link_libraries(benchmark PRIVATE m) +endif() # We need extra libraries on Windows if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")