Skip to content

Commit

Permalink
check subfolder too
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Jan 22, 2025
1 parent 79be150 commit e74c315
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion conan/tools/cmake/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,15 @@ 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
user_presets_path = os.path.join(user_presets_path, "CMakeUserPresets.json")
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
Expand Down
5 changes: 5 additions & 0 deletions test/integration/toolchains/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit e74c315

Please sign in to comment.