Skip to content

Commit

Permalink
[fix] Removed CMake warning message (#10150)
Browse files Browse the repository at this point in the history
* Deleted cmake warning

* Keeping aliases warning

* Deleted useless test
  • Loading branch information
franramirez688 committed Dec 10, 2021
1 parent 51a0774 commit f42cdf6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
2 changes: 0 additions & 2 deletions conan/tools/cmake/cmakedeps/templates/targets.py
Expand Up @@ -75,8 +75,6 @@ def template(self):
if(NOT TARGET {{ root_target_name }})
add_library({{ root_target_name }} INTERFACE IMPORTED)
conan_message(STATUS "Conan: Target declared '{{ root_target_name }}'")
else()
message(WARNING "Target name '{{root_target_name}}' already exists.")
endif()
{%- for alias, target in cmake_target_aliases.items() %}
Expand Down
Expand Up @@ -852,51 +852,3 @@ def build(self):
assert "Target declared 'CURL'" in client.out
assert "Component target declared 'MYPKGCOMPNAME'" in client.out
assert "Target declared 'nonamespacepkg'" in client.out


@pytest.mark.tool_cmake
def test_colliding_target_names():
client = TestClient()

mypkg = textwrap.dedent("""
from conans import ConanFile
class MyPkg(ConanFile):
name = "mypkg"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
def package_info(self):
self.cpp_info.set_property("cmake_target_name", "mypkg::name")
self.cpp_info.components["mycomponent"].set_property("cmake_target_name", "mypkg::name")
self.cpp_info.components["mycomponent2"].set_property("cmake_target_name", "collidetarget")
""")

client.save({"conanfile.py": mypkg})
client.run("create .")

cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 2.8)
find_package(mypkg REQUIRED)
""")

consumer = textwrap.dedent("""
from conans import ConanFile
from conan.tools.cmake import CMake
class Consumer(ConanFile):
name = "consumer"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"
exports_sources = ["CMakeLists.txt"]
requires = "mypkg/1.0"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
""")

client.save({"conanfile.py": consumer, "CMakeLists.txt": cmakelists})
client.run("create .")

assert "Target name 'mypkg::name' already exists." in client.out

0 comments on commit f42cdf6

Please sign in to comment.