1cmake_minimum_required(VERSION 3.13.4) 2project(DetectTestCompiler C CXX) 3 4include(CheckCCompilerFlag) 5include(CheckCXXCompilerFlag) 6 7function(write_compiler_information lang) 8 set(information "${CMAKE_${lang}_COMPILER}") 9 set(information "${information}\\;${CMAKE_${lang}_COMPILER_ID}") 10 set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}") 11 set(information "${information}\\;${${lang}_FLAGS}") 12 set(information "${information}\\;${${lang}_HAS_TSAN_FLAG}") 13 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information}) 14endfunction(write_compiler_information) 15 16find_package(OpenMP) 17if (NOT OpenMP_Found) 18 set(OpenMP_C_FLAGS "-fopenmp") 19 set(OpenMP_CXX_FLAGS "-fopenmp") 20endif() 21 22set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 23set(THREADS_PREFER_PTHREAD_FLAG TRUE) 24find_package(Threads REQUIRED) 25 26set(C_FLAGS "${OpenMP_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") 27set(CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}") 28 29# TODO: Implement blockaddress in GlobalISel and remove this flag! 30if (CMAKE_C_COMPILER_ID STREQUAL "Clang") 31 check_c_compiler_flag("-fno-experimental-isel" C_HAS_EXPERIMENTAL_ISEL_FLAG) 32 check_cxx_compiler_flag("-fno-experimental-isel" CXX_HAS_EXPERIMENTAL_ISEL_FLAG) 33 macro(add_experimental_isel_flag lang) 34 if (${lang}_HAS_EXPERIMENTAL_ISEL_FLAG) 35 set(${lang}_FLAGS "-fno-experimental-isel ${${lang}_FLAGS}") 36 endif() 37 endmacro(add_experimental_isel_flag) 38 39 add_experimental_isel_flag(C) 40 add_experimental_isel_flag(CXX) 41endif() 42 43SET(CMAKE_REQUIRED_FLAGS "-fsanitize=thread") 44check_c_compiler_flag("" C_HAS_TSAN_FLAG) 45check_cxx_compiler_flag("" CXX_HAS_TSAN_FLAG) 46 47write_compiler_information(C) 48write_compiler_information(CXX) 49