Skip to content
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

Add CONAN_IN_LOCAL_CACHE variable in CMake build_helper #3450

Merged
merged 8 commits into from Sep 6, 2018
34 changes: 21 additions & 13 deletions conans/client/build/cmake.py
Expand Up @@ -6,7 +6,8 @@
from conans.client import defs_to_string, join_arguments
from conans.client.build.cmake_flags import CMakeDefinitionsBuilder, \
get_generator, is_multi_configuration, verbose_definition, verbose_definition_name, \
cmake_install_prefix_var_name, get_toolset, build_type_definition, runtime_definition_var_name
cmake_install_prefix_var_name, get_toolset, build_type_definition, runtime_definition_var_name, \
cmake_in_local_cache_var_name, in_local_cache_definition
from conans.errors import ConanException
from conans.model.conan_file import ConanFile
from conans.model.version import Version
Expand Down Expand Up @@ -47,18 +48,17 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True,
self._cmake_system_name = cmake_system_name
self._make_program = make_program

self.definitions = self._def_builder.get_definitions()
self._build_type = self._settings.get_safe("build_type")
if build_type and build_type != self._build_type:
# Call the setter to warn and update the definitions if needed
self.build_type = build_type
# Initialize definitions (won't be updated if conanfile or any of these variables change)
builder = CMakeDefinitionsBuilder(self._conanfile, cmake_system_name=self._cmake_system_name,
make_program=self._make_program, parallel=self.parallel,
generator=self.generator,
set_cmake_flags=self._set_cmake_flags)
self.definitions = builder.get_definitions()

@property
def _def_builder(self):
return CMakeDefinitionsBuilder(self._conanfile, cmake_system_name=self._cmake_system_name,
make_program=self._make_program, parallel=self.parallel,
generator=self.generator,
set_cmake_flags=self._set_cmake_flags)
if build_type is None:
self.build_type = self._settings.get_safe("build_type")
else:
self.build_type = build_type

@property
def build_folder(self):
Expand All @@ -80,7 +80,7 @@ def build_type(self, build_type):
'Set CMake build type "%s" is different than the settings build_type "%s"'
% (build_type, settings_build_type))
self._build_type = build_type
self.definitions.update(build_type_definition(build_type, self.generator))
self.definitions.update(build_type_definition(self._build_type, self.generator))

@property
def flags(self):
Expand Down Expand Up @@ -241,6 +241,14 @@ def verbose(self):
def verbose(self, value):
self.definitions.update(verbose_definition(value))

@property
def in_local_cache(self):
try:
in_local_cache = self.definitions[cmake_in_local_cache_var_name]
return get_bool_from_text(str(in_local_cache))
except KeyError:
return False

def patch_config_paths(self):
"""
changes references to the absolute path of the installed package and its dependencies in
Expand Down
8 changes: 8 additions & 0 deletions conans/client/build/cmake_flags.py
Expand Up @@ -14,6 +14,7 @@
verbose_definition_name = "CMAKE_VERBOSE_MAKEFILE"
cmake_install_prefix_var_name = "CMAKE_INSTALL_PREFIX"
runtime_definition_var_name = "CONAN_LINK_RUNTIME"
cmake_in_local_cache_var_name = "CONAN_IN_LOCAL_CACHE"


def get_toolset(settings):
Expand Down Expand Up @@ -83,6 +84,10 @@ def verbose_definition(value):
return {verbose_definition_name: "ON" if value else "OFF"}


def in_local_cache_definition(value):
return {cmake_in_local_cache_var_name: "ON" if value else "OFF"}


def runtime_definition(runtime):
return {runtime_definition_var_name: "/%s" % runtime} if runtime else {}

Expand Down Expand Up @@ -243,6 +248,9 @@ def get_definitions(self):
ret.update(self._get_cpp_standard_vars())

ret["CONAN_EXPORTED"] = "1"
ret[cmake_in_local_cache_var_name] =\
in_local_cache_definition(self._conanfile.in_local_cache)[cmake_in_local_cache_var_name]

if compiler:
ret["CONAN_COMPILER"] = compiler
if compiler_version:
Expand Down
2 changes: 0 additions & 2 deletions conans/client/build/meson.py
Expand Up @@ -26,7 +26,6 @@ def __init__(self, conanfile, backend=None, build_type=None):

self.backend = backend or "ninja" # Other backends are poorly supported, not default other.
self.build_dir = None
self.definitions = {}
if build_type and build_type != self._build_type:
# Call the setter to warn and update the definitions if needed
self.build_type = build_type
Expand All @@ -43,7 +42,6 @@ def build_type(self, build_type):
'Set build type "%s" is different than the settings build_type "%s"'
% (build_type, settings_build_type))
self._build_type = build_type
self.definitions.update(self._build_type_definition())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._build_type_definition() doesn't exists!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this diff, the code in develop has self.definitions.update(build_type_definition(build_type, self.generator)) that indeed exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cmake.py it does, but not in meson.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoL.
I think the self.definitions can be removed from meson too, it is not used nor documented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, remove self.definitions if not used nor documented.


@property
def build_folder(self):
Expand Down
6 changes: 6 additions & 0 deletions conans/client/generators/cmake_common.py
Expand Up @@ -504,6 +504,9 @@ def generate_targets_section(dependencies):
if(CONAN_EXPORTED)
message(STATUS "Conan: called by CMake conan helper")
endif()
if(CONAN_IN_LOCAL_CACHE)
message(STATUS "Conan: called inside local cache")
endif()
conan_check_compiler()
if(NOT ARGUMENTS_NO_OUTPUT_DIRS)
conan_output_dirs_setup()
Expand Down Expand Up @@ -614,6 +617,9 @@ def generate_targets_section(dependencies):
if(CONAN_EXPORTED)
message(STATUS "Conan: called by CMake conan helper")
endif()
if(CONAN_IN_LOCAL_CACHE)
message(STATUS "Conan: called inside local cache")
endif()
conan_check_compiler()
# conan_output_dirs_setup()
if(NOT ARGUMENTS_TARGETS)
Expand Down