From e74c3158889ed87f75c33703eb33a6d13a46c723 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 22 Jan 2025 19:48:16 +0100 Subject: [PATCH] check subfolder too --- conan/tools/cmake/presets.py | 3 ++- test/integration/toolchains/cmake/test_cmaketoolchain.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/conan/tools/cmake/presets.py b/conan/tools/cmake/presets.py index b7e616150e2..cd7e3db2700 100644 --- a/conan/tools/cmake/presets.py +++ b/conan/tools/cmake/presets.py @@ -261,6 +261,7 @@ def generate(conanfile, preset_path, user_presets_path, preset_prefix, preset_da if not (conanfile.source_folder and conanfile.source_folder != conanfile.generators_folder): return + is_default = user_presets_path == "CMakeUserPresets.json" user_presets_path = os.path.join(conanfile.source_folder, user_presets_path) if os.path.isdir(user_presets_path): # Allows user to specify only the folder output_dir = user_presets_path @@ -268,7 +269,7 @@ def generate(conanfile, preset_path, user_presets_path, preset_prefix, preset_da else: output_dir = os.path.dirname(user_presets_path) - if not os.path.exists(os.path.join(output_dir, "CMakeLists.txt")): + if is_default and not os.path.exists(os.path.join(output_dir, "CMakeLists.txt")): return # It uses schema version 4 unless it is forced to 2 diff --git a/test/integration/toolchains/cmake/test_cmaketoolchain.py b/test/integration/toolchains/cmake/test_cmaketoolchain.py index 3443365aa99..318f43d762b 100644 --- a/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -1550,6 +1550,11 @@ def test_customize_cmakeuserpresets(): c.run("install . -g CMakeToolchain -of=build -c tools.cmake.cmaketoolchain:user_presets=my.json") new = c.load("my.json") assert old == new + # also in subfolder + c.run("install . -g CMakeToolchain -of=build " + "-c tools.cmake.cmaketoolchain:user_presets=mysub/my.json") + assert os.path.exists(os.path.join(c.current_folder, "mysub", "my.json")) + assert not os.path.exists(os.path.join(c.current_folder, "CMakeUserPresets.json")) c.run("install . -g CMakeToolchain -of=build -c tools.cmake.cmaketoolchain:user_presets=") assert not os.path.exists(os.path.join(c.current_folder, "CMakeUserPresets.json"))