From 7a1a7e6f6764b521a7897c7e08301839d6b96c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Sun, 13 Oct 2024 18:39:13 +0200 Subject: [PATCH] fix: Only switch dir for building with preset If config:build_directory_path() is relative then it will be treated as relative to nvim's cwd, not the cwd as given in the config, so cmake --build will fail if config.cwd is a subdirectory of nvim's cwd. On the other hand, when using presets CMake's cwd *must* be the directory where the preset files are. Fix this by only using config.cwd when building with presets. --- lua/cmake-tools/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/cmake-tools/init.lua b/lua/cmake-tools/init.lua index a488a09..822690c 100644 --- a/lua/cmake-tools/init.lua +++ b/lua/cmake-tools/init.lua @@ -342,15 +342,18 @@ function cmake.build(opt, callback) end local args + local cwd local presets_exists = config.base_settings.use_preset and Presets.exists(config.cwd) if presets_exists and config.build_preset then args = { "--build", "--preset", config.build_preset } -- preset don't need define build dir. + cwd = config.cwd else args = { "--build", utils.transform_path(config:build_directory_path(), config.executor.name == "quickfix"), } + cwd = "." end if opt.target ~= nil then @@ -368,7 +371,7 @@ function cmake.build(opt, callback) local env = environment.get_build_environment(config) local cmd = const.cmake_command - return utils.execute(cmd, config.env_script, env, args, config.cwd, config.executor, callback) + return utils.execute(cmd, config.env_script, env, args, cwd, config.executor, callback) end function cmake.quick_build(opt, callback)