2017-12-01 01:08:31 +08:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
project(DetectTestCompiler C CXX)
|
|
|
|
|
2018-02-15 16:10:22 +08:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2017-12-01 01:08:31 +08:00
|
|
|
function(write_compiler_information lang)
|
|
|
|
set(information "${CMAKE_${lang}_COMPILER}")
|
|
|
|
set(information "${information}\\;${CMAKE_${lang}_COMPILER_ID}")
|
|
|
|
set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}")
|
2018-02-15 16:10:22 +08:00
|
|
|
set(information "${information}\\;${${lang}_FLAGS}")
|
2017-12-01 01:08:31 +08:00
|
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information})
|
|
|
|
endfunction(write_compiler_information)
|
|
|
|
|
|
|
|
find_package(OpenMP)
|
|
|
|
if (NOT OpenMP_Found)
|
|
|
|
set(OpenMP_C_FLAGS "-fopenmp")
|
|
|
|
set(OpenMP_CXX_FLAGS "-fopenmp")
|
|
|
|
endif()
|
|
|
|
|
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
llvm-svn: 357618
2019-04-04 02:11:36 +08:00
|
|
|
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}")
|
2018-02-15 16:10:22 +08:00
|
|
|
|
|
|
|
# TODO: Implement blockaddress in GlobalISel and remove this flag!
|
|
|
|
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
|
|
|
check_c_compiler_flag("-fno-experimental-isel" C_HAS_EXPERIMENTAL_ISEL_FLAG)
|
|
|
|
check_cxx_compiler_flag("-fno-experimental-isel" CXX_HAS_EXPERIMENTAL_ISEL_FLAG)
|
|
|
|
macro(add_experimental_isel_flag lang)
|
|
|
|
if (${lang}_HAS_EXPERIMENTAL_ISEL_FLAG)
|
|
|
|
set(${lang}_FLAGS "-fno-experimental-isel ${${lang}_FLAGS}")
|
|
|
|
endif()
|
|
|
|
endmacro(add_experimental_isel_flag)
|
|
|
|
|
|
|
|
add_experimental_isel_flag(C)
|
|
|
|
add_experimental_isel_flag(CXX)
|
|
|
|
endif()
|
|
|
|
|
2017-12-01 01:08:31 +08:00
|
|
|
write_compiler_information(C)
|
|
|
|
write_compiler_information(CXX)
|