Skip to content

Commit

Permalink
fix: Only switch dir for building with preset
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Osse committed Dec 30, 2024
1 parent 4e134ed commit 7a1a7e6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lua/cmake-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 7a1a7e6

Please sign in to comment.