Skip to content

Commit f34418d

Browse files
DenzellceWolf
authored andcommitted
do not build with preset when none is selected (#349)
1 parent 02d109f commit f34418d

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

lua/cmake-tools/init.lua

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ function cmake.build(opt, callback)
348348
end
349349

350350
local presets_exists = config.base_settings.use_preset and Presets.exists(config.cwd)
351+
local use_build_preset = false
351352
if presets_exists then
352353
local presets = Presets:parse(config.cwd)
353354
if not config.build_preset then
@@ -367,9 +368,10 @@ function cmake.build(opt, callback)
367368
end
368369
if config.build_preset then
369370
local build_preset = presets:get_build_preset(config.build_preset)
370-
if build_preset then
371+
if build_preset and build_preset:is_valid() then
371372
config:update_build_target()
372373
config:update_build_type()
374+
use_build_preset = true
373375
end
374376
end
375377
end
@@ -387,7 +389,7 @@ function cmake.build(opt, callback)
387389

388390
local args
389391

390-
if presets_exists and config.build_preset then
392+
if use_build_preset then
391393
args = { "--build", "--preset", config.build_preset } -- preset don't need define build dir.
392394
else
393395
args = {
@@ -868,32 +870,29 @@ function cmake.select_build_preset(callback)
868870
callback(Result:new_error(Types.NOT_SELECT_PRESET, "No build preset selected"))
869871
return
870872
end
873+
871874
if config.build_preset ~= choice then
875+
config.build_preset = choice
876+
872877
local build_preset = presets:get_build_preset(choice)
873-
if build_preset:is_valid() then
874-
config.build_preset = choice
875878

876-
if build_preset then
877-
config:update_build_target()
879+
if build_preset and build_preset:is_valid() then
880+
config:update_build_target()
881+
882+
local associated_configure_preset =
883+
presets:get_configure_preset(build_preset.configurePreset, { include_hidden = true })
884+
local associated_configure_preset_name = associated_configure_preset
885+
and associated_configure_preset.name
886+
or nil
887+
888+
if
889+
associated_configure_preset_name
890+
and config.configure_preset ~= associated_configure_preset_name
891+
then
892+
config.configure_preset = associated_configure_preset_name
878893
end
879894
end
880895
end
881-
local associated_configure_preset = presets:get_configure_preset(
882-
presets:get_build_preset(choice).configurePreset,
883-
{ include_hidden = true }
884-
)
885-
local associated_configure_preset_name = associated_configure_preset
886-
and associated_configure_preset.name
887-
or nil
888-
local configure_preset_updated = false
889-
890-
if
891-
associated_configure_preset_name
892-
and config.configure_preset ~= associated_configure_preset_name
893-
then
894-
config.configure_preset = associated_configure_preset_name
895-
configure_preset_updated = true
896-
end
897896

898897
callback(Result:new(Types.SUCCESS, nil, nil))
899898
end)

0 commit comments

Comments
 (0)