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
Feature: set CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON #8599
Merged
memsharded
merged 6 commits into
conan-io:develop
from
SSE4:cmake_find_package_prefer_config
Mar 23, 2021
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,10 @@ class CMakeToolchainBase(object): | |
# We are going to adjust automagically many things as requested by Conan | ||
# these are the things done by 'conan_basic_setup()' | ||
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON) | ||
{%- if find_package_prefer_config %} | ||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG {{ find_package_prefer_config }}) | ||
{%- endif %} | ||
#set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) | ||
# To support the cmake_find_package generators | ||
{% if cmake_module_path -%} | ||
set(CMAKE_MODULE_PATH {{ cmake_module_path }} ${CMAKE_MODULE_PATH}) | ||
|
@@ -133,6 +137,8 @@ class CMakeToolchainBase(object): | |
""") | ||
|
||
def __init__(self, conanfile, **kwargs): | ||
import six | ||
|
||
self._conanfile = conanfile | ||
self.variables = Variables() | ||
self.preprocessor_definitions = Variables() | ||
|
@@ -143,6 +149,15 @@ def __init__(self, conanfile, **kwargs): | |
|
||
self.build_type = None | ||
|
||
self.find_package_prefer_config = \ | ||
conanfile.conf["tools.cmake.cmaketoolchain"].find_package_prefer_config | ||
if self.find_package_prefer_config is not None: | ||
if isinstance(self.find_package_prefer_config, six.string_types): | ||
self.find_package_prefer_config = self.find_package_prefer_config == "True" | ||
elif isinstance(self.find_package_prefer_config, six.integer_types): | ||
self.find_package_prefer_config = bool(self.find_package_prefer_config) | ||
self.find_package_prefer_config = "ON" if self.find_package_prefer_config else "OFF" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. two notes:
|
||
def _get_templates(self): | ||
return { | ||
'toolchain_macros': self._toolchain_macros_tpl, | ||
|
@@ -160,6 +175,7 @@ def _get_template_context_data(self): | |
"cmake_prefix_path": self.cmake_prefix_path, | ||
"cmake_module_path": self.cmake_module_path, | ||
"build_type": self.build_type, | ||
"find_package_prefer_config": self.find_package_prefer_config, | ||
} | ||
return ctxt_toolchain | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is not opting-out, it is opting-in please recall my comment:
Then simplify code, as you said they are always strings, so go for a oneliner:
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 not sure I understand. this is opt-out, the behavior matches CMake exactly:
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 whole idea was to have it ON by default so inexperienced users using
conanfile.txt
without anyconf
sections have a friendly dev env. Advanced users may want to disable it if they so desire.As a side note, still there are many inexperienced users out there both for Conan and CMake. Doing things that we consider trivial is not easy for them at all. For the last two days, I am remotely helping one of them to enable
mp-units
support viaconanfile.txt
even though I thought that my docs are clear: https://mpusz.github.io/units/usage.html#conan-cmake-release. Today I finally saw that person's CMake file and it turned out to be: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.
okay, I added the ON as default again. there was a confusion because initially I implemented ON as default, then others said it should be controlled by conf instead. hopefully the current behavior makes sense:
(although it's not exactly an opt out for the default CMake behavior, it should help for your case)
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.
Actually, in this case, a user correctly applied
CONFIG REQUIRED
as suggested in my docs. The problem was with the last two lines 😉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.
@SSE4 my request was:
A config required to opt-out. That means that by default it is ON, and you need to do something proactively to opt-out of that feature. If you need to define a conf for activating the feature, it is not an opt-out feature, it is an opt-in feature.