Replace CMAKE_REQUIRED_FLAGS with CMAKE_CXX_FLAGS

This prevents C++ flags from being passed to the C compiler while
running CMake tests.