From 67c8c8d3c99912e360220ad0477de40d100be552 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 20 Nov 2020 23:18:07 +0800 Subject: improve tools/cmake for ninja generator --- xmake/modules/package/tools/cmake.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index 453097c6d..3f8cd19e3 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -252,8 +252,18 @@ function _get_configs(package, configs, opt) end -- get build environments -function buildenvs(package) - local envs = {} +function buildenvs(package, opt) + + -- use ninja generator for windows platform? we need bind msvc environments manually + -- @see https://github.com/xmake-io/xmake/issues/1057 + opt = opt or {} + local envs = {} + local cmake_generator = opt.cmake_generator + if cmake_generator and cmake_generator == "Ninja" and package:is_plat("windows") then + table.join2(envs, toolchain.load("msvc"):runenvs()) + end + + -- add environments for cmake/find_packages local CMAKE_LIBRARY_PATH = {} local CMAKE_INCLUDE_PATH = {} local CMAKE_PREFIX_PATH = {} @@ -439,7 +449,7 @@ function build(package, configs, opt) table.insert(argv, '..') -- do configure - os.vrunv("cmake", argv, {envs = opt.envs or buildenvs(package)}) + os.vrunv("cmake", argv, {envs = opt.envs or buildenvs(package, opt)}) -- do build local cmake_generator = opt.cmake_generator @@ -497,7 +507,7 @@ function install(package, configs, opt) table.insert(argv, '..') -- generate build file - os.vrunv("cmake", argv, {envs = opt.envs or buildenvs(package)}) + os.vrunv("cmake", argv, {envs = opt.envs or buildenvs(package, opt)}) -- do build and install local cmake_generator = opt.cmake_generator -- cgit v1.3.1