Skip to content

Commit

Permalink
fix: Only switch dir for building with preset
Browse files Browse the repository at this point in the history
config:build_directory_path() is 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 build 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 Nov 22, 2024
1 parent 15a095c commit 771897a
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 771897a

Please sign in to comment.