Open fekir opened 1 year ago
Hi @fekir
Thanks for reporting.
Indeed, there is some wrong there, the c++11 flag doesn't exist for msvc
, lets fix it.
Uhm, can't reproduce it here, and checking the code I see:
function(detect_cxx_standard CXX_STANDARD)
set(${CXX_STANDARD} ${CMAKE_CXX_STANDARD} PARENT_SCOPE)
if (CMAKE_CXX_EXTENSIONS)
set(${CXX_STANDARD} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE)
endif()
endfunction()
It seems the only way to end with compiler.cppstd
in the detected profile is somehow CMAKE_CXX_STANDARD
is defined in the CMakeLists.txt
. Could you please double check this?
Doh
set(CMAKE_CXX_STANDARD 11)
When not using conan, this line is not problematic in cmake.
Note that the source code is unchanged, so you should be able to reproduce it
Ok, that would make sense.
Conan need to know what compiler.cppstd
value should be used to install dependencies, and the way to obtain it when running from CMake is from the CMAKE_CXX_STANDARD.
To be honest, not sure what Conan should be doing here, it feels like trying to automagically come up with a different cppstd
value would be not only difficult but probably very fragile and problematic for users.
From what I remember, Visual C++ does not really have compiler flags for C++11 (Starts with C++14, docs here), so that's what Conan mirrors and that's why there is an error if C++11 is passed.
I suspect the behaviour is different within CMake itself, and when it encounters set(CMAKE_CXX_STANDARD 11)
- CMake either does not pass any flag and relies on the compiler built-in defaults, or passes /std:c++14
, I need to verify this. -
In practice I think this would mean that any value prior to C++14 may actually be equivalent to C++14 ... if that is the case, we could probably have logic in the profile detection to cover this case.
Talking about auto-detecting compiler.cppstd
flag, I think it would be great to keep an option that would suppress the default detected C++ standard.
Most of the conan packages (at least conan-center ones) are built using the default compiler cppstd or defined by the library, which means that there's no compiler.cppstd
setting. After using the conan extensively and porting all the recipes to 2.0, the usual use-case in CMakeLists.txt was that the set(CMAKE_CXX_STANDARD YY)
was set prior to running conan package installation, which resulted in auto-detected compiler.cppstd
, which needed to be manually discarded from the settings, since no package binaries matched the specified settings.
Most of the conan packages (at least conan-center ones) are built using the default compiler cppstd or defined by the library, which means that there's no
compiler.cppstd
setting.
This is actively changing for the 2.0 pipeline and we are trying to roll this feature out :)
When executing
cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCMAKE_BUILD_TYPE=Release
as described in https://github.com/conan-io/cmake-conan/blob/develop2/README.md I get following error:my ~/.conan2/profiles/default looks like
and was created with
conan profile detect
AFAIK the microsoft compiler does not have a flag for c++11