1 cmake_minimum_required(VERSION 3.20.0)
2 project(DetectTestCompiler C CXX)
4 include(CheckCCompilerFlag)
5 include(CheckCXXCompilerFlag)
6 include(CheckIncludeFile)
7 include(CheckIncludeFileCXX)
9 function(write_compiler_information lang)
10 set(information "${CMAKE_${lang}_COMPILER}")
11 set(information "${information}\\;${CMAKE_${lang}_COMPILER_ID}")
12 set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}")
13 set(information "${information}\\;${${lang}_FLAGS}")
14 set(information "${information}\\;${${lang}_HAS_TSAN_FLAG}")
15 set(information "${information}\\;${${lang}_HAS_OMIT_FRAME_POINTER}")
16 set(information "${information}\\;${${lang}_HAS_OMP_H}")
17 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information})
18 endfunction(write_compiler_information)
22 set(OpenMP_C_FLAGS "-fopenmp")
23 set(OpenMP_CXX_FLAGS "-fopenmp")
26 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
27 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
28 find_package(Threads REQUIRED)
30 set(C_FLAGS "${OpenMP_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
31 set(CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
33 check_c_compiler_flag("-fno-omit-frame-pointer" C_HAS_OMIT_FRAME_POINTER)
34 check_cxx_compiler_flag("-fno-omit-frame-pointer" CXX_HAS_OMIT_FRAME_POINTER)
36 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
37 set(CMAKE_REQUIRED_FLAGS "-fsanitize=thread")
38 check_c_compiler_flag("" C_HAS_TSAN_FLAG)
39 check_cxx_compiler_flag("" CXX_HAS_TSAN_FLAG)
40 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
42 # Check if omp.h header exists for the test compiler
43 check_include_file_cxx(omp.h CXX_HAS_OMP_H)
44 check_include_file(omp.h C_HAS_OMP_H)
46 write_compiler_information(C)
47 write_compiler_information(CXX)