@@ -37,14 +37,15 @@ import (
3737// Cmake contains all configuration necessary to configure and build a CMake project
3838type Cmake struct {
3939 // Configs required for CMakeLists.txt
40- Name string // Executable name
41- IsCpp bool
42- Standard int // CMAKE_C/CXX_STANDARD
43- Files []string
44- IncludeDirs []string
45- LinkLibs []string // Library names or full paths
46- LinkDirs []string // Where should the linker look for libraries
47- Generator string
40+ Name string // Executable name
41+ IsCpp bool
42+ Standard int // CMAKE_C/CXX_STANDARD
43+ Files []string
44+ IncludeDirs []string
45+ LinkLibs []string // Library names or full paths
46+ LinkDirs []string // Where should the linker look for libraries
47+ Generator string
48+ ConfigureFlags []string
4849
4950 // Build configuration
5051 ConfDir string
@@ -159,20 +160,79 @@ func (cmake *Cmake) Configure() ([]byte, []byte, error) {
159160 cmake .Generator = "MinGW Makefiles"
160161 }
161162
162- if len (cmake .Generator ) > 0 {
163- return cmakeExec (cmake .BuildDir , cmake .ConfDir , "-G" , cmake .Generator )
164- } else {
165- return cmakeExec (cmake .BuildDir , cmake .ConfDir )
163+ var args = []string {cmake .ConfDir }
164+ args = append (args , cmake .ConfigureFlags [:]... )
165+
166+ if len (cmake .Generator ) > 0 && cmake .Generator != "default" {
167+ args = append (args , "-G" , cmake .Generator )
166168 }
169+
170+ return cmakeExec (cmake .BuildDir , args [:]... )
167171}
168172
169- // Build runs cmake build step.
170- func (cmake * Cmake ) Build () ([]byte , []byte , error ) {
173+ // Configure runs cmake configuration step without any CI quirks as is.
174+ func (cmake * Cmake ) ConfigureRaw () ([]byte , []byte , error ) {
175+ var args = []string {cmake .ConfDir }
176+ args = append (args , cmake .ConfigureFlags [:]... )
177+
178+ if len (cmake .Generator ) > 0 && cmake .Generator != "default" {
179+ args = append (args , "-G" , cmake .Generator )
180+ }
181+
182+ return cmakeExec (cmake .BuildDir , args [:]... )
183+ }
184+
185+ // Build runs cmake build "Name" target step.
186+ func (cmake * Cmake ) BuildTarget () ([]byte , []byte , error ) {
171187 return cmakeExec (cmake .ConfDir ,
172188 "--build" , cmake .BuildDir ,
173189 "--target" , cmake .Name ,
174- "--" ,
175- "-j" + strconv .FormatInt (int64 (runtime .NumCPU ()/ 2 ), 10 ))
190+ "--parallel " + strconv .FormatInt (int64 (runtime .NumCPU ()/ 2 ), 10 ),
191+ )
192+ }
193+
194+ // Build runs cmake build "Name" target step.
195+ func (cmake * Cmake ) BuildWithTarget (target string ) ([]byte , []byte , error ) {
196+ return cmakeExec (cmake .ConfDir ,
197+ "--build" , cmake .BuildDir ,
198+ "--target" , target ,
199+ // "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
200+ )
201+ }
202+
203+ // Build runs cmake build step.
204+ func (cmake * Cmake ) BuildDefaults () ([]byte , []byte , error ) {
205+ return cmakeExec (cmake .ConfDir ,
206+ "--build" , cmake .BuildDir ,
207+ // "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
208+ )
209+ }
210+
211+ // Build runs cmake default build step with config
212+ func (cmake * Cmake ) BuildDefaultsWithConfig (config string ) ([]byte , []byte , error ) {
213+ return cmakeExec (cmake .ConfDir ,
214+ "--build" , cmake .BuildDir ,
215+ "--config" , config ,
216+ // "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
217+ )
218+ }
219+
220+ // Build runs cmake default build step with config
221+ func (cmake * Cmake ) BuildTargetWithConfig (config , target string ) ([]byte , []byte , error ) {
222+ return cmakeExec (cmake .ConfDir ,
223+ "--build" , cmake .BuildDir ,
224+ "--config" , config ,
225+ "--target" , target ,
226+ // "--parallel "+strconv.FormatInt(int64(runtime.NumCPU()/2), 10),
227+ )
228+ }
229+
230+ func CopyDir (cwd string , src string , dst string ) ([]byte , []byte , error ) {
231+ return cmakeExec (cwd , "-E" , "copy_directory" , src , dst )
232+ }
233+
234+ func CopyFile (cwd string , file string , dst string ) ([]byte , []byte , error ) {
235+ return cmakeExec (cwd , "-E" , "copy" , file , dst )
176236}
177237
178238func cmakeExec (cwd string , args ... string ) (stdOut []byte , stdErr []byte , err error ) {
0 commit comments