Fix cmake `-Wno` compiler flag testing (#6145)
This commit is contained in:
parent
9fc7143fce
commit
d1462f3120
|
@ -68,15 +68,45 @@ function(_verilator_check_cxx_libraries LIBRARIES RESVAR)
|
|||
set("${RESVAR}" "${${RESVAR}}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(_verilator_check_cxx_compiler_flag FLAG RESVAR)
|
||||
# Check whether the compiler understands the flag FLAG
|
||||
set(_VERILATOR_CHECK_CXX_COMPILER_FLAG_SRC
|
||||
"
|
||||
#warning warning
|
||||
int main() { return 0; }
|
||||
"
|
||||
)
|
||||
set(CMAKE_REQUIRED_FLAGS ${FLAG})
|
||||
# Make sure the compiler warning is not turned into an error
|
||||
string(APPEND CMAKE_REQUIRED_FLAGS " -Wno-error=cpp")
|
||||
set(CMAKE_REQUIRED_DEFINITIONS)
|
||||
set(CMAKE_REQUIRED_INCLUDES)
|
||||
set(CMAKE_REQUIRED_LINK_OPTIONS)
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
set(CMAKE_REQUIRED_QUIET)
|
||||
|
||||
check_compiler_flag_common_patterns(_common_patterns)
|
||||
check_cxx_source_compiles(
|
||||
"${_VERILATOR_CHECK_CXX_COMPILER_FLAG_SRC}"
|
||||
"${RESVAR}"
|
||||
FAIL_REGEX
|
||||
"command[ -]line option .* is valid for .* but not for C[+][+]"
|
||||
FAIL_REGEX
|
||||
"-Werror=.* argument .* is not valid for C[+][+]"
|
||||
${_common_patterns}
|
||||
)
|
||||
set("${RESVAR}" "${${RESVAR}}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Check compiler flag support. Skip on MSVC, these are all GCC flags.
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
||||
if(NOT DEFINED VERILATOR_CFLAGS OR NOT DEFINED VERILATOR_MT_CFLAGS)
|
||||
include(CheckCXXCompilerFlag)
|
||||
foreach(FLAG @CFG_CXX_FLAGS_CMAKE@)
|
||||
string(MAKE_C_IDENTIFIER ${FLAG} FLAGNAME)
|
||||
check_cxx_compiler_flag(${FLAG} ${FLAGNAME})
|
||||
_verilator_check_cxx_compiler_flag(${FLAG} ${FLAGNAME})
|
||||
if(${FLAGNAME})
|
||||
list(APPEND VERILATOR_CFLAGS ${FLAG})
|
||||
list(APPEND VERILATOR_CFLAGS $<$<COMPILE_LANGUAGE:CXX>:${FLAG}>)
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(FLAG @CFG_LDFLAGS_THREADS_CMAKE@)
|
||||
|
|
Loading…
Reference in New Issue