Skip to content

Commit

Permalink
Merge pull request ICLDisco#81 from abouteiller/cleanup/compiler-flags
Browse files Browse the repository at this point in the history
Import cmake compilerFlags from parsec/540
  • Loading branch information
abouteiller authored May 15, 2023
2 parents b958ae9 + 29e1a6e commit 8b36497
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions cmake_modules/DplasmaCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,63 @@ function(check_and_set_compiler_option)
set(options "")
set(oneValueArgs NAME COMMENT OPTION CONFIG)
set(multipleValueArgs LANGUAGES)
cmake_parse_arguments(parsec_cas_co "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
cmake_parse_arguments(dplasma_cas_co "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT DEFINED parsec_cas_co_OPTION)
if(NOT DEFINED dplasma_cas_co_OPTION)
foreach(v NAME COMMENT LANGUAGES OPTION)
message(STATUS "parsec_cas_co_${v} = ${parsec_cas_co_${v}}")
message(STATUS "dplasma_cas_co_${v} = ${dplasma_cas_co_${v}}")
endforeach()
message(FATAL_ERROR "OPTION not defined in call to check_and_set_compiler_option")
endif()

if(NOT DEFINED parsec_cas_co_NAME)
if(NOT DEFINED dplasma_cas_co_NAME)
message(FATAL_ERROR "NAME not defined in call to check_and_set_compiler_option")
endif()

if(NOT DEFINED parsec_cas_co_LANGUAGES)
set(parsec_cas_co_LANGUAGES C CXX Fortran)
if(NOT DEFINED dplasma_cas_co_LANGUAGES)
set(dplasma_cas_co_LANGUAGES C Fortran)
endif()

if(NOT DEFINED ${parsec_cas_co_NAME})
# Not found in the cache, run the detection
message(CHECK_START "Performing Test for flag ${parsec_cas_co_OPTION} ")
set(save_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET true)
set(_supported_languages "")

foreach(parsec_cas_co_LANGUAGE ${parsec_cas_co_LANGUAGES})
if(CMAKE_${parsec_cas_co_LANGUAGE}_COMPILER_WORKS)
message(TRACE "Checking flag ${parsec_cas_co_OPTION} for language ${parsec_cas_co_LANGUAGE}")
cmake_language(CALL "check_${parsec_cas_co_LANGUAGE}_compiler_flag" "${parsec_cas_co_OPTION}" "${parsec_cas_co_NAME}_${parsec_cas_co_LANGUAGE}" )
if( "${${parsec_cas_co_NAME}_${parsec_cas_co_LANGUAGE}}" )
set(_supported_languages "${parsec_cas_co_LANGUAGE};${_supported_languages}")
message(TRACE "Flag ${parsec_cas_co_OPTION} supported by ${parsec_cas_co_LANGUAGE}")
if(DEFINED parsec_cas_co_CONFIG)
list(APPEND parsec_cas_co_defined_options "$<$<CONFIG:${parsec_cas_co_CONFIG}>:$<$<COMPILE_LANGUAGE:${parsec_cas_co_LANGUAGE}>:${parsec_cas_co_OPTION}>>")
else()
list(APPEND parsec_cas_co_defined_options "$<$<COMPILE_LANGUAGE:${parsec_cas_co_LANGUAGE}>:${parsec_cas_co_OPTION}>")
endif()
message(TRACE "Performing Test Flag ${dplasma_cas_co_OPTION} supported by languages")
set(_supported_languages "")
set(dplasma_cas_co_defined_options "")
set(save_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET true)
foreach(dplasma_cas_co_LANGUAGE ${dplasma_cas_co_LANGUAGES})
if(CMAKE_${dplasma_cas_co_LANGUAGE}_COMPILER_WORKS)
message(TRACE " Checking flag ${dplasma_cas_co_OPTION} for language ${dplasma_cas_co_LANGUAGE}")
cmake_language(CALL "check_${dplasma_cas_co_LANGUAGE}_compiler_flag" "${dplasma_cas_co_OPTION}" "${dplasma_cas_co_NAME}_${dplasma_cas_co_LANGUAGE}" )
if( "${${dplasma_cas_co_NAME}_${dplasma_cas_co_LANGUAGE}}" )
set(_supported_languages "${dplasma_cas_co_LANGUAGE};${_supported_languages}")
message(TRACE " Checking flag ${dplasma_cas_co_OPTION} for language ${dplasma_cas_co_LANGUAGE} - Supported")
if(DEFINED dplasma_cas_co_CONFIG)
list(APPEND dplasma_cas_co_defined_options "$<$<CONFIG:${dplasma_cas_co_CONFIG}>:$<$<COMPILE_LANGUAGE:${dplasma_cas_co_LANGUAGE}>:${dplasma_cas_co_OPTION}>>")
else()
list(APPEND dplasma_cas_co_defined_options "$<$<COMPILE_LANGUAGE:${dplasma_cas_co_LANGUAGE}>:${dplasma_cas_co_OPTION}>")
endif()
endif()
endforeach()
set(CMAKE_REQUIRED_QUIET ${save_CMAKE_REQUIRED_QUIET})
endif()
endforeach()
set(CMAKE_REQUIRED_QUIET ${save_CMAKE_REQUIRED_QUIET})

if(NOT DEFINED ${dplasma_cas_co_NAME} OR NOT ${dplasma_cas_co_NAME} STREQUAL dplasma_cas_co_defined_options)
# Something new found, output result
if( _supported_languages STREQUAL "" )
message(CHECK_FAIL "[none]")
message(STATUS "Performing Test Flag ${dplasma_cas_co_OPTION} supported by languages -\t[None]")
else( _supported_languages STREQUAL "" )
message(CHECK_PASS "[${_supported_languages}]")
message(STATUS "Performing Test Flag ${dplasma_cas_co_OPTION} supported by languages -\t[${_supported_languages}]")
endif( _supported_languages STREQUAL "" )
endif()

if(DEFINED parsec_cas_co_COMMENT)
set(${parsec_cas_co_NAME} "${parsec_cas_co_defined_options}" CACHE STRING "${parsec_cas_co_COMMENT}")
mark_as_advanced(${parsec_cas_co_NAME})
else()
set(${parsec_cas_co_NAME} "${parsec_cas_co_defined_options}" CACHE INTERNAL "Test result for ${parsec_cas_co_OPTION}")
endif()
endif(NOT DEFINED ${parsec_cas_co_NAME})
if(DEFINED dplasma_cas_co_COMMENT)
set(${dplasma_cas_co_NAME} "${dplasma_cas_co_defined_options}" CACHE INTERNAL "${dplasma_cas_co_COMMENT}")
else()
set(${dplasma_cas_co_NAME} "${dplasma_cas_co_defined_options}" CACHE INTERNAL "List of compile options for compiler flag ${dplasma_cas_co_OPTION}")
endif()

if(${parsec_cas_co_NAME})
message(TRACE "Add compile option ${${parsec_cas_co_NAME}}")
add_compile_options("${${parsec_cas_co_NAME}}")
if(${dplasma_cas_co_NAME})
message(TRACE "Add compile option ${${dplasma_cas_co_NAME}}")
add_compile_options("${${dplasma_cas_co_NAME}}")
endif()
endfunction(check_and_set_compiler_option)

Expand Down Expand Up @@ -163,8 +163,8 @@ endif(_match_icc)
add_compile_definitions($<$<CONFIG:RELEASE>:NDEBUG>)

if(CMAKE_GENERATOR STREQUAL "Ninja")
# Ninja is weird with colors. It does not present a pty to cc (hence
# colors get disabled by default), but if colors are forced upon it, it
# Ninja is weird with colors. It does not present a pty to cc (hence
# colors get disabled by default), but if colors are forced upon it, it
# will do the right thing and print colors only on terminals.
foreach(colorflag -fdiagnostics-color -fcolor-diagnostics)
string(REPLACE "-" "_" SAFE_colorflag ${colorflag})
Expand Down

0 comments on commit 8b36497

Please sign in to comment.