@@ -947,6 +947,13 @@ function _fix_pdbdir_for_ninja(package)
947
947
end
948
948
end
949
949
950
+ -- enter build directory
951
+ function _enter_buildir (package , opt )
952
+ local buildir = opt .buildir or package :buildir ()
953
+ os .mkdir (path .join (buildir , " install" ))
954
+ return os .cd (buildir )
955
+ end
956
+
950
957
-- get build environments
951
958
function buildenvs (package , opt )
952
959
@@ -1010,8 +1017,9 @@ end
1010
1017
-- do build for make
1011
1018
function _build_for_make (package , configs , opt )
1012
1019
local argv = {}
1013
- if opt .target then
1014
- table.insert (argv , opt .target )
1020
+ local targets = table .wrap (opt .target )
1021
+ if # targets ~= 0 then
1022
+ table .join2 (argv , targets )
1015
1023
end
1016
1024
local jobs = _get_parallel_njobs (opt )
1017
1025
table.insert (argv , " -j" .. jobs )
@@ -1055,9 +1063,19 @@ function _build_for_cmakebuild(package, configs, opt)
1055
1063
table.insert (argv , " --config" )
1056
1064
table.insert (argv , opt .config )
1057
1065
end
1058
- if opt .target then
1066
+ local targets = table .wrap (opt .target )
1067
+ if # targets ~= 0 then
1059
1068
table.insert (argv , " --target" )
1060
- table.insert (argv , opt .target )
1069
+ if # targets > 1 then
1070
+ -- https://stackoverflow.com/questions/47553569/how-can-i-build-multiple-targets-using-cmake-build
1071
+ if _get_cmake_version ():ge (" 3.15" ) then
1072
+ table .join2 (argv , targets )
1073
+ else
1074
+ raise (" Build multiple targets need cmake >=3.15" )
1075
+ end
1076
+ else
1077
+ table.insert (argv , targets [1 ])
1078
+ end
1061
1079
end
1062
1080
os .vrunv (cmake .program , argv , {envs = opt .envs or buildenvs (package )})
1063
1081
end
@@ -1168,15 +1186,9 @@ function _get_cmake_generator(package, opt)
1168
1186
return cmake_generator
1169
1187
end
1170
1188
1171
- -- build package
1172
- function build (package , configs , opt )
1189
+ function configure (package , configs , opt )
1173
1190
opt = opt or {}
1174
- local cmake_generator = _get_cmake_generator (package , opt )
1175
-
1176
- -- enter build directory
1177
- local buildir = opt .buildir or package :buildir ()
1178
- os .mkdir (path .join (buildir , " install" ))
1179
- local oldir = os .cd (buildir )
1191
+ local oldir = _enter_buildir (package , opt )
1180
1192
1181
1193
-- pass configurations
1182
1194
local argv = {}
@@ -1195,8 +1207,19 @@ function build(package, configs, opt)
1195
1207
-- do configure
1196
1208
local cmake = assert (find_tool (" cmake" ), " cmake not found!" )
1197
1209
os .vrunv (cmake .program , argv , {envs = opt .envs or buildenvs (package , opt )})
1210
+ os .cd (oldir )
1211
+ end
1212
+
1213
+ -- build package
1214
+ function build (package , configs , opt )
1215
+ opt = opt or {}
1216
+ local cmake_generator = _get_cmake_generator (package , opt )
1217
+
1218
+ -- do configure
1219
+ configure (package , configs , opt )
1198
1220
1199
1221
-- do build
1222
+ local oldir = _enter_buildir (package , opt )
1200
1223
if opt .cmake_build then
1201
1224
_build_for_cmakebuild (package , configs , opt )
1202
1225
elseif cmake_generator then
@@ -1224,30 +1247,11 @@ function install(package, configs, opt)
1224
1247
opt = opt or {}
1225
1248
local cmake_generator = _get_cmake_generator (package , opt )
1226
1249
1227
- -- enter build directory
1228
- local buildir = opt .buildir or package :buildir ()
1229
- os .mkdir (path .join (buildir , " install" ))
1230
- local oldir = os .cd (buildir )
1231
-
1232
- -- pass configurations
1233
- local argv = {}
1234
- for name , value in pairs (_get_configs (package , configs , opt )) do
1235
- value = tostring (value ):trim ()
1236
- if type (name ) == " number" then
1237
- if value ~= " " then
1238
- table.insert (argv , value )
1239
- end
1240
- else
1241
- table.insert (argv , " -D" .. name .. " =" .. value )
1242
- end
1243
- end
1244
- table.insert (argv , oldir )
1245
-
1246
- -- generate build file
1247
- local cmake = assert (find_tool (" cmake" ), " cmake not found!" )
1248
- os .vrunv (cmake .program , argv , {envs = opt .envs or buildenvs (package , opt )})
1250
+ -- do configure
1251
+ configure (package , configs , opt )
1249
1252
1250
1253
-- do build and install
1254
+ local oldir = _enter_buildir (package , opt )
1251
1255
if opt .cmake_build then
1252
1256
_install_for_cmakebuild (package , configs , opt )
1253
1257
elseif cmake_generator then
0 commit comments