@@ -116,13 +116,11 @@ function cmake.generate(opt, callback)
116116 local presets = Presets :parse (config .cwd )
117117
118118 local find_preset = false
119- -- Refresh build type to use from CMakePresets
120119 if config .configure_preset then
121120 local configure_preset =
122121 presets :get_configure_preset (config .configure_preset , { include_hidden = true })
123122 if configure_preset then
124123 find_preset = true
125- config .build_type = configure_preset :get_build_type ()
126124 end
127125 end
128126
@@ -167,6 +165,9 @@ function cmake.generate(opt, callback)
167165 end
168166 return
169167 end
168+
169+ cmake .update_build_type ()
170+
170171 local build_directory , no_expand_build_directory = preset .binaryDirExpanded , preset .binaryDir
171172 if build_directory ~= " " then
172173 config :update_build_dir (build_directory , no_expand_build_directory )
@@ -367,10 +368,8 @@ function cmake.build(opt, callback)
367368 if config .build_preset then
368369 local build_preset = presets :get_build_preset (config .build_preset )
369370 if build_preset then
370- local build_target_from_build_preset = build_preset :get_build_target ()
371- if build_target_from_build_preset ~= " " then
372- config .build_target = build_target_from_build_preset
373- end
371+ cmake .update_build_target (build_preset )
372+ cmake .update_build_type ()
374373 end
375374 end
376375 end
@@ -878,7 +877,11 @@ function cmake.select_build_preset(callback)
878877 end
879878 if config .build_preset ~= choice then
880879 config .build_preset = choice
881- config .build_target = presets :get_build_preset (choice ):get_build_target ()
880+
881+ local build_preset = presets :get_build_preset (choice )
882+ if build_preset then
883+ cmake .update_build_target (build_preset )
884+ end
882885 end
883886 local associated_configure_preset = presets :get_configure_preset (
884887 presets :get_build_preset (choice ).configurePreset ,
@@ -1865,4 +1868,56 @@ function cmake.register_telescope_function()
18651868 end
18661869end
18671870
1871+ function cmake .update_build_target (build_preset )
1872+ local build_target = build_preset :get_build_target ()
1873+ if build_target ~= " " then
1874+ config .build_target = build_target
1875+ end
1876+ end
1877+
1878+ function cmake .update_build_type ()
1879+ local presets = Presets :parse (config .cwd )
1880+ if not presets then
1881+ return
1882+ end
1883+ if not config .configure_preset then
1884+ return
1885+ end
1886+ local configure_preset =
1887+ presets :get_configure_preset (config .configure_preset , { include_hidden = true })
1888+ if not configure_preset then
1889+ return
1890+ end
1891+
1892+ config .build_type = configure_preset :get_build_type ()
1893+
1894+ if not config .build_preset then
1895+ return
1896+ end
1897+ local build_preset = presets :get_build_preset (config .build_preset )
1898+ if not build_preset then
1899+ return
1900+ end
1901+ local configuration_types = configure_preset :get_build_configuration_types ()
1902+
1903+ if not configuration_types then
1904+ return
1905+ end
1906+ local build_type_from_build_preset = build_preset :get_build_type ()
1907+
1908+ if not build_type_from_build_preset then
1909+ return
1910+ end
1911+ local exists = false
1912+ for _ , Item in ipairs (configuration_types ) do
1913+ if Item == build_type_from_build_preset then
1914+ exists = true
1915+ break
1916+ end
1917+ end
1918+ if exists then
1919+ config .build_type = build_type_from_build_preset
1920+ end
1921+ end
1922+
18681923return cmake
0 commit comments