1cmake_minimum_required(VERSION 3.13.4) 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 33# TODO: Implement blockaddress in GlobalISel and remove this flag! 34if (CMAKE_C_COMPILER_ID STREQUAL "Clang") 35 check_c_compiler_flag("-fno-experimental-isel" C_HAS_EXPERIMENTAL_ISEL_FLAG) 36 check_cxx_compiler_flag("-fno-experimental-isel" CXX_HAS_EXPERIMENTAL_ISEL_FLAG) 37 macro(add_experimental_isel_flag lang) 38 if (${lang}_HAS_EXPERIMENTAL_ISEL_FLAG) 39 set(${lang}_FLAGS "-fno-experimental-isel ${${lang}_FLAGS}") 40 endif() 41 endmacro(add_experimental_isel_flag) 42 43 add_experimental_isel_flag(C) 44 add_experimental_isel_flag(CXX) 45endif() 46 47check_c_compiler_flag("-fno-omit-frame-pointer" C_HAS_OMIT_FRAME_POINTER) 48check_cxx_compiler_flag("-fno-omit-frame-pointer" CXX_HAS_OMIT_FRAME_POINTER) 49 50set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 51set(CMAKE_REQUIRED_FLAGS "-fsanitize=thread") 52check_c_compiler_flag("" C_HAS_TSAN_FLAG) 53check_cxx_compiler_flag("" CXX_HAS_TSAN_FLAG) 54set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) 55 56# Check if omp.h header exists for the test compiler 57check_include_file_cxx(omp.h CXX_HAS_OMP_H) 58check_include_file(omp.h C_HAS_OMP_H) 59 60write_compiler_information(C) 61write_compiler_information(CXX) 62