From c165498992324c526bc3f663ec361dd262d48636 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 1 Mar 2016 15:54:40 +0000 Subject: [PATCH] Refactor duplicated code for linking with pthread. llvm-svn: 262344 --- cmake/config-ix.cmake | 4 ++++ examples/ParallelJIT/CMakeLists.txt | 4 +--- lib/CodeGen/CMakeLists.txt | 7 +------ lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt | 6 +++--- lib/Fuzzer/CMakeLists.txt | 8 ++------ lib/Support/CMakeLists.txt | 4 +--- unittests/Support/CMakeLists.txt | 4 +--- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index c5be442a2c5..86a106d26cf 100755 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -107,6 +107,10 @@ if( NOT PURE_WINDOWS ) check_library_exists(rt clock_gettime "" HAVE_LIBRT) endif() +if(HAVE_LIBPTHREAD) + set(PTHREAD_LIB pthread) +endif() + # Don't look for these libraries on Windows. Also don't look for them if we're # using MSan, since uninstrmented third party code may call MSan interceptors # like strlen, leading to false positives. diff --git a/examples/ParallelJIT/CMakeLists.txt b/examples/ParallelJIT/CMakeLists.txt index 07c0a085b91..e85b470f503 100644 --- a/examples/ParallelJIT/CMakeLists.txt +++ b/examples/ParallelJIT/CMakeLists.txt @@ -11,6 +11,4 @@ add_llvm_example(ParallelJIT ParallelJIT.cpp ) -if(HAVE_LIBPTHREAD) - target_link_libraries(ParallelJIT pthread) -endif(HAVE_LIBPTHREAD) +target_link_libraries(ParallelJIT ${PTHREAD_LIB}) diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt index de6d21dde5e..6ebde1aed53 100644 --- a/lib/CodeGen/CMakeLists.txt +++ b/lib/CodeGen/CMakeLists.txt @@ -1,8 +1,3 @@ -set(system_libs) -if(CMAKE_HOST_UNIX AND LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD) - set(system_libs ${system_libs} pthread) -endif() - add_llvm_library(LLVMCodeGen AggressiveAntiDepBreaker.cpp AllocationOrder.cpp @@ -135,7 +130,7 @@ add_llvm_library(LLVMCodeGen ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen/PBQP - LINK_LIBS ${system_libs} + LINK_LIBS ${PTHREAD_LIB} ) add_dependencies(LLVMCodeGen intrinsics_gen) diff --git a/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt b/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt index 65f2a2f51f9..3b8c4b973e6 100644 --- a/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt +++ b/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt @@ -3,9 +3,9 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ) if( HAVE_LIBDL ) set(LLVM_INTEL_JIT_LIBS ${CMAKE_DL_LIBS}) endif() -if( HAVE_LIBPTHREAD ) - set(LLVM_INTEL_JIT_LIBS pthread ${LLVM_INTEL_JIT_LIBS}) -endif() + +set(LLVM_INTEL_JIT_LIBS ${PTHREAD_LIB} ${LLVM_INTEL_JIT_LIBS}) + add_llvm_library(LLVMIntelJITEvents IntelJITEventListener.cpp diff --git a/lib/Fuzzer/CMakeLists.txt b/lib/Fuzzer/CMakeLists.txt index eeae5112ca5..3fae903c44c 100644 --- a/lib/Fuzzer/CMakeLists.txt +++ b/lib/Fuzzer/CMakeLists.txt @@ -18,16 +18,12 @@ if( LLVM_USE_SANITIZE_COVERAGE ) add_library(LLVMFuzzerNoMain STATIC $ ) - if( HAVE_LIBPTHREAD ) - target_link_libraries(LLVMFuzzerNoMain pthread) - endif() + target_link_libraries(LLVMFuzzerNoMain ${PTHREAD_LIB}) add_library(LLVMFuzzer STATIC FuzzerMain.cpp $ ) - if( HAVE_LIBPTHREAD ) - target_link_libraries(LLVMFuzzer pthread) - endif() + target_link_libraries(LLVMFuzzer ${PTHREAD_LIB}) if( LLVM_INCLUDE_TESTS ) add_subdirectory(test) diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index bccbdfca4c4..d14d7d305fd 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -17,9 +17,7 @@ elseif( CMAKE_HOST_UNIX ) if( LLVM_ENABLE_THREADS AND HAVE_LIBATOMIC ) set(system_libs ${system_libs} atomic) endif() - if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD ) - set(system_libs ${system_libs} pthread) - endif() + set(system_libs ${system_libs} ${PTHREAD_LIB}) if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ ) set(system_libs ${system_libs} z) endif() diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index 607b92e547a..690a2e376a3 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -53,6 +53,4 @@ add_llvm_unittest(SupportTests ) # ManagedStatic.cpp uses . -if(LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD) - target_link_libraries(SupportTests pthread) -endif() +target_link_libraries(SupportTests ${PTHREAD_LIB})