Repository: conan-io/conan

Issue:
CXX_STANDARD is set to invalid value '20'
Ok, 3rd bug with C++20. This time in Conan 1.4.1 and cmake generator:

```
/bin/sh -c 'mkdir -p Build && cd Build && conan install .. --settings build_type=Debug && conan build .. --configure'
----------Building project:[ Library - Debug ]----------
PROJECT: Installing /home/lyberta/Stuff/C++/ftz/Serialization/conanfile.py
Requirements
Packages
PROJECT: Generator cmake created conanbuildinfo.cmake
PROJECT: Generator txt created conanbuildinfo.txt
PROJECT: Generated conaninfo.txt
Project: Running build()
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: Compiler GCC>=5, checking major version 8
-- Conan: Checking correct version: 8
-- Conan: Using cmake targets configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan setting CPP STANDARD: 20 WITH EXTENSIONS OFF
-- Conan: C++ stdlib: libstdc++11
-- Configuring done
CMake Error at CMakeLists.txt:21 (add_library):
  CXX_STANDARD is set to invalid value '20'
-- Generating done
-- Build files have been written to: /home/lyberta/Stuff/C++/ftz/Serialization/Build
ERROR: ftzSerialization/Latest@PROJECT: Error in build() method, line 17
	cmake.configure(source_dir = self.source_folder)
	ConanException: Error 256 while executing cd '/home/lyberta/Stuff/C++/ftz/Serialization/Build' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug" -DCONAN_CMAKE_CXX_STANDARD="20" -DCONAN_CMAKE_CXX_EXTENSIONS="OFF" -DCONAN_STD_CXX_FLAG="-std=c++2a" -DCONAN_EXPORTED="1" -DCONAN_COMPILER="gcc" -DCONAN_COMPILER_VERSION="8" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libstdc++11" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="/home/lyberta/Stuff/C++/ftz/Serialization/Build/package" -Wno-dev '/home/lyberta/Stuff/C++/ftz/Serialization'
```

I'm not sure how to fix this one. Maybe don't set CXX_STANDARD at all and use compiler flag directly. When CMake adds official support for C++20, I think there should be a version check and current clean approach.

EDIT: I see that CMake git master added support for 20.


Discussion:
Note you have different compiler versions for gcc and gxx:

```
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 8.1.0
```
This is dangerous, I suggest to install both to the same version.
Yes, I am not sure how to fix this, as it is not per-se a conan bug, but something missing in CMake. The workaround to CMake until master is released could be implemented here:

```cmake
macro(conan_set_std)
  # Do not warn "Manually-specified variables were not used by the project"
  set(ignorevar "${CONAN_STD_CXX_FLAG}${CONAN_CMAKE_CXX_STANDARD}${CONAN_CMAKE_CXX_EXTENSIONS}")
  if (CMAKE_VERSION VERSION_LESS "3.1")
    if(CONAN_STD_CXX_FLAG)
      message(STATUS "Conan setting CXX_FLAGS flags: ${CONAN_STD_CXX_FLAG}")
      set(CMAKE_CXX_FLAGS "-std=${CONAN_STD_CXX_FLAG} ${CMAKE_CXX_FLAGS}")
    endif()
  else()
    if(CONAN_CMAKE_CXX_STANDARD)
      message(STATUS "Conan setting CPP STANDARD: ${CONAN_CMAKE_CXX_STANDARD} WITH EXTENSIONS ${CONAN_CMAKE_CXX_EXTENSIONS}")
      set(CMAKE_CXX_STANDARD ${CONAN_CMAKE_CXX_STANDARD})
      set(CMAKE_CXX_EXTENSIONS ${CONAN_CMAKE_CXX_EXTENSIONS})
    endif()
  endif ()
endmacro()
```
Now with 1.4.3 I get:

    c++: error: unrecognized command line option '-std=-std=c++2a'; did you mean '--std=c++03'?
This is fixable by editing `conanbuildinfo.cmake`:

```
  # TODO: Check version where CMake supports 20, still not released
  if (CMAKE_VERSION VERSION_LESS "3.1" OR "${CONAN_CMAKE_CXX_STANDARD}" STREQUAL "20"
                                       OR "${CONAN_CMAKE_CXX_STANDARD}" STREQUAL "gnu20")
    if(CONAN_STD_CXX_FLAG)
      message(STATUS "Conan setting CXX_FLAGS flags: ${CONAN_STD_CXX_FLAG}")
      set(CMAKE_CXX_FLAGS "-std=${CONAN_STD_CXX_FLAG} ${CMAKE_CXX_FLAGS}")
    endif()
```

I've just removed `-std=` in line 6 in the snippet.
Looks like a bug from the very first implementation. Thanks you soooo much for your help and patience with this feature (totally my fault).

Resolving patch:
diff --git a/conans/client/generators/cmake_common.py b/conans/client/generators/cmake_common.py
--- a/conans/client/generators/cmake_common.py
+++ b/conans/client/generators/cmake_common.py
@@ -242,7 +242,7 @@ def generate_targets_section(dependencies):
                                        OR "${CONAN_CMAKE_CXX_STANDARD}" STREQUAL "gnu20")
     if(CONAN_STD_CXX_FLAG)
       message(STATUS "Conan setting CXX_FLAGS flags: ${CONAN_STD_CXX_FLAG}")
-      set(CMAKE_CXX_FLAGS "-std=${CONAN_STD_CXX_FLAG} ${CMAKE_CXX_FLAGS}")
+      set(CMAKE_CXX_FLAGS "${CONAN_STD_CXX_FLAG} ${CMAKE_CXX_FLAGS}")
     endif()
   else()
     if(CONAN_CMAKE_CXX_STANDARD)


Test patch: