Skip to content

Commit 38b4e34

Browse files
committed
fix locations
1 parent 71db5ae commit 38b4e34

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

conan/tools/cmake/cmakedeps2/cmakedeps.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
import os
23
import re
34
import textwrap
@@ -258,6 +259,14 @@ def generate(self):
258259
pkg_name = self._cmakedeps.get_cmake_filename(dep)
259260
# https://cmake.org/cmake/help/v3.22/guide/using-dependencies/index.html
260261
if cmake_find_mode == FIND_MODE_NONE:
262+
cps = glob.glob(f"**/{pkg_name}.cps", root_dir=dep.package_folder, recursive=True)
263+
if cps:
264+
loc = os.path.dirname(os.path.join(dep.package_folder, cps[0]))
265+
loc = loc.replace("\\", "/")
266+
pkg_paths[pkg_name] = relativize_path(loc, self._conanfile,
267+
"${CMAKE_CURRENT_LIST_DIR}")
268+
continue
269+
261270
try:
262271
# This is irrespective of the components, it should be in the root cpp_info
263272
# To define the location of the pkg-config.cmake file
@@ -266,15 +275,11 @@ def generate(self):
266275
build_dir = dep.package_folder
267276
pkg_folder = build_dir.replace("\\", "/") if build_dir else None
268277
if pkg_folder:
269-
# prioritize cps if existing as CMake does
270-
for filename in (f"{pkg_name}.cps", f"cps/{pkg_name}.cps",
271-
f"{pkg_name}-config.cmake", f"{pkg_name}Config.cmake"):
278+
f = self._cmakedeps.get_cmake_filename(dep)
279+
for filename in (f"{f}-config.cmake", f"{f}Config.cmake"):
272280
if os.path.isfile(os.path.join(pkg_folder, filename)):
273-
loc = os.path.dirname(os.path.join(pkg_folder, filename))
274-
loc = loc.replace("\\", "/")
275-
pkg_paths[pkg_name] = relativize_path(loc, self._conanfile,
281+
pkg_paths[pkg_name] = relativize_path(pkg_folder, self._conanfile,
276282
"${CMAKE_CURRENT_LIST_DIR}")
277-
break
278283

279284
existing_paths = pkg_paths_multi.setdefault(pkg_name, [])
280285
if pkg_folder not in existing_paths:

test/functional/toolchains/cmake/test_cps.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def test_cps():
1414
conanfile = textwrap.dedent("""\
1515
from conan import ConanFile
1616
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
17+
from conan.cps import CPS
18+
import glob
1719
1820
class mypkgRecipe(ConanFile):
1921
name = "mypkg"
@@ -41,8 +43,8 @@ def package(self):
4143
cmake.install()
4244
4345
def package_info(self):
44-
from conan.cps import CPS
45-
self.cpp_info = CPS.load("cps/mypkg.cps").to_conan()
46+
file_loc = glob.glob("**/mypkg.cps", recursive=True)
47+
self.cpp_info = CPS.load(file_loc[0]).to_conan()
4648
""")
4749

4850
cmake = textwrap.dedent("""\

0 commit comments

Comments
 (0)