Skip to content

Commit

Permalink
Changed proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
franramirez688 committed Nov 15, 2022
1 parent 409bd22 commit 021ae22
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
15 changes: 13 additions & 2 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class FPicBlock(Block):
template = textwrap.dedent("""
{% if fpic %}
message(STATUS "Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE={{ fpic }} (options.fPIC)")
set(CMAKE_POSITION_INDEPENDENT_CODE {{ fpic }} CACHE BOOL "Position independent code")
set(CMAKE_POSITION_INDEPENDENT_CODE {{ fpic }} CACHE BOOL "Position independent code")
{% endif %}
""")

Expand Down Expand Up @@ -564,13 +564,24 @@ class PkgConfigBlock(Block):
{% if pkg_config %}
set(PKG_CONFIG_EXECUTABLE {{ pkg_config }} CACHE FILEPATH "pkg-config executable")
{% endif %}
{% if pkg_config_path %}
set(ENV{PKG_CONFIG_PATH} "{{ pkg_config_path }}")
{% endif %}
""")

def context(self):
pkg_config = self._conanfile.conf.get("tools.gnu:pkg_config", check_type=str)
if pkg_config:
pkg_config = pkg_config.replace("\\", "/")
return {"pkg_config": pkg_config}
pkg_config_path = self._conanfile.generators_folder
if pkg_config_path:
# Check if user has already defined their own PKG_CONFIG_PATH variable
user_pkg_config_path = os.getenv("PKG_CONFIG_PATH")
if user_pkg_config_path:
# Prepending the Conan one
pkg_config_path = pkg_config_path + os.pathsep + user_pkg_config_path
return {"pkg_config": pkg_config,
"pkg_config_path": pkg_config_path}


class UserToolchain(Block):
Expand Down
18 changes: 3 additions & 15 deletions conan/tools/cmake/toolchain/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from conan.tools.cmake.toolchain import CONAN_TOOLCHAIN_FILENAME
from conan.tools.cmake.toolchain.blocks import ToolchainBlocks, UserToolchain, GenericSystemBlock, \
AndroidSystemBlock, AppleSystemBlock, FPicBlock, ArchitectureBlock, GLibCXXBlock, VSRuntimeBlock, \
CppStdBlock, ParallelBlock, CMakeFlagsInitBlock, TryCompileBlock, FindFiles, PkgConfigBlock, SkipRPath, \
SharedLibBock, OutputDirsBlock, ExtraFlagsBlock
from conan.tools.env import Environment
CppStdBlock, ParallelBlock, CMakeFlagsInitBlock, TryCompileBlock, FindFiles, PkgConfigBlock, \
SkipRPath, SharedLibBock, OutputDirsBlock, ExtraFlagsBlock
from conan.tools.intel import IntelCC
from conan.tools.microsoft import VCVars
from conan.tools.microsoft.visual import vs_ide_version
Expand Down Expand Up @@ -169,18 +168,7 @@ def content(self):
content = Template(self._template, trim_blocks=True, lstrip_blocks=True).render(**context)
return content

def environment(self):
env = Environment()
env.prepend_path("PKG_CONFIG_PATH", self._conanfile.generators_folder)
return env

def vars(self):
return self.environment().vars(self._conanfile, scope="build")

def generate(self, env=None, scope="build"):
env = env or self.environment()
env = env.vars(self._conanfile, scope=scope)
env.save_script("conan_toolchain_env")
def generate(self):
toolchain_file = self._conanfile.conf.get("tools.cmake.cmaketoolchain:toolchain_file")
if toolchain_file is None: # The main toolchain file generated only if user dont define
save(os.path.join(self._conanfile.generators_folder, self.filename), self.content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ class HelloConan(ConanFile):
name = "pkg"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
generators = "PkgConfigDeps", "CMakeToolchain", "VirtualBuildEnv"
generators = "PkgConfigDeps", "CMakeToolchain"
exports_sources = "CMakeLists.txt"
def requirements(self):
Expand Down

0 comments on commit 021ae22

Please sign in to comment.