aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorDimitry Andric <dimitry@andric.com>2019-04-03 18:11:36 +0000
committerDimitry Andric <dimitry@andric.com>2019-04-03 18:11:36 +0000
commitcf0276b9ab4dba5d77a131fcf4061e5e2172d8eb (patch)
treea29d2ebc17eaa0b015211037f09a33f853fc5a72 /cmake
parent3e3199a8000cd9d3b8f9f36a12798cc336fcd63f (diff)
Ensure correct pthread flags and libraries are used
On most platforms, certain compiler and linker flags have to be passed when using pthreads, otherwise linking against libomp.so might fail with undefined references to several pthread functions. Use CMake's `find_package(Threads)` to determine these for standalone builds, or take them (and optionally modify them) from the top-level LLVM cmake files. Also, On FreeBSD, ensure that libomp.so is linked against libm.so, similar to NetBSD. Adjust test cases with hardcoded `-lpthread` flag to use the common build flags, which should now have the required pthread flags. Reviewers: emaste, jlpeyton, krytarowski, mgorny, protze.joachim, Hahnfeld Reviewed By: Hahnfeld Subscribers: AndreyChurbanov, tra, EricWF, Hahnfeld, jfb, jdoerfert, openmp-commits Tags: #openmp Differential Revision: https://reviews.llvm.org/D59451 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@357618 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/DetectTestCompiler/CMakeLists.txt8
-rw-r--r--cmake/OpenMPTesting.cmake10
2 files changed, 15 insertions, 3 deletions
diff --git a/cmake/DetectTestCompiler/CMakeLists.txt b/cmake/DetectTestCompiler/CMakeLists.txt
index c2f408c..1fd7cc7 100644
--- a/cmake/DetectTestCompiler/CMakeLists.txt
+++ b/cmake/DetectTestCompiler/CMakeLists.txt
@@ -18,8 +18,12 @@ if (NOT OpenMP_Found)
set(OpenMP_CXX_FLAGS "-fopenmp")
endif()
-set(C_FLAGS ${flags} ${OpenMP_C_FLAGS})
-set(CXX_FLAGS ${flags} ${OpenMP_CXX_FLAGS})
+set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+set(THREADS_PREFER_PTHREAD_FLAG TRUE)
+find_package(Threads REQUIRED)
+
+set(C_FLAGS "${OpenMP_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
+set(CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
# TODO: Implement blockaddress in GlobalISel and remove this flag!
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
diff --git a/cmake/OpenMPTesting.cmake b/cmake/OpenMPTesting.cmake
index 187c874..396460a 100644
--- a/cmake/OpenMPTesting.cmake
+++ b/cmake/OpenMPTesting.cmake
@@ -120,8 +120,16 @@ else()
set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}")
set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_MAJOR_VERSION}")
set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_MAJOR_VERSION}.${LLVM_MINOR_VERSION}")
+ # Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's
+ # CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work
+ # around that, until it is fixed there.
+ if(${CMAKE_THREAD_LIBS_INIT} STREQUAL "-lpthread")
+ set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread")
+ else()
+ set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
# TODO: Implement blockaddress in GlobalISel and remove this flag!
- set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp -fno-experimental-isel")
+ set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS} -fno-experimental-isel")
endif()
# Function to set compiler features for use in lit.