_common_patterns FAIL_REGEX error on running cmake

I am migrating my dev boxes from RHEL8 (gcc11) to RHEL9 (gcc13) while maintaining the version of my cmake (3.21.3). Wile testing the migration, i’ve noticed the following error

/usr/share/cmake/Modules/Internal/CheckCompilerFlag.cmake(17):  check_compiler_flag_common_patterns(_common_patterns )
/usr/share/cmake/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake(10):  set(_common_patterns FAIL_REGEX [Uu]nrecogni[sz]ed .*option FAIL_REGEX switch .* is no longer supported FAIL_REGEX unknown .*option FAIL_REGEX optimization flag .* not supported FAIL_REGEX unknown argument ignored FAIL_REGEX ignoring unknown option FAIL_REGEX warning D9002 FAIL_REGEX option.*not supported FAIL_REGEX invalid argument .*option FAIL_REGEX ignoring option .*argument required FAIL_REGEX ignoring option .*argument is of wrong type FAIL_REGEX [Uu]nknown option FAIL_REGEX [Ww]arning: [Oo]ption FAIL_REGEX command option .* is not recognized FAIL_REGEX command option .* contains an incorrect subargument FAIL_REGEX Option .* is not recognized.  Option will be ignored. FAIL_REGEX not supported in this configuration. ignored FAIL_REGEX File with unknown suffix passed to linker FAIL_REGEX [Uu]nknown switch FAIL_REGEX WARNING: unknown flag: FAIL_REGEX Incorrect command line option: FAIL_REGEX Warning: illegal option FAIL_REGEX [Ww]arning: Invalid suboption FAIL_REGEX An invalid option .* appears on the command line FAIL_REGEX WARNING: invalid compiler option )
/usr/share/cmake/Modules/Internal/CheckCompilerFlag.cmake(18):  cmake_check_source_compiles(${_lang} ${_lang_src} ${_var} ${_lang_fail_regex} ${_common_patterns} OUTPUT_VARIABLE _output )

This error is elicited from calling the following function

function(set_compiler_flag _result)
    # loop over all flags, try to find the first which works
    set(_list_of_flags_result)
    foreach(_arg IN ITEMS ${ARGN})
        check_cxx_compiler_flag("${_arg}" _${_arg}_works)

        # if the flag works, use it,
        if(_${_arg}_works)
            list(APPEND _list_of_flags_result "${_arg}")
        endif()
	 list(APPEND _list_of_flags_result "${_arg}")
    endforeach()

    set(${_result} "${_list_of_flags_result}" PARENT_SCOPE)
endfunction()

From this call site

    set_compiler_flag(GCC_FLAGS
                      "-Wall"
                      "-Wextra"
                      "-Wcast-qual"
                      "-Wconversion-null"
                      "-Wmissing-declarations"
                      "-Woverlength-strings"
                      "-Wpointer-arith"
                      "-Wunused-local-typedefs"
                      "-Wunused-result"
                      "-Wvarargs"
                      "-Wvla"
                      "-Wwrite-strings"
                      "-Wno-sign-compare"
                      "-pipe"
                      "-fconcepts"
                      "-g" # always include debug information - even for releases

                      # We disable the AVX512 instruction sets to avoid CPU frequency throttling
                      "-march=native"
                      "-mno-avx512f"
                      "-mno-avx512pf"
                      "-mno-avx512er"
                      "-mno-avx512cd"
                      )

Any ideas why it doesn’t work on RH9 for the same version of cmake?

The output you’ve posted doesn’t look like an error, but a normal piece of cmake --trace output. If you’re getting an error, can you post that?

Hi @Angew,
Thanks. All the compiler flags now fail the check_cxx_compiler_flag tests as follows. What is baffling is that I can invoke the compiler (when called standalone) with these flags successfully

-- Performing Test _-fexceptions_works
-- Performing Test _-fexceptions_works - Failed
-- Performing Test _-Wall_works
-- Performing Test _-Wall_works - Failed
-- Performing Test _-Wextra_works
-- Performing Test _-Wextra_works - Failed
-- Performing Test _-Wcast-qual_works
-- Performing Test _-Wcast-qual_works - Failed
-- Performing Test _-Wconversion-null_works
-- Performing Test _-Wconversion-null_works - Failed
-- Performing Test _-Wmissing-declarations_works
-- Performing Test _-Wmissing-declarations_works - Failed
-- Performing Test _-Woverlength-strings_works
-- Performing Test _-Woverlength-strings_works - Failed
-- Performing Test _-Wpointer-arith_works
-- Performing Test _-Wpointer-arith_works - Failed
-- Performing Test _-Wunused-local-typedefs_works
-- Performing Test _-Wunused-local-typedefs_works - Failed
-- Performing Test _-Wunused-result_works
-- Performing Test _-Wunused-result_works - Failed
-- Performing Test _-Wvarargs_works
-- Performing Test _-Wvarargs_works - Failed
-- Performing Test _-Wvla_works
-- Performing Test _-Wvla_works - Failed
-- Performing Test _-Wwrite-strings_works
-- Performing Test _-Wwrite-strings_works - Failed
-- Performing Test _-Wno-sign-compare_works
-- Performing Test _-Wno-sign-compare_works - Failed
-- Performing Test _-pipe_works
-- Performing Test _-pipe_works - Failed
-- Performing Test _-fconcepts_works
-- Performing Test _-fconcepts_works - Failed
-- Performing Test _-g_works
-- Performing Test _-g_works - Failed
-- Performing Test _-march=native_works
-- Performing Test _-march=native_works - Failed
-- Performing Test _-mno-avx512f_works
-- Performing Test _-mno-avx512f_works - Failed
-- Performing Test _-mno-avx512pf_works
-- Performing Test _-mno-avx512pf_works - Failed
-- Performing Test _-mno-avx512er_works
-- Performing Test _-mno-avx512er_works - Failed
-- Performing Test _-mno-avx512cd_works
-- Performing Test _-mno-avx512cd_works - Failed
-- Performing Test _-Wno-conversion-null_works
-- Performing Test _-Wno-conversion-null_works - Failed
-- Performing Test _-Wno-missing-declarations_works
-- Performing Test _-Wno-missing-declarations_works - Failed
-- Performing Test _-Wno-unused-function_works
-- Performing Test _-Wno-unused-function_works - Failed
-- Performing Test _-Wno-unused-parameter_works
-- Performing Test _-Wno-unused-parameter_works - Failed
-- Performing Test _-O0_works
-- Performing Test _-O0_works - Failed
-- Performing Test _-Wno-deprecated_works
-- Performing Test _-Wno-deprecated_works - Failed
-- Performing Test _-fno-omit-frame-pointer_works
-- Performing Test _-fno-omit-frame-pointer_works - Failed

You could try a test for just one flag (instead of the loop in the function), and run the CMake with --debug-trycompile. That will ensure that the CMakeList and Makefile used by CMake for the try_compile() inside check_cxx_compiler_flag() remain on disk, and you can then inspect/build them manually. It might help you figure out what’s going wrong.

The docs of check_cxx_compiler_flag() mention that variables like CMAKE_CXX_FLAGS get passed along and can skew the result, you might want to rule that out as a possible cause.

Hi @Angew that was helpful. I can now see the error clearly after adding --debug-trycompile

Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_67e05/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_67e05.dir/build.make CMakeFiles/cmTC_67e05.dir/build
gmake[1]: Entering directory '/apps/qtg/home/valentine/projects/bluebox/cmake-build-debug/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_67e05.dir/src.cxx.o
/opt/rh/gcc-toolset-13/root/usr/bin/c++   -pthread -latomic -D_GLIBCXX_USE_CXX11_ABI=1    -D_-Wcast-qual_works -Wcast-qual -std=gnu++20 -o CMakeFiles/cmTC_67e05.dir/src.cxx.o -c /apps/qtg/home/valentine/projects/bluebox/cmake-build-debug/CMakeFiles/CMakeTmp/src.cxx
<command-line>: warning: ISO C++11 requires whitespace after the macro name
Linking CXX executable cmTC_67e05
/opt/cmake/cmake-3.21.3-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_67e05.dir/link.txt --verbose=1
/opt/rh/gcc-toolset-13/root/usr/bin/c++  -pthread -latomic -D_GLIBCXX_USE_CXX11_ABI=1  -Wl,--disable-new-dtags  CMakeFiles/cmTC_67e05.dir/src.cxx.o -o cmTC_67e05
/opt/rh/gcc-toolset-13/root/usr/libexec/gcc/x86_64-redhat-linux/13/ld: cannot find -latomic: No such file or directory

The obvious issue is that the linker cant find libatomic.so which I can sort but I am also seeing a less fatal issue where we are passing the second variable to check_cxx_compiler_flag to the compiler flags in -D_-Wcast-qual_works which is odd.

I believe that’s CMake’s doing, and as such I don’t expect that to be an issue. Quoting docs of CheckSourceCompiles (which is used internally by the flag check mechanism):

A definition for the name specified by <resultVar> will also be added automatically.

Thanks for all your help @Angew . I think I am fine now.