Commit ab5d0b03 authored by Tom Stellard's avatar Tom Stellard
Browse files

Merging r294690:

------------------------------------------------------------------------
r294690 | ericwf | 2017-02-09 20:59:20 -0500 (Thu, 09 Feb 2017) | 13 lines

[CMake] Fix pthread handling for out-of-tree builds

LLVM defines `PTHREAD_LIB` which is used by AddLLVM.cmake and various projects
to correctly link the threading library when needed. Unfortunately
`PTHREAD_LIB` is defined by LLVM's `config-ix.cmake` file which isn't installed
and therefore can't be used when configuring out-of-tree builds. This causes
such builds to fail since `pthread` isn't being correctly linked.

This patch attempts to fix that problem by renaming and exporting
`LLVM_PTHREAD_LIB` as part of`LLVMConfig.cmake`. I renamed `PTHREAD_LIB`
because It seemed likely to cause collisions with downstream users of
`LLVMConfig.cmake`.

------------------------------------------------------------------------

llvm-svn: 303399
parent 45e3f34a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ if(HAVE_LIBPTHREAD)
  set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  set(THREADS_HAVE_PTHREAD_ARG Off)
  find_package(Threads REQUIRED)
  set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
  set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
endif()

# Don't look for these libraries on Windows. Also don't look for them if we're
+3 −3
Original line number Diff line number Diff line
@@ -718,11 +718,11 @@ macro(add_llvm_executable name)
  if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
    llvm_externalize_debuginfo(${name})
  endif()
  if (PTHREAD_LIB)
  if (LLVM_PTHREAD_LIB)
    # libpthreads overrides some standard library symbols, so main
    # executable must be linked with it in order to provide consistent
    # API for all shared libaries loaded by this executable.
    target_link_libraries(${name} ${PTHREAD_LIB})
    target_link_libraries(${name} ${LLVM_PTHREAD_LIB})
  endif()
endmacro(add_llvm_executable name)

@@ -1027,7 +1027,7 @@ function(add_unittest test_suite test_name)
  # libpthreads overrides some standard library symbols, so main
  # executable must be linked with it in order to provide consistent
  # API for all shared libaries loaded by this executable.
  target_link_libraries(${test_name} gtest_main gtest ${PTHREAD_LIB})
  target_link_libraries(${test_name} gtest_main gtest ${LLVM_PTHREAD_LIB})

  add_dependencies(${test_suite} ${test_name})
  get_target_property(test_suite_folder ${test_suite} FOLDER)
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@ set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)

set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@)

if (NOT "@LLVM_PTHREAD_LIB@" STREQUAL "")
  set(LLVM_PTHREAD_LIB "@LLVM_PTHREAD_LIB@")
endif()

set(LLVM_ENABLE_PLUGINS @LLVM_ENABLE_PLUGINS@)
set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS @LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@)
set(LLVM_PLUGIN_EXT @LLVM_PLUGIN_EXT@)
+1 −1
Original line number Diff line number Diff line
@@ -11,4 +11,4 @@ add_llvm_example(ParallelJIT
  ParallelJIT.cpp
  )

target_link_libraries(ParallelJIT ${PTHREAD_LIB})
target_link_libraries(ParallelJIT ${LLVM_PTHREAD_LIB})
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ add_llvm_library(LLVMCodeGen
  ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen
  ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen/PBQP

  LINK_LIBS ${PTHREAD_LIB}
  LINK_LIBS ${LLVM_PTHREAD_LIB}

  DEPENDS
  intrinsics_gen
Loading