llvm.org GIT mirror llvm / f717a4e
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`. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@303399 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 2 years ago
11 changed file(s) with 18 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
114114 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
115115 set(THREADS_HAVE_PTHREAD_ARG Off)
116116 find_package(Threads REQUIRED)
117 set(PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
117 set(LLVM_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
118118 endif()
119119
120120 # Don't look for these libraries on Windows. Also don't look for them if we're
717717 if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO)
718718 llvm_externalize_debuginfo(${name})
719719 endif()
720 if (PTHREAD_LIB)
720 if (LLVM_PTHREAD_LIB)
721721 # libpthreads overrides some standard library symbols, so main
722722 # executable must be linked with it in order to provide consistent
723723 # API for all shared libaries loaded by this executable.
724 target_link_libraries(${name} ${PTHREAD_LIB})
724 target_link_libraries(${name} ${LLVM_PTHREAD_LIB})
725725 endif()
726726 endmacro(add_llvm_executable name)
727727
10261026 # libpthreads overrides some standard library symbols, so main
10271027 # executable must be linked with it in order to provide consistent
10281028 # API for all shared libaries loaded by this executable.
1029 target_link_libraries(${test_name} gtest_main gtest ${PTHREAD_LIB})
1029 target_link_libraries(${test_name} gtest_main gtest ${LLVM_PTHREAD_LIB})
10301030
10311031 add_dependencies(${test_suite} ${test_name})
10321032 get_target_property(test_suite_folder ${test_suite} FOLDER)
4444
4545 set(LLVM_BUILD_32_BITS @LLVM_BUILD_32_BITS@)
4646
47 if (NOT "@LLVM_PTHREAD_LIB@" STREQUAL "")
48 set(LLVM_PTHREAD_LIB "@LLVM_PTHREAD_LIB@")
49 endif()
50
4751 set(LLVM_ENABLE_PLUGINS @LLVM_ENABLE_PLUGINS@)
4852 set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS @LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@)
4953 set(LLVM_PLUGIN_EXT @LLVM_PLUGIN_EXT@)
1010 ParallelJIT.cpp
1111 )
1212
13 target_link_libraries(ParallelJIT ${PTHREAD_LIB})
13 target_link_libraries(ParallelJIT ${LLVM_PTHREAD_LIB})
146146 ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen
147147 ${LLVM_MAIN_INCLUDE_DIR}/llvm/CodeGen/PBQP
148148
149 LINK_LIBS ${PTHREAD_LIB}
149 LINK_LIBS ${LLVM_PTHREAD_LIB}
150150
151151 DEPENDS
152152 intrinsics_gen
33 set(LLVM_INTEL_JIT_LIBS ${CMAKE_DL_LIBS})
44 endif()
55
6 set(LLVM_INTEL_JIT_LIBS ${PTHREAD_LIB} ${LLVM_INTEL_JIT_LIBS})
6 set(LLVM_INTEL_JIT_LIBS ${LLVM_PTHREAD_LIB} ${LLVM_INTEL_JIT_LIBS})
77
88
99 add_llvm_library(LLVMIntelJITEvents
3131 add_library(LLVMFuzzerNoMain STATIC
3232 $
3333 )
34 target_link_libraries(LLVMFuzzerNoMain ${PTHREAD_LIB})
34 target_link_libraries(LLVMFuzzerNoMain ${LLVM_PTHREAD_LIB})
3535 add_library(LLVMFuzzer STATIC
3636 FuzzerMain.cpp
3737 $
3838 )
39 target_link_libraries(LLVMFuzzer ${PTHREAD_LIB})
39 target_link_libraries(LLVMFuzzer ${LLVM_PTHREAD_LIB})
4040
4141 if( LLVM_INCLUDE_TESTS )
4242 add_subdirectory(test)
1616 if( LLVM_ENABLE_THREADS AND HAVE_LIBATOMIC )
1717 set(system_libs ${system_libs} atomic)
1818 endif()
19 set(system_libs ${system_libs} ${PTHREAD_LIB})
19 set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB})
2020 if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ )
2121 set(system_libs ${system_libs} z)
2222 endif()
2020 RPCUtilsTest.cpp
2121 )
2222
23 target_link_libraries(OrcJITTests ${PTHREAD_LIB})
23 target_link_libraries(OrcJITTests ${LLVM_PTHREAD_LIB})
6262 )
6363
6464 # ManagedStatic.cpp uses .
65 target_link_libraries(SupportTests ${PTHREAD_LIB})
65 target_link_libraries(SupportTests ${LLVM_PTHREAD_LIB})
3939 add_definitions( -DGTEST_HAS_PTHREAD=0 )
4040 endif()
4141
42 find_library(PTHREAD_LIBRARY_PATH pthread)
43 if (PTHREAD_LIBRARY_PATH)
42 find_library(LLVM_PTHREAD_LIBRARY_PATH pthread)
43 if (LLVM_PTHREAD_LIBRARY_PATH)
4444 list(APPEND LIBS pthread)
4545 endif()
4646