1cmake_minimum_required(VERSION 3.20.0) 2project(DetectTestCompiler C CXX) 3 4include(CheckCCompilerFlag) 5include(CheckCXXCompilerFlag) 6include(CheckIncludeFile) 7include(CheckIncludeFileCXX) 8 9function(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}) 18endfunction(write_compiler_information) 19 20find_package(OpenMP) 21if (NOT OpenMP_Found) 22 set(OpenMP_C_FLAGS "-fopenmp") 23 set(OpenMP_CXX_FLAGS "-fopenmp") 24endif() 25 26set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 27set(THREADS_PREFER_PTHREAD_FLAG TRUE) 28find_package(Threads REQUIRED) 29 30set(C_FLAGS "${OpenMP_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") 31set(CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") 32 33check_c_compiler_flag("-fno-omit-frame-pointer" C_HAS_OMIT_FRAME_POINTER) 34check_cxx_compiler_flag("-fno-omit-frame-pointer" CXX_HAS_OMIT_FRAME_POINTER) 35 36set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 37set(CMAKE_REQUIRED_FLAGS "-fsanitize=thread") 38check_c_compiler_flag("" C_HAS_TSAN_FLAG) 39check_cxx_compiler_flag("" CXX_HAS_TSAN_FLAG) 40set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) 41 42# Check if omp.h header exists for the test compiler 43check_include_file_cxx(omp.h CXX_HAS_OMP_H) 44check_include_file(omp.h C_HAS_OMP_H) 45 46write_compiler_information(C) 47write_compiler_information(CXX) 48