This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by EricWF on Feb 4 2017, 7:14 PM.

Details

Summary

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.

Diff Detail

Event Timeline

EricWF created this revision.Feb 4 2017, 7:14 PM
EricWF edited the summary of this revision. (Show Details)Feb 5 2017, 3:46 AM
mgorny added inline comments.Feb 5 2017, 4:32 AM
cmake/modules/LLVMConfig.cmake.in
49

Are you sure that this is safe to do for every package doing find_package(LLVM)?

EricWF added inline comments.Feb 5 2017, 4:35 AM
cmake/modules/LLVMConfig.cmake.in
49

Perhaps not. I tested without it and it didn't immediately seem needed, at least on my platform. I'll look into moving or removing it.

EricWF updated this revision to Diff 87539.Feb 7 2017, 3:59 PM

Address @mgorny's comments and don't set CMAKE_THREAD_PREFER_PTHREAD and THREADS_HAVE_PTHREAD_ARG in LLVMConfig. These options are only needed during the initial configuration and should not be set when LLVMConfig is included by downstream users code.

beanz accepted this revision.Feb 8 2017, 3:18 PM

This looks reasonable to me.

This revision is now accepted and ready to land.Feb 8 2017, 3:18 PM
EricWF closed this revision.Feb 9 2017, 6:11 PM

This patch and the dependencies were committed as r294690.