Skip to content

feat: Add CONAN_RUNTIME_LIB_DIRS to the conan_toolchain.cmake #15914

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

Merged
merged 20 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ class FindFiles(Block):
{% if cmake_include_path %}
list(PREPEND CMAKE_INCLUDE_PATH {{ cmake_include_path }})
{% endif %}
{% if lib_dirs %}
list(PREPEND CONAN_RUNTIME_LIB_DIRS {{ lib_dirs }})
{% endif %}

{% if cross_building %}
if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PACKAGE OR CMAKE_FIND_ROOT_PATH_MODE_PACKAGE STREQUAL "ONLY")
Expand Down Expand Up @@ -518,12 +521,14 @@ def context(self):
find_package_prefer_config = "OFF"

is_apple_ = is_apple_os(self._conanfile)
is_win = self._conanfile.settings.get_safe("os") == "Windows"

# Read information from host context
# TODO: Add here in 2.0 the "skip": False trait
host_req = self._conanfile.dependencies.filter({"build": False}).values()
build_paths = []
host_lib_paths = []
host_lib_dirs = []
host_framework_paths = []
host_include_paths = []
for req in host_req:
Expand All @@ -533,6 +538,10 @@ def context(self):
if is_apple_:
host_framework_paths.extend(cppinfo.frameworkdirs)
host_include_paths.extend(cppinfo.includedirs)
if is_win:
host_lib_dirs.extend(cppinfo.bindirs)
else:
host_lib_dirs.extend(cppinfo.libdirs)

# Read information from build context
build_req = self._conanfile.dependencies.build.values()
Expand All @@ -552,6 +561,7 @@ def context(self):
"cmake_include_path": self._join_paths(host_include_paths),
"is_apple": is_apple_,
"cross_building": cross_building(self._conanfile),
"lib_dirs": self._join_paths(host_lib_dirs)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ def requirements(self):
client.run("install consumer --lockfile=consumer.lock -s os=Windows -s:b os=Windows")
assert "REV1!!!" in client.out
assert "REV2!!!" not in client.out
assert "nix" not in client.out
assert "nix/0.1" not in client.out
client.run("install consumer -s os=Windows -s:b os=Windows")
assert "REV2!!!" in client.out
assert "REV1!!!" not in client.out
assert "nix" not in client.out
assert "nix/0.1" not in client.out

client.run("install consumer --lockfile=consumer.lock -s os=Linux -s:b os=Linux")
assert "REV1!!!" in client.out
assert "REV2!!!" not in client.out
assert "win" not in client.out
assert "win/0.1" not in client.out
client.run("install consumer -s os=Linux -s:b os=Linux")
assert "REV2!!!" in client.out
assert "REV1!!!" not in client.out
assert "win" not in client.out
assert "win/0.1" not in client.out


@pytest.mark.parametrize("requires", ["requires", "tool_requires"])
Expand Down
80 changes: 80 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import platform
import re
import textwrap

import pytest
Expand Down Expand Up @@ -352,6 +353,85 @@ def generate(self):
assert "/path/to/builddir" in contents


@pytest.mark.skipif(platform.system() != "Windows", reason="Only Windows")
def test_lib_dirs_windows():
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class Conan(ConanFile):

def package_info(self):
self.cpp_info.builddirs = ["/path/to/builddir"]
""")
client.save({"conanfile.py": conanfile})
client.run("create . --name=dep --version=1.0")

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain

class Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
requires = "dep/1.0@"

def generate(self):
cmake = CMakeToolchain(self)
cmake.generate()
""")

client.save({"conanfile.py": conanfile})
client.run("install . ")
with open(os.path.join(client.current_folder, "conan_toolchain.cmake")) as f:
contents = f.read()
pattern_lib_path = r'list\(PREPEND CMAKE_LIBRARY_PATH "(.*?)"\)'
pattern_lib_dirs = r'list\(PREPEND CONAN_RUNTIME_LIB_DIRS "(.*?)"\)'
lib_path_group = re.search(pattern_lib_path, contents).groups()
lib_dirs_group = re.search(pattern_lib_dirs, contents).groups()

assert len(lib_path_group) == len(lib_dirs_group)
assert all(lib_dir[-3:] == "bin" for lib_dir in lib_dirs_group)


@pytest.mark.skipif(platform.system() == "Windows", reason="Only Linux and OSX")
def test_lib_dirs_no_windows():
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile

class Conan(ConanFile):

def package_info(self):
self.cpp_info.builddirs = ["/path/to/builddir"]
""")
client.save({"conanfile.py": conanfile})
client.run("create . --name=dep --version=1.0")

conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain

class Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
requires = "dep/1.0@"

def generate(self):
cmake = CMakeToolchain(self)
cmake.generate()
""")

client.save({"conanfile.py": conanfile})
client.run("install . ")
with open(os.path.join(client.current_folder, "conan_toolchain.cmake")) as f:
contents = f.read()
pattern_lib_path = r'list\(PREPEND CMAKE_LIBRARY_PATH (.*)\)'
pattern_lib_dirs = r'list\(PREPEND CONAN_RUNTIME_LIB_DIRS (.*)\)'
lib_path = re.search(pattern_lib_path, contents).group(1)
lib_dirs = re.search(pattern_lib_dirs, contents).group(1)

assert lib_path == lib_dirs


@pytest.mark.skipif(platform.system() != "Darwin", reason="Only OSX")
def test_cmaketoolchain_cmake_system_processor_cross_apple():
"""
Expand Down