726
726
function _get_default_flags (package , configs , buildtype , opt )
727
727
local cmake_default_flags = _g .cmake_default_flags and _g .cmake_default_flags [buildtype ]
728
728
if not cmake_default_flags then
729
- local tmpdir = path .join (os .tmpdir (), package :name (), package :mode ())
729
+ local tmpdir = path .join (os .tmpdir () .. " .dir " , package :name (), package :mode ())
730
730
local dummy_cmakelist = path .join (tmpdir , " CMakeLists.txt" )
731
731
732
732
io .writefile (dummy_cmakelist , format ([[
@@ -747,23 +747,26 @@ function _get_default_flags(package, configs, buildtype, opt)
747
747
]] , buildtype , buildtype , buildtype , buildtype , buildtype , buildtype , buildtype , buildtype , buildtype , buildtype ))
748
748
749
749
local runenvs = opt .envs or buildenvs (package )
750
- local cmake = find_tool (" cmake" , { envs = runenvs } )
750
+ local cmake = find_tool (" cmake" )
751
751
local _configs = table .join (configs , " -S " .. path .directory (dummy_cmakelist ), " -B " .. tmpdir )
752
752
local _ , outdata = os .iorunv (cmake .program , _configs , {envs = runenvs })
753
- cmake_default_flags = {}
754
- cmake_default_flags .cflags = outdata :match (" CMAKE_C_FLAGS is (.-)\n " ):split (" " )
755
- table .join2 (cmake_default_flags .cflags , outdata :match (format (" CMAKE_C_FLAGS_%s is (.-)\n " , buildtype )):replace (" /MDd" , " " ):replace (" /MD" , " " ):split (" " ))
756
- cmake_default_flags .cxxflags = outdata :match (" CMAKE_CXX_FLAGS is (.-)\n " ):split (" " )
757
- table .join2 (cmake_default_flags .cxxflags , outdata :match (format (" CMAKE_CXX_FLAGS_%s is (.-)\n " , buildtype )):replace (" /MDd" , " " ):replace (" /MD" , " " ):split (" " ))
758
- cmake_default_flags .ldflags = outdata :match (" CMAKE_EXE_LINKER_FLAGS is (.-)\n " ):split (" " )
759
- table .join2 (cmake_default_flags .ldflags , outdata :match (format (" CMAKE_EXE_LINKER_FLAGS_%s is (.-)\n " , buildtype )):split (" " ))
760
- cmake_default_flags .shflags = outdata :match (" CMAKE_SHARED_LINKER_FLAGS is (.-)\n " ):split (" " )
761
- table .join2 (cmake_default_flags .shflags , outdata :match (format (" CMAKE_SHARED_LINKER_FLAGS_%s is (.-)\n " , buildtype )):split (" " ))
762
- cmake_default_flags .arflags = outdata :match (" CMAKE_STATIC_LINKER_FLAGS is (.-)\n " ):split (" " )
763
- table .join2 (cmake_default_flags .arflags , outdata :match (format (" CMAKE_STATIC_LINKER_FLAGS_%s is (.-)\n " , buildtype )):split (" " ))
764
-
765
- _g .cmake_default_flags = _g .cmake_default_flags or {}
766
- _g .cmake_default_flags [buildtype ] = cmake_default_flags
753
+ if outdata then
754
+ cmake_default_flags = {}
755
+ cmake_default_flags .cflags = outdata :match (" CMAKE_C_FLAGS is (.-)\n " ):split (" " )
756
+ table .join2 (cmake_default_flags .cflags , outdata :match (format (" CMAKE_C_FLAGS_%s is (.-)\n " , buildtype )):replace (" /MDd" , " " ):replace (" /MD" , " " ):split (" " ))
757
+ cmake_default_flags .cxxflags = outdata :match (" CMAKE_CXX_FLAGS is (.-)\n " ):split (" " )
758
+ table .join2 (cmake_default_flags .cxxflags , outdata :match (format (" CMAKE_CXX_FLAGS_%s is (.-)\n " , buildtype )):replace (" /MDd" , " " ):replace (" /MD" , " " ):split (" " ))
759
+ cmake_default_flags .ldflags = outdata :match (" CMAKE_EXE_LINKER_FLAGS is (.-)\n " ):split (" " )
760
+ table .join2 (cmake_default_flags .ldflags , outdata :match (format (" CMAKE_EXE_LINKER_FLAGS_%s is (.-)\n " , buildtype )):split (" " ))
761
+ cmake_default_flags .shflags = outdata :match (" CMAKE_SHARED_LINKER_FLAGS is (.-)\n " ):split (" " )
762
+ table .join2 (cmake_default_flags .shflags , outdata :match (format (" CMAKE_SHARED_LINKER_FLAGS_%s is (.-)\n " , buildtype )):split (" " ))
763
+ cmake_default_flags .arflags = outdata :match (" CMAKE_STATIC_LINKER_FLAGS is (.-)\n " ):split (" " )
764
+ table .join2 (cmake_default_flags .arflags , outdata :match (format (" CMAKE_STATIC_LINKER_FLAGS_%s is (.-)\n " , buildtype )):split (" " ))
765
+
766
+ _g .cmake_default_flags = _g .cmake_default_flags or {}
767
+ _g .cmake_default_flags [buildtype ] = cmake_default_flags
768
+ end
769
+ os .rm (tmpdir )
767
770
end
768
771
return cmake_default_flags
769
772
end
@@ -845,7 +848,7 @@ function _get_configs(package, configs, opt)
845
848
if runtime_envs then
846
849
envs = envs or {}
847
850
for name , value in pairs (runtime_envs ) do
848
- envs [name ] = table .join (envs [name ], value )
851
+ envs [name ] = table .join (envs [name ] or {} , value )
849
852
end
850
853
end
851
854
if envs then
0 commit comments