Skip to content

Commit

Permalink
Assume only config files are generated in CMakeDeps generator when no…
Browse files Browse the repository at this point in the history
…ne is specified (#11240)

* Assume find mode is config when none is specified in CMakeDeps generator

* Add test to cover case when transitive dependency doesnt provide a config mode
  • Loading branch information
jcar87 authored May 13, 2022
1 parent 3063757 commit ba8c97f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions conan/tools/cmake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def get_file_name(conanfile, forced_module_mode=None):
def get_find_mode(conanfile):
"""
:param conanfile: conanfile of the requirement
:return: "none" or "config" or "module" or "both" or None when not set
:return: "none" or "config" or "module" or "both" or "config" when not set
"""
tmp = conanfile.cpp_info.get_property("cmake_find_mode")
if tmp is None:
return None
return "config"
return tmp.lower()
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,17 @@ def test_reuse_with_modules_and_config(client):
client.run("build . -if=install")


@pytest.mark.parametrize("find_mode", ["both", "config", "module"])
def test_transitive_modules_found(find_mode):
find_modes = [
("both", "both", ""),
("config", "config", ""),
("module", "module", ""),
("both", None, ""),
("both", None, "MODULE")
]


@pytest.mark.parametrize("find_mode_PKGA, find_mode_PKGB, find_mode_consumer", find_modes)
def test_transitive_modules_found(find_mode_PKGA, find_mode_PKGB, find_mode_consumer):
"""
related to https://github.com/conan-io/conan/issues/10224
modules files variables were set with the pkg_name_FOUND or pkg_name_VERSION
Expand All @@ -127,7 +136,8 @@ def test_transitive_modules_found(find_mode):
class Pkg(ConanFile):
{requires}
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "{mode}")
if "{mode}" != "None":
self.cpp_info.set_property("cmake_find_mode", "{mode}")
self.cpp_info.set_property("cmake_file_name", "{filename}")
self.cpp_info.defines.append("DEFINE_{filename}")
""")
Expand All @@ -149,19 +159,20 @@ def build(self):
cmakelist = textwrap.dedent("""
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
find_package(MYPKGB REQUIRED)
message("MYPKGB_VERSION: ${MYPKGB_VERSION}")
message("MYPKGB_VERSION_STRING: ${MYPKGB_VERSION_STRING}")
message("MYPKGB_INCLUDE_DIRS: ${MYPKGB_INCLUDE_DIRS}")
message("MYPKGB_INCLUDE_DIR: ${MYPKGB_INCLUDE_DIR}")
message("MYPKGB_LIBRARIES: ${MYPKGB_LIBRARIES}")
message("MYPKGB_DEFINITIONS: ${MYPKGB_DEFINITIONS}")
find_package(MYPKGB REQUIRED {find_mode})
message("MYPKGB_VERSION: ${{MYPKGB_VERSION}}")
message("MYPKGB_VERSION_STRING: ${{MYPKGB_VERSION_STRING}}")
message("MYPKGB_INCLUDE_DIRS: ${{MYPKGB_INCLUDE_DIRS}}")
message("MYPKGB_INCLUDE_DIR: ${{MYPKGB_INCLUDE_DIR}}")
message("MYPKGB_LIBRARIES: ${{MYPKGB_LIBRARIES}}")
message("MYPKGB_DEFINITIONS: ${{MYPKGB_DEFINITIONS}}")
""")

client.save({"pkgb.py": conan_pkg.format(requires='requires="pkga/1.0"', filename='MYPKGB', mode=find_mode),
"pkga.py": conan_pkg.format(requires='', filename='MYPKGA', mode=find_mode),
client.save({"pkgb.py": conan_pkg.format(requires='requires="pkga/1.0"', filename='MYPKGB',
mode=find_mode_PKGA),
"pkga.py": conan_pkg.format(requires='', filename='MYPKGA', mode=find_mode_PKGB),
"consumer.py": consumer,
"CMakeLists.txt": cmakelist})
"CMakeLists.txt": cmakelist.format(find_mode=find_mode_consumer)})
client.run("create pkga.py pkga/1.0@")
client.run("create pkgb.py pkgb/1.0@")
client.run("create consumer.py consumer/1.0@")
Expand All @@ -173,7 +184,5 @@ def build(self):
assert "MYPKGB_LIBRARIES: pkga::pkga" in client.out
assert "MYPKGB_DEFINITIONS: -DDEFINE_MYPKGB" in client.out
assert "Conan: Target declared 'pkga::pkga'"
if find_mode == "module":
if find_mode_PKGA == "module":
assert 'Found MYPKGA: 1.0 (found version "1.0")' in client.out


0 comments on commit ba8c97f

Please sign in to comment.