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

[bugfix] Legacy cmake not affected by set_property #9952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion conans/model/build_info.py
Expand Up @@ -220,7 +220,8 @@ def get_name(self, generator, default_name=True):
property_name = None
if generator == "cmake_find_package" and self.get_property("cmake_module_target_name", generator):
property_name = "cmake_module_target_name"
elif "cmake" in generator:
# set_property will have no effect on "cmake" legacy generator
elif "cmake" in generator and "cmake" != generator:
property_name = "cmake_target_name"
elif "pkg_config" in generator:
property_name = "pkg_config_name"
Expand Down
Expand Up @@ -289,6 +289,38 @@ def package_info(self):
assert find_package_contents_old == find_package_contents


def test_legacy_cmake_is_not_affected_by_set_property_usage():
"""
"set_property" will have no effect on "cmake" legacy generator

Originally posted: https://github.com/conan-io/conan-center-index/issues/7925
"""

client = TestClient()

greetings = textwrap.dedent("""
import os
from conans import ConanFile
class MyPkg(ConanFile):
settings = "build_type"
name = "greetings"
version = "1.0"

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "MyChat")
self.cpp_info.set_property("cmake_target_name", "MyChat")
self.cpp_info.components["sayhello"].set_property("cmake_target_name", "MySay")
""")
client.save({"greetings.py": greetings})
client.run("create greetings.py greetings/1.0@")
client.run("install greetings/1.0@ -g cmake")
conanbuildinfo = client.load("conanbuildinfo.cmake")
# Let's check our final target is the pkg name instead of "MyChat"
assert "set_property(TARGET CONAN_PKG::greetings" in conanbuildinfo
assert "add_library(CONAN_PKG::greetings" in conanbuildinfo
assert "set(CONAN_TARGETS CONAN_PKG::greetings)" in conanbuildinfo


def test_pkg_config_names(setup_client):
client = setup_client
mypkg = textwrap.dedent("""
Expand Down