-
Notifications
You must be signed in to change notification settings - Fork 977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standard as an option #2042
Standard as an option #2042
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2042 +/- ##
===========================================
- Coverage 95.89% 94.16% -1.73%
===========================================
Files 350 352 +2
Lines 28056 28121 +65
===========================================
- Hits 26904 26481 -423
- Misses 1152 1640 +488 |
…into feature/standard_as_option
…into feature/standard_as_option
|
||
v98 = v98gnu = v11 = v11gnu = v14 = v14gnu = v17 = v17gnu = None | ||
|
||
if not float(clang_version) < 4.0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit hacky this comparison, not saying it doesnt work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, generally I like it. Please see comments.
if self._cppstd: | ||
if self._cppstd.endswith("gnu"): | ||
ret["CONAN_CMAKE_CXX_STANDARD"] = self._cppstd[:-3] | ||
ret["CONAN_CMAKE_CXX_EXTENSIONS"] = "ON" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe CONAN_CMAKE_CXX_GNU_EXTENSIONS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the variable in CMake is CMAKE_CXX_EXTENSIONS
:
set(CMAKE_CXX_EXTENSIONS OFF)
On some platforms, this results in linking to a different library (e.g. -std=c++11 rather than -std=gnu++11). The default behavior is for C++ extensions to be enabled.
if self.std: | ||
ret.append(self.std) | ||
|
||
ret.extend(['/D%s' % lib for lib in self.defines]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defines
only if self.std
?
|
||
def _get_cl_list(self, quotes=True): | ||
if quotes: | ||
ret = ['/I%s' % lib for lib in self.include_paths] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines are identical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
@@ -234,6 +234,30 @@ def generate_targets_section(dependencies): | |||
endif() | |||
endmacro() | |||
|
|||
macro(conan_set_std) | |||
if (CMAKE_VERSION VERSION_LESS "3.1") | |||
if(CONAN_STD_CXX_FLAG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully get the CONAN_STD_CXX_FLAG and CONAN_CMAKE_CXX_STANDARD, I guess something Cmake-ish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CONAN_STD_CXX_FLAG
: Only used in case the CMake < 3.1, it is directly the flag to pass to the compiler, because CMake < 3.1 do no support it another way. Includes the -std=XXXX
. Conan uses the compilers_info.py to translate to the correct flag depending on each compiler/version.
CONAN_CMAKE_CXX_STANDARD
: Used > 3.1. Do not include the -std=XXX
is directly the value of the standard, 98, 11, 14, 17. Internally CMake will translate it to the -std=xxx
taking also into account the CMAKE_CXX_EXTENSIONS
to know if it should like with "gnu++11" or just "c++11".
conans/model/conan_file.py
Outdated
def add_shared(self, default=False): | ||
self.options.add_option("shared", [True, False], default) | ||
|
||
def add_cppstd(self, default=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This self.add_cppstd()
default to 11 seems a bit weird to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, better to keep it explicit and not optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh, maybe it should be defaulted to the compiler's version default?
"compiler": "gcc", | ||
"compiler.libcxx": "libstdc++11", | ||
"compiler.version": "4.9"}) | ||
options = MockOptions({"cppstd": "17"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if this should be managed somehow. So you requested cppstd=17, which is impossible, it will be ignored, but it will affect the binary package ID? Maybe should it raise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably shouldn't be a valid option if you used the "add_cppstd" and will raise because of it. (not in this case of Mock()).
Actually we miss information in the case of Visual Studio, where depending on the revision of the compiler the default standard can change. In visual 2015 rev3 the default is cpp14, and c++11 makes no sense, there is no flag to specify a lower one, but in previous revisions the default was c++11.
def test_variables(self): | ||
# GCC 32 | ||
settings = MockSettings({"build_type": "Release", | ||
"arch": "x86", | ||
"compiler": "gcc", | ||
"compiler.libcxx": "libstdc++"}) | ||
conanfile = MockConanfile(settings) | ||
conanfile = MockConanfile(settings, MockOptions({})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe set a default in MockConanFile
constructor
self.deps_cpp_info = namedtuple("deps_cpp_info", "sysroot")("/path/to/sysroot") | ||
self.output = TestBufferConanOutput() | ||
if shared is not None: | ||
self.options = namedtuple("options", "shared")(shared) | ||
self.options = Options(PackageOptions({"shared": ["True", "False"]})) | ||
self.options.values = OptionsValues([("shared", shared)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.options.shared = True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already assigned because of the default value, right? it's not needed to assign it.
default_options= "shared=False" | ||
|
||
def options(self, config): | ||
config.add_shared() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it looks to add other options than shared & standards when using the options()
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config.options.add_option("flavour", ["choco", "strawberry", "orange"], "orange")
It has to be added to the docs, of course
conans/test/util/tools_test.py
Outdated
error = client.run('create Hello/1.2.1@lasote/stable -o Hello:cppstd=11 -s compiler="Visual Studio" -s ' | ||
'compiler.version=14', ignore_error=True) | ||
self.assertTrue(error) | ||
client.save(files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why save again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed.
I have a further question: how the default for a certain compiler differs from the selected one: So if I use |
…into feature/standard_as_option
Discarded PR in favor of #2486 |
#1799 (part of #2033, but can be completed later)
CHANGED TO USE THE config_options METHOD, BUT AFFECTED BY #2108
def options(self, config)
method instead ofoptions
attribute. Look at the tests.