Skip to content

Commit 8f1a5ca

Browse files
authored
new test for relocaiton of cmake_find_none (#18819)
* new test for relocaiton of cmake_find_none * wip * wip * working! * some logs * wip * print version * cmake version? * cleanup * using list(APPEND, better regex * renamed to CONAN_ variable
1 parent 6e4f724 commit 8f1a5ca

File tree

5 files changed

+555
-3
lines changed

5 files changed

+555
-3
lines changed

conan/tools/cmake/cmakedeps2/cmakedeps.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ def generate(self):
203203
{% for pkg_name, folder in pkg_paths.items() %}
204204
set({{pkg_name}}_DIR "{{folder}}")
205205
{% endfor %}
206+
{% for pkg_name, folders in pkg_paths_multi.items() %}
207+
{% for folder in folders %}
208+
list(APPEND CONAN_{{pkg_name}}_DIR_MULTI "{{folder}}")
209+
{% endfor %}
210+
{% endfor %}
206211
{% if host_runtime_dirs %}
207212
set(CONAN_RUNTIME_LIB_DIRS {{ host_runtime_dirs }} )
208213
# Only for VS, needs CMake>=3.27
@@ -234,6 +239,17 @@ def generate(self):
234239
# if not, test_cmake_add_subdirectory test fails
235240
# content.append('set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)')
236241
pkg_paths = {}
242+
243+
pkg_paths_multi = {}
244+
if os.path.exists(self._conan_cmakedeps_paths):
245+
existing_toolchain = load(self._conan_cmakedeps_paths)
246+
pattern_paths = r"list\(APPEND CONAN_([A-Za-z0-9-_]*)_DIR_MULTI \"([^)]*)\"\)"
247+
variable_match = re.findall(pattern_paths, existing_toolchain)
248+
for (captured_name, captured_path) in variable_match:
249+
path_list = pkg_paths_multi.setdefault(captured_name, [])
250+
if captured_path not in path_list:
251+
path_list.append(captured_path)
252+
237253
for req, dep in all_reqs:
238254
cmake_find_mode = self._cmakedeps.get_property("cmake_find_mode", dep)
239255
cmake_find_mode = cmake_find_mode or FIND_MODE_CONFIG
@@ -255,6 +271,10 @@ def generate(self):
255271
if os.path.isfile(os.path.join(pkg_folder, filename)):
256272
pkg_paths[pkg_name] = relativize_path(pkg_folder, self._conanfile,
257273
"${CMAKE_CURRENT_LIST_DIR}")
274+
275+
existing_paths = pkg_paths_multi.setdefault(pkg_name, [])
276+
if pkg_folder not in existing_paths:
277+
existing_paths.append(pkg_folder)
258278
continue
259279

260280
# If CMakeDeps generated, the folder is this one
@@ -269,6 +289,7 @@ def generate(self):
269289
cmake_module_path = self._get_cmake_paths(all_reqs, "builddirs")
270290
context = {"host_runtime_dirs": self._get_host_runtime_dirs(),
271291
"pkg_paths": pkg_paths,
292+
"pkg_paths_multi": pkg_paths_multi,
272293
"cmake_program_path": _join_paths(self._conanfile, cmake_program_path),
273294
"cmake_library_path": _join_paths(self._conanfile, cmake_library_path),
274295
"cmake_include_path": _join_paths(self._conanfile, cmake_include_path),

0 commit comments

Comments
 (0)