@@ -166,7 +166,7 @@ function cmake.generate(opt, callback)
166166 return
167167 end
168168
169- cmake . update_build_type ()
169+ config : update_build_type ()
170170
171171 local build_directory , no_expand_build_directory = preset .binaryDirExpanded , preset .binaryDir
172172 if build_directory ~= " " then
@@ -368,8 +368,8 @@ function cmake.build(opt, callback)
368368 if config .build_preset then
369369 local build_preset = presets :get_build_preset (config .build_preset )
370370 if build_preset then
371- cmake . update_build_target (build_preset )
372- cmake . update_build_type ()
371+ config : update_build_target ()
372+ config : update_build_type ()
373373 end
374374 end
375375 end
@@ -880,7 +880,7 @@ function cmake.select_build_preset(callback)
880880
881881 local build_preset = presets :get_build_preset (choice )
882882 if build_preset then
883- cmake . update_build_target (build_preset )
883+ config : update_build_target ()
884884 end
885885 end
886886 local associated_configure_preset = presets :get_configure_preset (
@@ -1046,8 +1046,20 @@ end
10461046function cmake .get_target_vars (target )
10471047 local vars = cmake .get_base_vars ()
10481048
1049- local model = config :get_code_model_info ()[target ]
1049+ config :update_build_directory ()
1050+
1051+ local codemodel = config :get_code_model_info ()
1052+ if not codemodel then
1053+ return
1054+ end
1055+ local model = codemodel [target ]
1056+ if not model then
1057+ return
1058+ end
10501059 local result = config :get_launch_target_from_info (model )
1060+ if result .code ~= Types .SUCCESS then
1061+ return
1062+ end
10511063 vars .dir .binary = utils .get_path (result .data )
10521064 return vars
10531065end
@@ -1117,8 +1129,13 @@ function cmake.target_settings(opt)
11171129 inherit_base_environment = true ,
11181130 env = {},
11191131 })
1132+ local target_vars = cmake .get_target_vars (target )
1133+ if not target_vars then
1134+ log .info (" Target has not been configured!" )
1135+ return
1136+ end
11201137
1121- local content = " local vars = " .. vim .inspect (cmake . get_target_vars ( target ) )
1138+ local content = " local vars = " .. vim .inspect (target_vars )
11221139 content = content .. " \n return " .. vim .inspect (config .target_settings [target ])
11231140
11241141 window .set_content (content )
@@ -1159,32 +1176,33 @@ function cmake.run_test(opt, callback)
11591176 end
11601177
11611178 local env = environment .get_build_environment (config )
1162- local all_tests = ctest .list_all_tests (config :build_directory_path ())
1163- if # all_tests == 0 then
1164- return
1165- end
1166- table.insert (all_tests , 1 , " all" )
1167- vim .ui .select (
1168- all_tests ,
1169- { prompt = " select test to run" },
1170- vim .schedule_wrap (function (_ , idx )
1171- if not idx then
1172- return
1173- end
1174- if idx == 1 then
1175- ctest .run (const .ctest_command , " '.*'" , config :build_directory_path (), env , config , opt )
1176- else
1177- ctest .run (
1178- const .ctest_command ,
1179- all_tests [idx ],
1180- config :build_directory_path (),
1181- env ,
1182- config ,
1183- opt
1184- )
1185- end
1186- end )
1187- )
1179+ ctest .list_all_tests (config :build_directory_path (), function (all_tests )
1180+ if # all_tests == 0 then
1181+ return
1182+ end
1183+ table.insert (all_tests , 1 , " all" )
1184+ vim .ui .select (
1185+ all_tests ,
1186+ { prompt = " select test to run" },
1187+ vim .schedule_wrap (function (_ , idx )
1188+ if not idx then
1189+ return
1190+ end
1191+ if idx == 1 then
1192+ ctest .run (const .ctest_command , " '.*'" , config :build_directory_path (), env , config , opt )
1193+ else
1194+ ctest .run (
1195+ const .ctest_command ,
1196+ all_tests [idx ],
1197+ config :build_directory_path (),
1198+ env ,
1199+ config ,
1200+ opt
1201+ )
1202+ end
1203+ end )
1204+ )
1205+ end )
11881206end
11891207
11901208function cmake .run_current_file (opt )
@@ -1868,56 +1886,4 @@ function cmake.register_telescope_function()
18681886 end
18691887end
18701888
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-
19231889return cmake
0 commit comments