0030702: Configuration, CMake - error for iOS build due to searching macos frameworks
[occt.git] / adm / genproj.tcl
CommitLineData
910970ab 1# =======================================================================
d1a67b9d 2# Created on: 2014-07-24
3# Created by: SKI
4# Copyright (c) 2014 OPEN CASCADE SAS
5#
6# This file is part of Open CASCADE Technology software library.
7#
8# This library is free software; you can redistribute it and/or modify it under
9# the terms of the GNU Lesser General Public License version 2.1 as published
10# by the Free Software Foundation, with special exception defined in the file
11# OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12# distribution for complete text of the license and disclaimer of any warranty.
13#
14# Alternatively, this file may be used under the terms of Open CASCADE
15# commercial license or contractual agreement.
16
17# =======================================================================
18# This script defines Tcl command genproj generating project files for
944d808c 19# different IDEs and platforms. Run it with -help to get synopsis.
910970ab 20# =======================================================================
21
d1a67b9d 22source [file join [file dirname [info script]] genconfdeps.tcl]
23
944d808c 24# the script is assumed to be run from CASROOT (or dependent Products root)
25set path [file normalize .]
e31a8e52 26set THE_CASROOT ""
910970ab 27set fBranch ""
e31a8e52 28if { [info exists ::env(CASROOT)] } {
471a2ca0 29 set THE_CASROOT [file normalize "$::env(CASROOT)"]
e31a8e52 30}
c7d774c5 31
910970ab 32proc _get_options { platform type branch } {
910970ab 33 set res ""
e31a8e52 34 if {[file exists "$::THE_CASROOT/adm/CMPLRS"]} {
35 set fd [open "$::THE_CASROOT/adm/CMPLRS" rb]
910970ab 36 set opts [split [read $fd] "\n"]
37 close $fd
38 foreach line $opts {
39 if {[regexp "^${platform} ${type} ${branch} (.+)$" $line dummy res]} {
40 while {[regexp {\(([^\(\)]+) ([^\(\)]+) ([^\(\)]+)\)(.+)} $res dummy p t b oldres]} {
41 set res "[_get_options $p $t $b] $oldres"
42 }
43 }
44 }
45 }
46 return $res
47}
48
49proc _get_type { name } {
e31a8e52 50 set UDLIST {}
51 if {[file exists "$::path/adm/UDLIST"]} {
52 set fd [open "$::path/adm/UDLIST" rb]
53 set UDLIST [concat $UDLIST [split [read $fd] "\n"]]
910970ab 54 close $fd
e31a8e52 55 }
56 if { "$::path/adm/UDLIST" != "$::THE_CASROOT/adm/UDLIST" && [file exists "$::THE_CASROOT/adm/UDLIST"] } {
57 set fd [open "$::THE_CASROOT/adm/UDLIST" rb]
58 set UDLIST [concat $UDLIST [split [read $fd] "\n"]]
59 close $fd
60 }
61
62 foreach uitem $UDLIST {
63 set line [split $uitem]
64 if {[lindex $line 1] == "$name"} {
65 return [lindex $line 0]
910970ab 66 }
67 }
68 return ""
69}
70
71proc _get_used_files { pk {inc true} {src true} } {
72 global path
73 set type [_get_type $pk]
74 set lret {}
75 set pk_path "$path/src/$pk"
76 set FILES_path "$path/src/$pk/FILES"
77 set FILES {}
78 if {[file exists $FILES_path]} {
79 set fd [open $FILES_path rb]
80 set FILES [split [read $fd] "\n"]
81 close $fd
82 }
83 set FILES [lsearch -inline -all -not -exact $FILES ""]
84
85 set index -1
86 foreach line $FILES {
87 incr index
88 if {$inc && ([regexp {([^:\s]*\.[hgl]xx)$} $line dummy name] || [regexp {([^:\s]*\.h)$} $line dummy name]) && [file exists $pk_path/$name]} {
89 lappend lret "pubinclude $name $pk_path/$name"
90 continue
91 }
92 if {[regexp {:} $line]} {
93 regexp {[^:]*:+([^\s]*)} $line dummy line
94 }
95 regexp {([^\s]*)} $line dummy line
96 if {$src && [file exists $pk_path/$line]} {
97 lappend lret "source $line $pk_path/$line"
98 }
99 }
100 return $lret
101}
102
e31a8e52 103# return location of the path within src directory
104proc osutils:findSrcSubPath {theSubPath} {
105 if {[file exists "$::path/src/$theSubPath"]} {
106 return "$::path/src/$theSubPath"
107 }
108 return "$::THE_CASROOT/src/$theSubPath"
109}
110
ee5befae 111# Auxiliary tool comparing content of two files line-by-line.
112proc osutils:isEqualContent { theContent1 theContent2 } {
113 set aLen1 [llength $theContent1]
114 set aLen2 [llength $theContent2]
115 if { $aLen1 != $aLen2 } {
116 return false
117 }
118
119 for {set aLineIter 0} {$aLineIter < $aLen1} {incr aLineIter} {
120 set aLine1 [lindex $theContent1 $aLineIter]
121 set aLine2 [lindex $theContent2 $aLineIter]
122 if { $aLine1 != $aLine2 } {
123 return false
124 }
125 }
126 return true
127}
128
129# Auxiliary function for writing new file content only if it has been actually changed
130# (e.g. to preserve file timestamp on no change).
131# Useful for automatically (re)generated files.
132proc osutils:writeTextFile { theFile theContent {theEol lf} } {
133 if {[file exists "${theFile}"]} {
134 set aFileOld [open "${theFile}" rb]
135 fconfigure $aFileOld -translation crlf
136 set aLineListOld [split [read $aFileOld] "\n"]
137 close $aFileOld
138
139 # append empty line for proper comparison (which will be implicitly added by last puts below)
140 set aContent $theContent
141 lappend aContent ""
142 if { [osutils:isEqualContent $aLineListOld $aContent] == true } {
143 return false
144 }
145
146 file delete -force "${theFile}"
147 }
148
149 set anOutFile [open "$theFile" "w"]
150 fconfigure $anOutFile -translation $theEol
151 foreach aLine ${theContent} {
152 puts $anOutFile "${aLine}"
153 }
154 close $anOutFile
155 return true
156}
157
158# Function re-generating header files for specified text resource
159proc genResources { theResource } {
160 global path
161
162 set aResFileList {}
163 set aResourceAbsPath [file normalize "${path}/src/${theResource}"]
164 set aResourceDirectory ""
165 set isResDirectory false
166
167 if {[file isdirectory "${aResourceAbsPath}"]} {
168 if {[file exists "${aResourceAbsPath}/FILES"]} {
169 set aFilesFile [open "${aResourceAbsPath}/FILES" rb]
170 set aResFileList [split [read $aFilesFile] "\n"]
171 close $aFilesFile
172 }
173 set aResFileList [lsearch -inline -all -not -exact $aResFileList ""]
174 set aResourceDirectory "${theResource}"
175 set isResDirectory true
176 } else {
177 set aResourceName [file tail "${theResource}"]
178 lappend aResFileList "res:::${aResourceName}"
179 set aResourceDirectory [file dirname "${theResource}"]
180 }
181
182 foreach aResFileIter ${aResFileList} {
183 if {![regexp {^[^:]+:::(.+)} "${aResFileIter}" dump aResFileIter]} {
184 continue
185 }
186
187 set aResFileName [file tail "${aResFileIter}"]
188 regsub -all {\.} "${aResFileName}" {_} aResFileName
189 set aHeaderFileName "${aResourceDirectory}_${aResFileName}.pxx"
190 if { $isResDirectory == true && [lsearch $aResFileList $aHeaderFileName] == -1 } {
191 continue
192 }
193
194 # generate
195 set aContent {}
196 lappend aContent "// This file has been automatically generated from resource file src/${aResourceDirectory}/${aResFileIter}"
197 lappend aContent ""
198
199 # generate necessary structures
200 set aLineList {}
201 if {[file exists "${path}/src/${aResourceDirectory}/${aResFileIter}"]} {
202 set anInputFile [open "${path}/src/${aResourceDirectory}/${aResFileIter}" rb]
203 fconfigure $anInputFile -translation crlf
204 set aLineList [split [read $anInputFile] "\n"]
205 close $anInputFile
206 }
207
208 # drop empty trailing line
209 set anEndOfFile ""
210 if { [lindex $aLineList end] == "" } {
211 set aLineList [lreplace $aLineList end end]
212 set anEndOfFile "\\n"
213 }
214
215 lappend aContent "static const char ${aResourceDirectory}_${aResFileName}\[\] ="
216 set aNbLines [llength $aLineList]
217 set aLastLine [expr $aNbLines - 1]
218 for {set aLineIter 0} {$aLineIter < $aNbLines} {incr aLineIter} {
219 set aLine [lindex $aLineList $aLineIter]
220 regsub -all {\"} "${aLine}" {\\"} aLine
221 if { $aLineIter == $aLastLine } {
222 lappend aContent " \"${aLine}${anEndOfFile}\";"
223 } else {
224 lappend aContent " \"${aLine}\\n\""
225 }
226 }
227
228 # Save generated content to header file
229 set aHeaderFilePath "${path}/src/${aResourceDirectory}/${aHeaderFileName}"
230 if { [osutils:writeTextFile $aHeaderFilePath $aContent] == true } {
231 puts "Generating header file from resource file: ${path}/src/${aResourceDirectory}/${aResFileIter}"
232 } else {
233 #puts "Header file from resource ${path}/src/${aResourceDirectory}/${aResFileIter} is up-to-date"
234 }
235 }
236}
237
238# Function re-generating header files for all text resources
239proc genAllResources {} {
240 global path
241 set aCasRoot [file normalize $path]
242 if {![file exists "$aCasRoot/adm/RESOURCES"]} {
243 puts "OCCT directory is not defined correctly: $aCasRoot"
244 return
245 }
246
247 set aFileResources [open "$aCasRoot/adm/RESOURCES" rb]
248 set anAdmResources [split [read $aFileResources] "\r\n"]
249 close $aFileResources
250 set anAdmResources [lsearch -inline -all -not -exact $anAdmResources ""]
251
252 foreach line $anAdmResources {
253 genResources "${line}"
254 }
255}
256
910970ab 257# Wrapper-function to generate VS project files
d6cda17a 258proc genproj {theFormat args} {
aafe169f 259 set aSupportedFormats { "vc7" "vc8" "vc9" "vc10" "vc11" "vc12" "vc14" "vc141" "cbp" "xcd" "pro"}
d6cda17a 260 set aSupportedPlatforms { "wnt" "uwp" "lin" "mac" "ios" "qnx" }
910970ab 261 set isHelpRequire false
910970ab 262
d6cda17a 263 # check format argument
264 if { $theFormat == "-h" || $theFormat == "-help" || $theFormat == "--help" } {
944d808c 265 set isHelpRequire true
d6cda17a 266 } elseif { [lsearch -exact $aSupportedFormats $theFormat] < 0 } {
267 puts "Error: genproj: unrecognized project format \"$theFormat\""
910970ab 268 set isHelpRequire true
269 }
270
944d808c 271 # choice of compiler for Code::Blocks, currently hard-coded
272 set aCmpl "gcc"
c7d774c5 273
944d808c 274 # Determine default platform: wnt for vc*, mac for xcd, current for cbp
d6cda17a 275 if { [regexp "^vc" $theFormat] } {
944d808c 276 set aPlatform "wnt"
d6cda17a 277 } elseif { $theFormat == "xcd" || $::tcl_platform(os) == "Darwin" } {
944d808c 278 set aPlatform "mac"
279 } elseif { $::tcl_platform(platform) == "windows" } {
280 set aPlatform "wnt"
281 } elseif { $::tcl_platform(platform) == "unix" } {
282 set aPlatform "lin"
910970ab 283 }
284
944d808c 285 # Check optional arguments
286 set aLibType "dynamic"
287 foreach arg $args {
288 if { $arg == "-h" || $arg == "-help" || $arg == "--help" } {
289 set isHelpRequire true
290 } elseif { [lsearch -exact $aSupportedPlatforms $arg] >= 0 } {
291 set aPlatform $arg
292 } elseif { $arg == "-static" } {
293 set aLibType "static"
294 puts "Static build has been selected"
295 } elseif { $arg == "-dynamic" } {
296 set aLibType "dynamic"
297 puts "Dynamic build has been selected"
298 } else {
299 puts "Error: genproj: unrecognized option \"$arg\""
300 set isHelpRequire true
910970ab 301 }
302 }
303
304 if { $isHelpRequire == true } {
d6cda17a 305 puts "usage: genproj Format \[Platform\] \[-static\] \[-h|-help|--help\]
910970ab 306
d6cda17a 307 Format must be one of:
7fbac3c2 308 vc8 - Visual Studio 2005
309 vc9 - Visual Studio 2008
310 vc10 - Visual Studio 2010
311 vc11 - Visual Studio 2012
312 vc12 - Visual Studio 2013
313 vc14 - Visual Studio 2015
d6cda17a 314 vc141 - Visual Studio 2017
7fbac3c2 315 cbp - CodeBlocks
316 xcd - XCode
aafe169f 317 pro - Qt Creator
944d808c 318
d6cda17a 319 Platform (optional):
320 wnt - Windows Desktop
321 uwp - Universal Windows Platform
944d808c 322 lin - Linux
323 mac - OS X
324 ios - iOS
325 qnx - QNX
326
327 Option -static can be used with XCode to build static libraries
328 "
329 return
910970ab 330 }
331
944d808c 332 if { ! [info exists aPlatform] } {
333 puts "Error: genproj: Cannon identify default platform, please specify!"
334 return
910970ab 335 }
cb6a2fbc 336
d6cda17a 337 puts "Preparing to generate $theFormat projects for $aPlatform platform..."
910970ab 338
d6cda17a 339 # base path to where to generate projects, hardcoded from current dir
944d808c 340 set anAdmPath [file normalize "${::path}/adm"]
910970ab 341
d6cda17a 342 OS:MKPRC "$anAdmPath" "$theFormat" "$aLibType" "$aPlatform" "$aCmpl"
910970ab 343
d6cda17a 344 genprojbat "$theFormat" "$aPlatform"
ee5befae 345 genAllResources
944d808c 346}
910970ab 347
471a2ca0 348# copy file providing warning if the target file exists and has
349# different date or size; if it is newer than source, save it as .bak
350proc copy_with_warning {from to} {
351 if { [file exists "$to"] &&
352 ([file size "$to"] != [file size "$from"] ||
353 [file mtime "$to"] != [file mtime "$from"]) } {
354 puts "Warning: file $to is updated (copied from $from)!"
355 if { [file mtime $to] > [file mtime $from] } {
356 puts "Info: old content of file $to is saved in ${to}.bak"
357 file copy -force -- "$to" "${to}.bak"
358 }
359 }
360
361 file copy -force -- "$from" "$to"
362}
363
d6cda17a 364proc genprojbat {theFormat thePlatform} {
910970ab 365 set aTargetPlatformExt sh
d6cda17a 366 if { $thePlatform == "wnt" || $thePlatform == "uwp" } {
910970ab 367 set aTargetPlatformExt bat
368 }
369
d6cda17a 370 if {"$theFormat" != "cmake"} {
944d808c 371 # copy env.bat/sh only if not yet present
372 if { ! [file exists "$::path/env.${aTargetPlatformExt}"] } {
373 set anEnvTmplFile [open "$::THE_CASROOT/adm/templates/env.${aTargetPlatformExt}" "r"]
374 set anEnvTmpl [read $anEnvTmplFile]
375 close $anEnvTmplFile
376
377 set aCasRoot ""
378 if { [file normalize "$::path"] != [file normalize "$::THE_CASROOT"] } {
379 set aCasRoot [relativePath "$::path" "$::THE_CASROOT"]
380 }
910970ab 381
944d808c 382 regsub -all -- {__CASROOT__} $anEnvTmpl "$aCasRoot" anEnvTmpl
910970ab 383
944d808c 384 set anEnvFile [open "$::path/env.${aTargetPlatformExt}" "w"]
385 puts $anEnvFile $anEnvTmpl
386 close $anEnvFile
387 }
910970ab 388
471a2ca0 389 copy_with_warning "$::THE_CASROOT/adm/templates/draw.${aTargetPlatformExt}" "$::path/draw.${aTargetPlatformExt}"
910970ab 390 }
391
d6cda17a 392 if { [regexp {^vc} $theFormat] } {
471a2ca0 393 copy_with_warning "$::THE_CASROOT/adm/templates/msvc.bat" "$::path/msvc.bat"
910970ab 394 } else {
d6cda17a 395 switch -exact -- "$theFormat" {
7c65581d 396 "cbp" {
397 file copy -force -- "$::THE_CASROOT/adm/templates/codeblocks.sh" "$::path/codeblocks.sh"
398 file copy -force -- "$::THE_CASROOT/adm/templates/codeblocks.bat" "$::path/codeblocks.bat"
aafe169f 399
944d808c 400 # Code::Blocks 16.01 does not create directory for import libs, help him
aafe169f 401 set aPlatformAndCompiler "${thePlatform}/gcc"
402 if { "$thePlatform" == "mac" || "$thePlatform" == "ios" } {
403 set aPlatformAndCompiler "${thePlatform}/clang"
404 }
405 file mkdir "$::path/${aPlatformAndCompiler}/lib"
406 file mkdir "$::path/${aPlatformAndCompiler}/libd"
7c65581d 407 }
e31a8e52 408 "xcd" { file copy -force -- "$::THE_CASROOT/adm/templates/xcode.sh" "$::path/xcode.sh" }
910970ab 409 }
410 }
411}
412
413###### MSVC #############################################################33
414proc removeAllOccurrencesOf { theObject theList } {
415 set aSortIndices [lsort -decreasing [lsearch -all -nocase $theList $theObject]]
416 foreach anIndex $aSortIndices {
417 set theList [lreplace $theList $anIndex $anIndex]
418 }
419 return $theList
420}
421
c7d774c5 422set aTKNullKey "TKNull"
423set THE_GUIDS_LIST($aTKNullKey) "{00000000-0000-0000-0000-000000000000}"
910970ab 424
d6cda17a 425# Entry function to generate project files
7c65581d 426# @param theOutDir Root directory for project files
d6cda17a 427# @param theFormat Project format name (vc.. for Visual Studio projects, cbp for Code::Blocks, xcd for XCode)
7c65581d 428# @param theLibType Library type - dynamic or static
429# @param thePlatform Optional target platform for cross-compiling, e.g. ios for iOS
430# @param theCmpl Compiler option (msvc or gcc)
d6cda17a 431proc OS:MKPRC { theOutDir theFormat theLibType thePlatform theCmpl } {
944d808c 432 global path
910970ab 433 set anOutRoot $theOutDir
434 if { $anOutRoot == "" } {
435 error "Error : \"theOutDir\" is not initialized"
436 }
437
438 # Create output directory
944d808c 439 set aWokStation "$thePlatform"
d6cda17a 440 if { [regexp {^vc} $theFormat] } {
910970ab 441 set aWokStation "msvc"
442 }
d6cda17a 443 set aSuffix ""
444 set isUWP 0
445 if { $thePlatform == "uwp" } {
446 set aSuffix "-uwp"
447 set isUWP 1
448 }
449 set anOutDir "${anOutRoot}/${aWokStation}/${theFormat}${aSuffix}"
910970ab 450
451 # read map of already generated GUIDs
d6cda17a 452 set aGuidsFilePath [file join $anOutDir "wok_${theFormat}_guids.txt"]
910970ab 453 if [file exists "$aGuidsFilePath"] {
454 set aFileIn [open "$aGuidsFilePath" r]
455 set aFileDataRaw [read $aFileIn]
456 close $aFileIn
457 set aFileData [split $aFileDataRaw "\n"]
458 foreach aLine $aFileData {
459 set aLineSplt [split $aLine "="]
460 if { [llength $aLineSplt] == 2 } {
461 set ::THE_GUIDS_LIST([lindex $aLineSplt 0]) [lindex $aLineSplt 1]
462 }
463 }
464 }
465
466 # make list of modules and platforms
467 set aModules [OS:init]
c7d774c5 468 if { "$thePlatform" == "ios" } {
469 set goaway [list Draw]
470 set aModules [osutils:juststation $goaway $aModules]
471 }
910970ab 472
7fbac3c2 473 # Draw module is turned off due to it is not supported on UWP
d6cda17a 474 if { $isUWP } {
7fbac3c2 475 set aDrawIndex [lsearch -exact ${aModules} "Draw"]
476 if { ${aDrawIndex} != -1 } {
477 set aModules [lreplace ${aModules} ${aDrawIndex} ${aDrawIndex}]
478 }
479 }
480
910970ab 481 # create the out dir if it does not exist
482 if (![file isdirectory $path/inc]) {
483 puts "$path/inc folder does not exists and will be created"
484 wokUtils:FILES:mkdir $path/inc
485 }
486
487 # collect all required header files
488 puts "Collecting required header files into $path/inc ..."
944d808c 489 osutils:collectinc $aModules $path/inc
910970ab 490
aafe169f 491 if { "$theFormat" == "pro" } {
492 return
493 }
494
495 # generate one solution for all projects if complete OS or VAS is processed
496 set anAllSolution "OCCT"
497
498 wokUtils:FILES:mkdir $anOutDir
499 if { ![file exists $anOutDir] } {
500 puts stderr "Error: Could not create output directory \"$anOutDir\""
501 return
502 }
503
d6cda17a 504 # Generating project files for the selected format
505 switch -exact -- "$theFormat" {
910970ab 506 "vc7" -
507 "vc8" -
508 "vc9" -
7fbac3c2 509 "vc10" -
510 "vc11" -
511 "vc12" -
512 "vc14" -
d6cda17a 513 "vc141" { OS:MKVC $anOutDir $aModules $anAllSolution $theFormat $isUWP}
7fbac3c2 514 "cbp" { OS:MKCBP $anOutDir $aModules $anAllSolution $thePlatform $theCmpl }
515 "xcd" {
c7d774c5 516 set ::THE_GUIDS_LIST($::aTKNullKey) "000000000000000000000000"
517 OS:MKXCD $anOutDir $aModules $anAllSolution $theLibType $thePlatform
518 }
910970ab 519 }
910970ab 520
521 # Store generated GUIDs map
522 set anOutFile [open "$aGuidsFilePath" "w"]
523 fconfigure $anOutFile -translation lf
524 foreach aKey [array names ::THE_GUIDS_LIST] {
525 set aValue $::THE_GUIDS_LIST($aKey)
526 puts $anOutFile "${aKey}=${aValue}"
527 }
528 close $anOutFile
529}
530
531# Function to generate Visual Studio solution and project files
d6cda17a 532proc OS:MKVC { theOutDir theModules theAllSolution theVcVer isUWP } {
910970ab 533
534 puts stderr "Generating VS project files for $theVcVer"
535
536 # generate projects for toolkits and separate solution for each module
537 foreach aModule $theModules {
538 OS:vcsolution $theVcVer $aModule $aModule $theOutDir ::THE_GUIDS_LIST
d6cda17a 539 OS:vcproj $theVcVer $isUWP $aModule $theOutDir ::THE_GUIDS_LIST
910970ab 540 }
541
542 # generate single solution "OCCT" containing projects from all modules
543 if { "$theAllSolution" != "" } {
544 OS:vcsolution $theVcVer $theAllSolution $theModules $theOutDir ::THE_GUIDS_LIST
545 }
546
547 puts "The Visual Studio solution and project files are stored in the $theOutDir directory"
548}
549
550proc OS:init {{os {}}} {
e31a8e52 551 set askplat $os
552 set aModules {}
553 if { "$os" == "" } {
554 set os $::tcl_platform(os)
555 }
556
557 if [file exists "$::path/src/VAS/Products.tcl"] {
558 source "$::path/src/VAS/Products.tcl"
559 foreach aModuleIter [VAS:Products] {
560 set aFileTcl "$::path/src/VAS/${aModuleIter}.tcl"
561 if [file exists $aFileTcl] {
562 source $aFileTcl
563 lappend aModules $aModuleIter
564 } else {
565 puts stderr "Definition file for module $aModuleIter is not found in unit VAS"
566 }
910970ab 567 }
e31a8e52 568 return $aModules
569 }
910970ab 570
e31a8e52 571 # Load list of OCCT modules and their definitions
572 source "$::path/src/OS/Modules.tcl"
573 foreach aModuleIter [OS:Modules] {
574 set aFileTcl "$::path/src/OS/${aModuleIter}.tcl"
575 if [file exists $aFileTcl] {
576 source $aFileTcl
577 lappend aModules $aModuleIter
578 } else {
579 puts stderr "Definition file for module $aModuleIter is not found in unit OS"
580 }
581 }
910970ab 582
e31a8e52 583 return $aModules
910970ab 584}
585
586# topological sort. returns a list { {a h} {b g} {c f} {c h} {d i} } => { d a b c i g f h }
587proc wokUtils:EASY:tsort { listofpairs } {
588 foreach x $listofpairs {
589 set e1 [lindex $x 0]
590 set e2 [lindex $x 1]
591 if ![info exists pcnt($e1)] {
592 set pcnt($e1) 0
593 }
594 if ![ info exists pcnt($e2)] {
595 set pcnt($e2) 1
596 } else {
597 incr pcnt($e2)
598 }
599 if ![info exists scnt($e1)] {
600 set scnt($e1) 1
601 } else {
602 incr scnt($e1)
603 }
604 set l {}
605 if [info exists slist($e1)] {
606 set l $slist($e1)
607 }
608 lappend l $e2
609 set slist($e1) $l
610 }
611 set nodecnt 0
612 set back 0
613 foreach node [array names pcnt] {
614 incr nodecnt
615 if { $pcnt($node) == 0 } {
616 incr back
617 set q($back) $node
618 }
619 if ![info exists scnt($node)] {
620 set scnt($node) 0
621 }
622 }
623 set res {}
624 for {set front 1} { $front <= $back } { incr front } {
625 lappend res [set node $q($front)]
626 for {set i 1} {$i <= $scnt($node) } { incr i } {
627 set ll $slist($node)
628 set j [expr {$i - 1}]
629 set u [expr { $pcnt([lindex $ll $j]) - 1 }]
630 if { [set pcnt([lindex $ll $j]) $u] == 0 } {
631 incr back
632 set q($back) [lindex $ll $j]
633 }
634 }
635 }
636 if { $back != $nodecnt } {
637 puts stderr "input contains a cycle"
638 return {}
639 } else {
640 return $res
641 }
642}
643
644proc wokUtils:LIST:Purge { l } {
645 set r {}
646 foreach e $l {
647 if ![info exist tab($e)] {
648 lappend r $e
649 set tab($e) {}
650 }
651 }
652 return $r
653}
654
655# Read file pointed to by path
656# 1. sort = 1 tri
657# 2. trim = 1 plusieurs blancs => 1 seul blanc
658# 3. purge= not yet implemented.
659# 4. emptl= dont process blank lines
660proc wokUtils:FILES:FileToList { path {sort 0} {trim 0} {purge 0} {emptl 1} } {
661 if ![ catch { set id [ open $path r ] } ] {
662 set l {}
663 while {[gets $id line] >= 0 } {
664 if { $trim } {
665 regsub -all {[ ]+} $line " " line
666 }
667 if { $emptl } {
668 if { [string length ${line}] != 0 } {
669 lappend l $line
670 }
671 } else {
672 lappend l $line
673 }
674 }
675 close $id
676 if { $sort } {
677 return [lsort $l]
678 } else {
679 return $l
680 }
681 } else {
682 return {}
683 }
684}
685
686# retorn the list of executables in module.
687proc OS:executable { module } {
688 set lret {}
689 foreach XXX [${module}:ressources] {
690 if { "[lindex $XXX 1]" == "x" } {
691 lappend lret [lindex $XXX 2]
692 }
693 }
694 return $lret
695}
696
697# Topological sort of toolkits in tklm
698proc osutils:tk:sort { tklm } {
699 set tkby2 {}
700 foreach tkloc $tklm {
701 set lprg [wokUtils:LIST:Purge [osutils:tk:close $tkloc]]
702 foreach tkx $lprg {
703 if { [lsearch $tklm $tkx] != -1 } {
704 lappend tkby2 [list $tkx $tkloc]
705 } else {
706 lappend tkby2 [list $tkloc {}]
707 }
708 }
709 }
710 set lret {}
711 foreach e [wokUtils:EASY:tsort $tkby2] {
712 if { $e != {} } {
713 lappend lret $e
714 }
715 }
716 return $lret
717}
718
719# close dependencies of ltk. (full wok pathes of toolkits)
720# The CURRENT WOK LOCATION MUST contains ALL TOOLKITS required.
721# (locate not performed.)
722proc osutils:tk:close { ltk } {
723 set result {}
724 set recurse {}
725 foreach dir $ltk {
726 set ids [LibToLink $dir]
e31a8e52 727# puts "osutils:tk:close($ltk) ids='$ids'"
910970ab 728 set eated [osutils:tk:eatpk $ids]
729 set result [concat $result $eated]
730 set ids [LibToLink $dir]
731 set result [concat $result $ids]
732
733 foreach file $eated {
e31a8e52 734 set kds [osutils:findSrcSubPath "$file/EXTERNLIB"]
910970ab 735 if { [osutils:tk:eatpk $kds] != {} } {
736 lappend recurse $file
737 }
738 }
739 }
740 if { $recurse != {} } {
741 set result [concat $result [osutils:tk:close $recurse]]
742 }
743 return $result
744}
745
746proc osutils:tk:eatpk { EXTERNLIB } {
747 set l [wokUtils:FILES:FileToList $EXTERNLIB]
748 set lret {}
749 foreach str $l {
750 if ![regexp -- {(CSF_[^ ]*)} $str csf] {
751 lappend lret $str
752 }
753 }
754 return $lret
755}
756# Define libraries to link using only EXTERNLIB file
757
758proc LibToLink {theTKit} {
910970ab 759 regexp {^.*:([^:]+)$} $theTKit dummy theTKit
760 set type [_get_type $theTKit]
761 if {$type != "t" && $type != "x"} {
762 return
763 }
764 set aToolkits {}
e31a8e52 765 set anExtLibList [osutils:tk:eatpk [osutils:findSrcSubPath "$theTKit/EXTERNLIB"]]
910970ab 766 foreach anExtLib $anExtLibList {
767 set aFullPath [LocateRecur $anExtLib]
768 if { "$aFullPath" != "" && [_get_type $anExtLib] == "t" } {
769 lappend aToolkits $anExtLib
770 }
771 }
772 return $aToolkits
773}
774# Search unit recursively
775
776proc LocateRecur {theName} {
e31a8e52 777 set theNamePath [osutils:findSrcSubPath "$theName"]
910970ab 778 if {[file isdirectory $theNamePath]} {
779 return $theNamePath
780 }
781 return ""
782}
783
d6cda17a 784proc OS:genGUID { {theFormat "vc"} } {
785 if { "$theFormat" == "vc" } {
910970ab 786 set p1 "[format %07X [expr { int(rand() * 268435456) }]][format %X [expr { int(rand() * 16) }]]"
787 set p2 "[format %04X [expr { int(rand() * 6536) }]]"
788 set p3 "[format %04X [expr { int(rand() * 6536) }]]"
789 set p4 "[format %04X [expr { int(rand() * 6536) }]]"
790 set p5 "[format %06X [expr { int(rand() * 16777216) }]][format %06X [expr { int(rand() * 16777216) }]]"
791 return "{$p1-$p2-$p3-$p4-$p5}"
792 } else {
793 set p1 "[format %04X [expr { int(rand() * 6536) }]]"
794 set p2 "[format %04X [expr { int(rand() * 6536) }]]"
795 set p3 "[format %04X [expr { int(rand() * 6536) }]]"
796 set p4 "[format %04X [expr { int(rand() * 6536) }]]"
797 set p5 "[format %04X [expr { int(rand() * 6536) }]]"
798 set p6 "[format %04X [expr { int(rand() * 6536) }]]"
799 return "$p1$p2$p3$p4$p5$p6"
800 }
801}
802
803# collect all include file that required for theModules in theOutDir
944d808c 804proc osutils:collectinc {theModules theIncPath} {
910970ab 805 global path
910970ab 806 set aCasRoot [file normalize $path]
807 set anIncPath [file normalize $theIncPath]
808
809 if {![file isdirectory $aCasRoot]} {
810 puts "OCCT directory is not defined correctly: $aCasRoot"
811 return
812 }
813
814 set anUsedToolKits {}
815 foreach aModule $theModules {
816 foreach aToolKit [${aModule}:toolkits] {
817 lappend anUsedToolKits $aToolKit
818
819 foreach aDependency [LibToLink $aToolKit] {
820 lappend anUsedToolKits $aDependency
821 }
822 }
823 foreach anExecutable [OS:executable ${aModule}] {
824 lappend anUsedToolKits $anExecutable
825
826 foreach aDependency [LibToLink $anExecutable] {
827 lappend anUsedToolKits $aDependency
828 }
829 }
830 }
5951a088 831 set anUsedToolKits [lsort -unique $anUsedToolKits]
910970ab 832
833 set anUnits {}
834 foreach anUsedToolKit $anUsedToolKits {
835 set anUnits [concat $anUnits [osutils:tk:units $anUsedToolKit]]
836 }
5951a088 837 set anUnits [lsort -unique $anUnits]
838
839 # define copying style
840 set aCopyType "copy"
841 if { [info exists ::env(SHORTCUT_HEADERS)] } {
842 if { [string equal -nocase $::env(SHORTCUT_HEADERS) "hard"]
843 || [string equal -nocase $::env(SHORTCUT_HEADERS) "hardlink"] } {
844 set aCopyType "hardlink"
845 } elseif { [string equal -nocase $::env(SHORTCUT_HEADERS) "true"]
846 || [string equal -nocase $::env(SHORTCUT_HEADERS) "shortcut"] } {
847 set aCopyType "shortcut"
848 }
849 }
910970ab 850
5da3dfdf 851 set allHeaderFiles {}
5951a088 852 if { $aCopyType == "shortcut" } {
910970ab 853 # template preparation
e31a8e52 854 if { ![file exists $::THE_CASROOT/adm/templates/header.in] } {
855 puts "template file does not exist: $::THE_CASROOT/adm/templates/header.in"
910970ab 856 return
857 }
e31a8e52 858 set aHeaderTmpl [wokUtils:FILES:FileToString $::THE_CASROOT/adm/templates/header.in]
910970ab 859
860 # relative anIncPath in connection with aCasRoot/src
861 set aFromBuildIncToSrcPath [relativePath "$anIncPath" "$aCasRoot/src"]
862
863 # create and copy short-cut header files
864 foreach anUnit $anUnits {
5da3dfdf 865 osutils:checksrcfiles ${anUnit}
866
867 set aHFiles [_get_used_files ${anUnit} true false]
868 foreach aHeaderFile ${aHFiles} {
869 set aHeaderFileName [lindex ${aHeaderFile} 1]
870 lappend allHeaderFiles "${aHeaderFileName}"
910970ab 871
ee5befae 872 regsub -all -- {@OCCT_HEADER_FILE_CONTENT@} $aHeaderTmpl "#include \"$aFromBuildIncToSrcPath/$anUnit/$aHeaderFileName\"" aShortCutHeaderFileContent
910970ab 873
874 if {[file exists "$theIncPath/$aHeaderFileName"] && [file readable "$theIncPath/$aHeaderFileName"]} {
875 set fp [open "$theIncPath/$aHeaderFileName" r]
876 set aHeaderContent [read $fp]
877 close $fp
878
879 # minus eof
880 set aHeaderLenght [expr [string length $aHeaderContent] - 1]
881
882 if {$aHeaderLenght == [string length $aShortCutHeaderFileContent]} {
883 # remove eof from string
884 set aHeaderContent [string range $aHeaderContent 0 [expr $aHeaderLenght - 1]]
885
886 if {[string compare $aShortCutHeaderFileContent $aHeaderContent] == 0} {
887 continue
888 }
889 }
5951a088 890 file delete -force "$theIncPath/$aHeaderFileName"
910970ab 891 }
892
893 set aShortCutHeaderFile [open "$theIncPath/$aHeaderFileName" "w"]
894 fconfigure $aShortCutHeaderFile -translation lf
895 puts $aShortCutHeaderFile $aShortCutHeaderFileContent
896 close $aShortCutHeaderFile
897 }
5951a088 898 }
910970ab 899 } else {
900 set nbcopied 0
901 foreach anUnit $anUnits {
5da3dfdf 902 osutils:checksrcfiles ${anUnit}
903
904 set aHFiles [_get_used_files ${anUnit} true false]
905 foreach aHeaderFile ${aHFiles} {
906 set aHeaderFileName [lindex ${aHeaderFile} 1]
907 lappend allHeaderFiles "${aHeaderFileName}"
910970ab 908
909 # copy file only if target does not exist or is older than original
0fdbd10b 910 set torig [file mtime $aCasRoot/src/$anUnit/$aHeaderFileName]
5951a088 911 set tcopy 0
912 if { [file isfile $anIncPath/$aHeaderFileName] } {
910970ab 913 set tcopy [file mtime $anIncPath/$aHeaderFileName]
914 }
915 if { $tcopy < $torig } {
916 incr nbcopied
5951a088 917 if { $aCopyType == "hardlink" } {
918 if { $tcopy != 0 } {
919 file delete -force "$theIncPath/$aHeaderFileName"
920 }
0fdbd10b 921 file link -hard $anIncPath/$aHeaderFileName $aCasRoot/src/$anUnit/$aHeaderFileName
5951a088 922 } else {
0fdbd10b 923 file copy -force $aCasRoot/src/$anUnit/$aHeaderFileName $anIncPath/$aHeaderFileName
5951a088 924 }
910970ab 925 } elseif { $tcopy != $torig } {
0fdbd10b 926 puts "Warning: file $anIncPath/$aHeaderFileName is newer than $aCasRoot/src/$anUnit/$aHeaderFileName, not changed!"
910970ab 927 }
928 }
929 }
930 puts "Info: $nbcopied files updated"
931 }
5da3dfdf 932
933 # remove header files not listed in FILES
934 set anIncFiles [glob -tails -nocomplain -dir ${anIncPath} "*"]
935 foreach anIncFile ${anIncFiles} {
936 if { [lsearch -exact ${allHeaderFiles} ${anIncFile}] == -1 } {
937 puts "Warning: file ${anIncPath}/${anIncFile} is not presented in the sources and will be removed from ${theIncPath}!"
938 file delete -force "${theIncPath}/${anIncFile}"
939 }
940 }
910970ab 941}
942
943# Generate header for VS solution file
944proc osutils:vcsolution:header { vcversion } {
945 if { "$vcversion" == "vc7" } {
946 append var \
947 "Microsoft Visual Studio Solution File, Format Version 8.00\n"
948 } elseif { "$vcversion" == "vc8" } {
949 append var \
950 "Microsoft Visual Studio Solution File, Format Version 9.00\n" \
951 "# Visual Studio 2005\n"
952 } elseif { "$vcversion" == "vc9" } {
953 append var \
954 "Microsoft Visual Studio Solution File, Format Version 10.00\n" \
955 "# Visual Studio 2008\n"
956 } elseif { "$vcversion" == "vc10" } {
957 append var \
958 "Microsoft Visual Studio Solution File, Format Version 11.00\n" \
959 "# Visual Studio 2010\n"
960 } elseif { "$vcversion" == "vc11" } {
961 append var \
962 "Microsoft Visual Studio Solution File, Format Version 12.00\n" \
963 "# Visual Studio 2012\n"
964 } elseif { "$vcversion" == "vc12" } {
965 append var \
d6cda17a 966 "Microsoft Visual Studio Solution File, Format Version 12.00\n" \
910970ab 967 "# Visual Studio 2013\n"
d6cda17a 968 } elseif { "$vcversion" == "vc14" || "$vcversion" == "vc141"} {
39bff09c 969 append var \
970 "Microsoft Visual Studio Solution File, Format Version 12.00\n" \
971 "# Visual Studio 14\n"
910970ab 972 } else {
973 puts stderr "Error: Visual Studio version $vcversion is not supported by this function!"
974 }
975 return $var
976}
977# Returns extension (without dot) for project files of given version of VC
978
979proc osutils:vcproj:ext { vcversion } {
980 if { "$vcversion" == "vc7" || "$vcversion" == "vc8" || "$vcversion" == "vc9" } {
981 return "vcproj"
910970ab 982 } else {
39bff09c 983 return "vcxproj"
910970ab 984 }
985}
986# Generate start of configuration section of VS solution file
987
988proc osutils:vcsolution:config:begin { vcversion } {
989 if { "$vcversion" == "vc7" } {
990 append var \
991 "Global\n" \
992 "\tGlobalSection(SolutionConfiguration) = preSolution\n" \
993 "\t\tDebug = Debug\n" \
994 "\t\tRelease = Release\n" \
995 "\tEndGlobalSection\n" \
996 "\tGlobalSection(ProjectConfiguration) = postSolution\n"
39bff09c 997 } else {
910970ab 998 append var \
999 "Global\n" \
1000 "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n" \
1001 "\t\tDebug|Win32 = Debug|Win32\n" \
1002 "\t\tRelease|Win32 = Release|Win32\n" \
1003 "\t\tDebug|x64 = Debug|x64\n" \
1004 "\t\tRelease|x64 = Release|x64\n" \
1005 "\tEndGlobalSection\n" \
1006 "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n"
910970ab 1007 }
1008 return $var
1009}
1010# Generate part of configuration section of VS solution file describing one project
1011
1012proc osutils:vcsolution:config:project { vcversion guid } {
1013 if { "$vcversion" == "vc7" } {
1014 append var \
1015 "\t\t$guid.Debug.ActiveCfg = Debug|Win32\n" \
1016 "\t\t$guid.Debug.Build.0 = Debug|Win32\n" \
1017 "\t\t$guid.Release.ActiveCfg = Release|Win32\n" \
1018 "\t\t$guid.Release.Build.0 = Release|Win32\n"
39bff09c 1019 } else {
910970ab 1020 append var \
1021 "\t\t$guid.Debug|Win32.ActiveCfg = Debug|Win32\n" \
1022 "\t\t$guid.Debug|Win32.Build.0 = Debug|Win32\n" \
1023 "\t\t$guid.Release|Win32.ActiveCfg = Release|Win32\n" \
1024 "\t\t$guid.Release|Win32.Build.0 = Release|Win32\n" \
1025 "\t\t$guid.Debug|x64.ActiveCfg = Debug|x64\n" \
1026 "\t\t$guid.Debug|x64.Build.0 = Debug|x64\n" \
1027 "\t\t$guid.Release|x64.ActiveCfg = Release|x64\n" \
1028 "\t\t$guid.Release|x64.Build.0 = Release|x64\n"
910970ab 1029 }
1030 return $var
1031}
1032# Generate start of configuration section of VS solution file
1033
1034proc osutils:vcsolution:config:end { vcversion } {
1035 if { "$vcversion" == "vc7" } {
1036 append var \
1037 "\tEndGlobalSection\n" \
1038 "\tGlobalSection(ExtensibilityGlobals) = postSolution\n" \
1039 "\tEndGlobalSection\n" \
1040 "\tGlobalSection(ExtensibilityAddIns) = postSolution\n" \
1041 "\tEndGlobalSection\n"
39bff09c 1042 } else {
910970ab 1043 append var \
1044 "\tEndGlobalSection\n" \
1045 "\tGlobalSection(SolutionProperties) = preSolution\n" \
1046 "\t\tHideSolutionNode = FALSE\n" \
1047 "\tEndGlobalSection\n"
910970ab 1048 }
1049 return $var
1050}
1051# generate Visual Studio solution file
1052# if module is empty, generates one solution for all known modules
1053
1054proc OS:vcsolution { theVcVer theSolName theModules theOutDir theGuidsMap } {
1055 global path
1056 upvar $theGuidsMap aGuidsMap
1057
1058 # collect list of projects to be created
1059 set aProjects {}
1060 set aDependencies {}
1061 foreach aModule $theModules {
1062 # toolkits
1063 foreach aToolKit [osutils:tk:sort [${aModule}:toolkits]] {
1064 lappend aProjects $aToolKit
1065 lappend aProjectsInModule($aModule) $aToolKit
1066 lappend aDependencies [LibToLink $aToolKit]
1067 }
1068 # executables, assume one project per cxx file...
1069 foreach aUnit [OS:executable ${aModule}] {
1070 set aUnitLoc $aUnit
1071 set src_files [_get_used_files $aUnit false]
1072 set aSrcFiles {}
1073 foreach s $src_files {
1074 regexp {source ([^\s]+)} $s dummy name
1075 lappend aSrcFiles $name
1076 }
1077 foreach aSrcFile $aSrcFiles {
1078 set aFileExtension [file extension $aSrcFile]
1079 if { $aFileExtension == ".cxx" } {
1080 set aPrjName [file rootname $aSrcFile]
1081 lappend aProjects $aPrjName
1082 lappend aProjectsInModule($aModule) $aPrjName
1083 if {[file isdirectory $path/src/$aUnitLoc]} {
1084 lappend aDependencies [LibToLinkX $aUnitLoc [file rootname $aSrcFile]]
1085 } else {
1086 lappend aDependencies {}
1087 }
1088 }
1089 }
1090 }
1091 }
1092
1093# generate GUIDs for projects (unless already known)
1094 foreach aProject $aProjects {
1095 if { ! [info exists aGuidsMap($aProject)] } {
1096 set aGuidsMap($aProject) [OS:genGUID]
1097 }
1098 }
1099
1100 # generate solution file
1101# puts "Generating Visual Studio ($theVcVer) solution file for $theSolName ($aProjects)"
1102 append aFileBuff [osutils:vcsolution:header $theVcVer]
1103
1104 # GUID identifying group projects in Visual Studio
1105 set VC_GROUP_GUID "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"
1106
1107 # generate group projects -- one per module
1108 if { "$theVcVer" != "vc7" && [llength "$theModules"] > 1 } {
1109 foreach aModule $theModules {
1110 if { ! [info exists aGuidsMap(_$aModule)] } {
1111 set aGuidsMap(_$aModule) [OS:genGUID]
1112 }
1113 set aGuid $aGuidsMap(_$aModule)
1114 append aFileBuff "Project(\"${VC_GROUP_GUID}\") = \"$aModule\", \"$aModule\", \"$aGuid\"\nEndProject\n"
1115 }
1116 }
1117
1118 # extension of project files
1119 set aProjExt [osutils:vcproj:ext $theVcVer]
1120
1121 # GUID identifying C++ projects in Visual Studio
1122 set VC_CPP_GUID "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"
1123
1124 # generate normal projects
1125 set aProjsNb [llength $aProjects]
1126 for {set aProjId 0} {$aProjId < $aProjsNb} {incr aProjId} {
1127 set aProj [lindex $aProjects $aProjId]
1128 set aGuid $aGuidsMap($aProj)
1129 append aFileBuff "Project(\"${VC_CPP_GUID}\") = \"$aProj\", \"$aProj.${aProjExt}\", \"$aGuid\"\n"
1130 # write projects dependencies information (vc7 to vc9)
1131 set aDepGuids ""
1132 foreach aDepLib [lindex $aDependencies $aProjId] {
1133 if { $aDepLib != $aProj && [lsearch $aProjects $aDepLib] != "-1" } {
1134 set depGUID $aGuidsMap($aDepLib)
1135 append aDepGuids "\t\t$depGUID = $depGUID\n"
1136 }
1137 }
1138 if { "$aDepGuids" != "" } {
1139 append aFileBuff "\tProjectSection(ProjectDependencies) = postProject\n"
1140 append aFileBuff "$aDepGuids"
1141 append aFileBuff "\tEndProjectSection\n"
1142 }
1143 append aFileBuff "EndProject\n"
1144 }
1145
1146 # generate configuration section
1147 append aFileBuff [osutils:vcsolution:config:begin $theVcVer]
1148 foreach aProj $aProjects {
1149 append aFileBuff [osutils:vcsolution:config:project $theVcVer $aGuidsMap($aProj)]
1150 }
1151 append aFileBuff [osutils:vcsolution:config:end $theVcVer]
1152
1153 # write information of grouping of projects by module
1154 if { "$theVcVer" != "vc7" && [llength "$theModules"] > 1 } {
1155 append aFileBuff " GlobalSection(NestedProjects) = preSolution\n"
1156 foreach aModule $theModules {
1157 if { ! [info exists aProjectsInModule($aModule)] } { continue }
1158 foreach aProject $aProjectsInModule($aModule) {
1159 append aFileBuff " $aGuidsMap($aProject) = $aGuidsMap(_$aModule)\n"
1160 }
1161 }
1162 append aFileBuff " EndGlobalSection\n"
1163 }
1164
1165 # final word (footer)
1166 append aFileBuff "EndGlobal"
1167
1168 # write solution
1169 set aFile [open [set fdsw [file join $theOutDir ${theSolName}.sln]] w]
1170 fconfigure $aFile -translation crlf
1171 puts $aFile $aFileBuff
1172 close $aFile
1173 return [file join $theOutDir ${theSolName}.sln]
1174}
1175# Generate Visual Studio projects for specified version
1176
d6cda17a 1177proc OS:vcproj { theVcVer isUWP theModules theOutDir theGuidsMap } {
910970ab 1178 upvar $theGuidsMap aGuidsMap
1179
1180 set aProjectFiles {}
1181
1182 foreach aModule $theModules {
1183 foreach aToolKit [${aModule}:toolkits] {
d6cda17a 1184 lappend aProjectFiles [osutils:vcproj $theVcVer $isUWP $theOutDir $aToolKit aGuidsMap]
910970ab 1185 }
1186 foreach anExecutable [OS:executable ${aModule}] {
d6cda17a 1187 lappend aProjectFiles [osutils:vcprojx $theVcVer $isUWP $theOutDir $anExecutable aGuidsMap]
910970ab 1188 }
1189 }
1190 return $aProjectFiles
1191}
1192# generate template name and load it for given version of Visual Studio and platform
1193
d6cda17a 1194proc osutils:vcproj:readtemplate {theVcVer isUWP isExec} {
39bff09c 1195 set anExt $theVcVer
1196 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
1197 set anExt vc10
1198 }
1199
d6cda17a 1200 # determine versions of runtime and toolset
1201 set aVCRTVer $theVcVer
1202 set aToolset "v[string range $theVcVer 2 3]0"
1203 if { $theVcVer == "vc141" } {
1204 set aVCRTVer "vc14"
1205 set aToolset "v141"
1206 }
1207
39bff09c 1208 set what "$theVcVer"
39bff09c 1209 set aCmpl32 ""
1210 set aCmpl64 ""
ad03c234 1211 set aCharSet "Unicode"
d6cda17a 1212 if { $isExec } {
39bff09c 1213 set anExt "${anExt}x"
910970ab 1214 set what "$what executable"
1215 }
39bff09c 1216 if { "$theVcVer" == "vc10" } {
1217 # SSE2 is enabled by default in vc11+, but not in vc10 for 32-bit target
7fbac3c2 1218 set aCmpl32 "<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>"
39bff09c 1219 }
1220 set aTmpl [osutils:readtemplate $anExt "MS VC++ project ($what)"]
7fbac3c2 1221
d6cda17a 1222 if { $isUWP } {
7fbac3c2 1223 set UwpWinRt "<CompileAsWinRT>false</CompileAsWinRT>"
1224 foreach bitness {32 64} {
1225 set indent ""
1226 if {"[set aCmpl${bitness}]" != ""} {
1227 set indent "\n "
1228 }
1229 set aCmpl${bitness} "[set aCmpl${bitness}]${indent}${UwpWinRt}"
1230 }
7fbac3c2 1231 }
1232
26cfd29c 1233 set format_template "\[\\r\\n\\s\]*"
7fbac3c2 1234 foreach bitness {32 64} {
26cfd29c 1235 set format_templateloc ""
7fbac3c2 1236 if {"[set aCmpl${bitness}]" == ""} {
26cfd29c 1237 set format_templateloc "$format_template"
7fbac3c2 1238 }
26cfd29c 1239 regsub -all -- "${format_templateloc}__VCMPL${bitness}__" $aTmpl "[set aCmpl${bitness}]" aTmpl
1240 }
1241
1242 set aDebugInfo "no"
1243 set aReleaseLnk ""
1244 if { "$::HAVE_RelWithDebInfo" == "true" } {
1245 set aDebugInfo "true"
1246 set aReleaseLnk "\n <OptimizeReferences>true</OptimizeReferences>\n <EnableCOMDATFolding>true</EnableCOMDATFolding>"
7fbac3c2 1247 }
1248
d6cda17a 1249 regsub -all -- {__VCVER__} $aTmpl $aVCRTVer aTmpl
1250 regsub -all -- {__VCVEREXT__} $aTmpl $aToolset aTmpl
7fbac3c2 1251 regsub -all -- {__VCCHARSET__} $aTmpl $aCharSet aTmpl
26cfd29c 1252 regsub -all -- {__VCReleasePDB__} $aTmpl $aDebugInfo aTmpl
1253 regsub -all -- "${format_template}__VCLNKREL__" $aTmpl "${aReleaseLnk}" aTmpl
1254
39bff09c 1255 return $aTmpl
910970ab 1256}
1257
1258proc osutils:readtemplate {ext what} {
e31a8e52 1259 set loc "$::THE_CASROOT/adm/templates/template.$ext"
910970ab 1260 return [wokUtils:FILES:FileToString $loc]
1261}
1262# Read a file in a string as is.
1263
1264proc wokUtils:FILES:FileToString { fin } {
1265 if { [catch { set in [ open $fin r ] } errin] == 0 } {
1266 set strin [read $in [file size $fin]]
1267 close $in
1268 return $strin
1269 } else {
1270 return {}
1271 }
1272}
910970ab 1273
944d808c 1274# List extensions of compilable files in OCCT
1275proc osutils:compilable {thePlatform} {
cf4bee7c 1276 if { "$thePlatform" == "mac" || "$thePlatform" == "ios" } { return [list .c .cxx .cpp .mm] }
910970ab 1277 return [list .c .cxx .cpp]
1278}
1279
cf4bee7c 1280# List extensions of header file in OCCT
1281proc osutils:fileExtensionsHeaders {thePlatform} {
1282 if { "$thePlatform" == "mac" || "$thePlatform" == "ios" } { return [list .h .hxx .hpp .lxx .pxx .gxx ] }
1283 return [list .h .hxx .hpp .lxx .pxx .gxx .mm ]
1284}
1285
910970ab 1286proc osutils:commonUsedTK { theToolKit } {
910970ab 1287 set anUsedToolKits [list]
1288 set aDepToolkits [LibToLink $theToolKit]
1289 foreach tkx $aDepToolkits {
1290 if {[_get_type $tkx] == "t"} {
1291 lappend anUsedToolKits "${tkx}"
1292 }
1293 }
1294 return $anUsedToolKits
1295}
910970ab 1296
c7d774c5 1297# Return the list of name *CSF_ in a EXTERNLIB description of a toolkit
1298proc osutils:tk:csfInExternlib { EXTERNLIB } {
910970ab 1299 set l [wokUtils:FILES:FileToList $EXTERNLIB]
1300 set lret {STLPort}
1301 foreach str $l {
1302 if [regexp -- {(CSF_[^ ]*)} $str csf] {
1303 lappend lret $csf
1304 }
1305 }
1306 return $lret
1307}
1308
7c65581d 1309# Collect dependencies map depending on target OS (libraries for CSF_ codenames used in EXTERNLIB) .
1310# @param theOS - target OS
c7d774c5 1311# @param theCsfLibsMap - libraries map
1312# @param theCsfFrmsMap - frameworks map, OS X specific
1313proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap } {
1314 upvar $theCsfLibsMap aLibsMap
1315 upvar $theCsfFrmsMap aFrmsMap
910970ab 1316
c7d774c5 1317 unset theCsfLibsMap
1318 unset theCsfFrmsMap
910970ab 1319
7c65581d 1320 set aLibsMap(CSF_FREETYPE) "freetype"
1321 set aLibsMap(CSF_TclLibs) "tcl8.6"
1322 set aLibsMap(CSF_TclTkLibs) "tk8.6"
1323 if { "$::HAVE_FREEIMAGE" == "true" } {
1324 if { "$theOS" == "wnt" } {
60273f77 1325 set aLibsMap(CSF_FreeImagePlus) "FreeImage"
7c65581d 1326 } else {
1327 set aLibsMap(CSF_FreeImagePlus) "freeimage"
1328 }
a975e06e 1329 } elseif { "$theOS" == "wnt" } {
1330 set aLibsMap(CSF_FreeImagePlus) "windowscodecs"
7c65581d 1331 }
e22105a9 1332 if { "$::HAVE_FFMPEG" == "true" } {
1333 set aLibsMap(CSF_FFmpeg) "avcodec avformat swscale avutil"
1334 }
7c65581d 1335 if { "$::HAVE_TBB" == "true" } {
1336 set aLibsMap(CSF_TBB) "tbb tbbmalloc"
1337 }
1338 if { "$::HAVE_VTK" == "true" } {
1339 if { "$theOS" == "wnt" } {
1340 set aLibsMap(CSF_VTK) [osutils:vtkCsf "wnt"]
1341 } else {
1342 set aLibsMap(CSF_VTK) [osutils:vtkCsf "unix"]
1343 }
1344 }
e22105a9 1345 if { "$::HAVE_ZLIB" == "true" } {
1346 set aLibsMap(CSF_ZLIB) "zlib"
1347 }
1348 if { "$::HAVE_LIBLZMA" == "true" } {
1349 set aLibsMap(CSF_LIBLZMA) "liblzma"
1350 }
7c65581d 1351
910970ab 1352 if { "$theOS" == "wnt" } {
c7d774c5 1353 # WinAPI libraries
7c65581d 1354 set aLibsMap(CSF_kernel32) "kernel32"
1355 set aLibsMap(CSF_advapi32) "advapi32"
1356 set aLibsMap(CSF_gdi32) "gdi32"
1357 set aLibsMap(CSF_user32) "user32 comdlg32"
f4d20b00 1358 set aLibsMap(CSF_shell32) "shell32"
7c65581d 1359 set aLibsMap(CSF_opengl32) "opengl32"
1360 set aLibsMap(CSF_wsock32) "wsock32"
1361 set aLibsMap(CSF_netapi32) "netapi32"
98e6c6d1 1362 set aLibsMap(CSF_winmm) "winmm"
7c65581d 1363 set aLibsMap(CSF_OpenGlLibs) "opengl32"
1ce0716b 1364 if { "$::HAVE_GLES2" == "true" } {
1365 set aLibsMap(CSF_OpenGlLibs) "libEGL libGLESv2"
1366 }
7c65581d 1367 set aLibsMap(CSF_psapi) "Psapi"
1368 set aLibsMap(CSF_d3d9) "d3d9"
1369
1370 # the naming is different on Windows
1371 set aLibsMap(CSF_TclLibs) "tcl86"
1372 set aLibsMap(CSF_TclTkLibs) "tk86"
1373
1374 set aLibsMap(CSF_QT) "QtCore4 QtGui4"
1375
1376 # tbb headers define different pragma lib depending on debug/release
1377 set aLibsMap(CSF_TBB) ""
910970ab 1378 } else {
41f97958 1379 set aLibsMap(CSF_dl) "dl"
48ba1811 1380 if { "$theOS" == "mac" || "$theOS" == "ios" } {
c7d774c5 1381 set aLibsMap(CSF_objc) "objc"
48ba1811 1382 if { "$theOS" == "ios" } {
1383 set aFrmsMap(CSF_Appkit) "UIKit"
1384 set aFrmsMap(CSF_OpenGlLibs) "OpenGLES"
1385 } else {
1386 set aFrmsMap(CSF_Appkit) "AppKit"
1387 set aFrmsMap(CSF_OpenGlLibs) "OpenGL"
1388 }
c7d774c5 1389 set aFrmsMap(CSF_IOKit) "IOKit"
c7d774c5 1390 set aFrmsMap(CSF_TclLibs) "Tcl"
7c65581d 1391 set aLibsMap(CSF_TclLibs) ""
c7d774c5 1392 set aFrmsMap(CSF_TclTkLibs) "Tk"
7c65581d 1393 set aLibsMap(CSF_TclTkLibs) ""
14bbbdcb 1394 set aLibsMap(CSF_QT) "QtCore QtGui"
c7d774c5 1395 } else {
d8d01f6e 1396 if { "$theOS" == "qnx" } {
7c65581d 1397 # CSF_ThreadLibs - pthread API is part of libc on QNX
d8d01f6e 1398 set aLibsMap(CSF_OpenGlLibs) "EGL GLESv2"
d8d01f6e 1399 } else {
1400 set aLibsMap(CSF_ThreadLibs) "pthread rt"
1401 set aLibsMap(CSF_OpenGlLibs) "GL"
d8d01f6e 1402 set aLibsMap(CSF_TclTkLibs) "X11 tk8.6"
1403 set aLibsMap(CSF_XwLibs) "X11 Xext Xmu Xi"
1404 set aLibsMap(CSF_MotifLibs) "X11"
1405 }
1ce0716b 1406
1407 if { "$::HAVE_GLES2" == "true" } {
1408 set aLibsMap(CSF_OpenGlLibs) "EGL GLESv2"
1409 }
910970ab 1410 }
910970ab 1411 }
1412}
1413
1c29294e 1414# Returns string of library dependencies for generation of Visual Studio project or make lists.
1415proc osutils:vtkCsf {{theOS ""}} {
1416 set aVtkVer "6.1"
1417
1c29294e 1418 set aPathSplitter ":"
1c29294e 1419 if {"$theOS" == "wnt"} {
1420 set aPathSplitter ";"
1c29294e 1421 }
1422
1423 set anOptIncs [split $::env(CSF_OPT_INC) "$aPathSplitter"]
1424 foreach anIncItem $anOptIncs {
1425 if {[regexp -- "vtk-(.*)$" [file tail $anIncItem] dummy aFoundVtkVer]} {
1426 set aVtkVer $aFoundVtkVer
1427 }
1428 }
1429
1430 set aLibArray [list vtkCommonCore vtkCommonDataModel vtkCommonExecutionModel vtkCommonMath vtkCommonTransforms vtkRenderingCore \
1431 vtkRenderingOpenGL vtkFiltersGeneral vtkIOCore vtkIOImage vtkImagingCore vtkInteractionStyle]
1432
1433 # Additional suffices for the libraries
1434 set anIdx 0
1435 foreach anItem $aLibArray {
7c65581d 1436 lset aLibArray $anIdx $anItem-$aVtkVer
1c29294e 1437 incr anIdx
1438 }
1439
1440 return [join $aLibArray " "]
1441}
1442
c7d774c5 1443# @param theLibsList - dependencies (libraries list)
1444# @param theFrameworks - dependencies (frameworks list, OS X specific)
1445proc osutils:usedOsLibs { theToolKit theOS theLibsList theFrameworks } {
910970ab 1446 global path
c7d774c5 1447 upvar $theLibsList aLibsList
1448 upvar $theFrameworks aFrameworks
1449 set aLibsList [list]
1450 set aFrameworks [list]
910970ab 1451
c7d774c5 1452 osutils:csfList $theOS aLibsMap aFrmsMap
910970ab 1453
c7d774c5 1454 foreach aCsfElem [osutils:tk:csfInExternlib "$path/src/${theToolKit}/EXTERNLIB"] {
1455 if [info exists aLibsMap($aCsfElem)] {
1456 foreach aLib [split "$aLibsMap($aCsfElem)"] {
1457 if { [lsearch $aLibsList $aLib] == "-1" } {
1458 lappend aLibsList $aLib
1459 }
1460 }
910970ab 1461 }
c7d774c5 1462 if [info exists aFrmsMap($aCsfElem)] {
1463 foreach aFrm [split "$aFrmsMap($aCsfElem)"] {
1464 if { [lsearch $aFrameworks $aFrm] == "-1" } {
1465 lappend aFrameworks $aFrm
1466 }
910970ab 1467 }
1468 }
1469 }
910970ab 1470}
1471
1472# Returns liste of UD in a toolkit. tkloc is a full path wok.
1473proc osutils:tk:units { tkloc } {
1474 global path
1475 set l {}
1476 set PACKAGES "$path/src/$tkloc/PACKAGES"
1477 foreach u [wokUtils:FILES:FileToList $PACKAGES] {
1478 if {[file isdirectory "$path/src/$u"]} {
1479 lappend l $u
1480 }
1481 }
1482 if { $l == {} } {
1483 ;#puts stderr "Warning. No devunit included in $tkloc"
1484 }
1485 return $l
1486}
1487
1488proc osutils:justwnt { listloc } {
cf4bee7c 1489 set goaway [list Xw]
910970ab 1490 return [osutils:juststation $goaway $listloc]
1491}
1492
1493# remove from listloc OpenCascade units indesirables on NT
1494proc osutils:juststation {goaway listloc} {
1495 global path
1496 set lret {}
1497 foreach u $listloc {
1498 if {([file isdirectory "$path/src/$u"] && [lsearch $goaway $u] == -1 )
1499 || (![file isdirectory "$path/src/$u"] && [lsearch $goaway $u] == -1 ) } {
1500 lappend lret $u
1501 }
1502 }
1503 return $lret
1504}
1505
1506# intersect3 - perform the intersecting of two lists, returning a list containing three lists.
1507# The first list is everything in the first list that wasn't in the second,
1508# the second list contains the intersection of the two lists, the third list contains everything
1509# in the second list that wasn't in the first.
1510proc osutils:intersect3 {list1 list2} {
1511 set la1(0) {} ; unset la1(0)
1512 set lai(0) {} ; unset lai(0)
1513 set la2(0) {} ; unset la2(0)
1514 foreach v $list1 {
1515 set la1($v) {}
1516 }
1517 foreach v $list2 {
1518 set la2($v) {}
1519 }
1520 foreach elem [concat $list1 $list2] {
1521 if {[info exists la1($elem)] && [info exists la2($elem)]} {
1522 unset la1($elem)
1523 unset la2($elem)
1524 set lai($elem) {}
1525 }
1526 }
1527 list [lsort [array names la1]] [lsort [array names lai]] [lsort [array names la2]]
1528}
1529
1530# Prepare relative path
1531proc relativePath {thePathFrom thePathTo} {
1532 if { [file isdirectory "$thePathFrom"] == 0 } {
1533 return ""
1534 }
1535
1536 set aPathFrom [file normalize "$thePathFrom"]
1537 set aPathTo [file normalize "$thePathTo"]
1538
1539 set aCutedPathFrom "${aPathFrom}/dummy"
1540 set aRelatedDeepPath ""
1541
1542 while { "$aCutedPathFrom" != [file normalize "$aCutedPathFrom/.."] } {
1543 set aCutedPathFrom [file normalize "$aCutedPathFrom/.."]
1544 # does aPathTo contain aCutedPathFrom?
1545 regsub -all $aCutedPathFrom $aPathTo "" aPathFromAfterCut
1546 if { "$aPathFromAfterCut" != "$aPathTo" } { # if so
1547 if { "$aCutedPathFrom" == "$aPathFrom" } { # just go higher, for example, ./somefolder/someotherfolder
1548 set aPathTo ".${aPathTo}"
1549 } elseif { "$aCutedPathFrom" == "$aPathTo" } { # remove the last "/"
1550 set aRelatedDeepPath [string replace $aRelatedDeepPath end end ""]
1551 }
1552 regsub -all $aCutedPathFrom $aPathTo $aRelatedDeepPath aPathToAfterCut
1553 regsub -all "//" $aPathToAfterCut "/" aPathToAfterCut
1554 return $aPathToAfterCut
1555 }
1556 set aRelatedDeepPath "$aRelatedDeepPath../"
1557
1558 }
1559
1560 return $thePathTo
1561}
1562
1563proc wokUtils:EASY:bs1 { s } {
1564 regsub -all {/} $s {\\} r
1565 return $r
1566}
1567
1568# Returs for a full path the liste of n last directory part
1569# n = 1 => tail
1570# n = 2 => dir/file.c
1571# n = 3 => sdir/dir/file.c
1572# etc..
1573proc wokUtils:FILES:wtail { f n } {
1574 set ll [expr [llength [set lif [file split $f]]] -$n]
1575 return [join [lrange $lif $ll end] /]
1576}
1577
1578# Generate entry for one source file in Visual Studio 10 project file
cf4bee7c 1579proc osutils:vcxproj:cxxfile { theFile theParams } {
1580 if { $theParams == "" } {
1581 return " <ClCompile Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $theFile 3]]\" />\n"
910970ab 1582 }
1583
cf4bee7c 1584 set aParams [string trim ${theParams}]
1585 append text " <ClCompile Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $theFile 3]]\">\n"
1586 append text " <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Debug|Win32\'\">${aParams} %(AdditionalOptions)</AdditionalOptions>\n"
1587 append text " <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Release|Win32\'\">${aParams} %(AdditionalOptions)</AdditionalOptions>\n"
1588 append text " <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Debug|x64\'\">${aParams} %(AdditionalOptions)</AdditionalOptions>\n"
1589 append text " <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Release|x64\'\">${aParams} %(AdditionalOptions)</AdditionalOptions>\n"
910970ab 1590 append text " </ClCompile>\n"
1591 return $text
1592}
1593
cf4bee7c 1594# Generate entry for one header file in Visual Studio 10 project file
1595proc osutils:vcxproj:hxxfile { theFile } { return " <ClInclude Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $theFile 3]]\" />\n" }
1596
910970ab 1597# Generate Visual Studio 2010 project filters file
cf4bee7c 1598proc osutils:vcxproj:filters { dir proj theCxxFilesMap theHxxFilesMap } {
1599 upvar $theCxxFilesMap aCxxFilesMap
1600 upvar $theHxxFilesMap aHxxFilesMap
910970ab 1601
1602 # header
1603 append text "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1604 append text "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
1605
1606 # list of "filters" (units)
1607 append text " <ItemGroup>\n"
1608 append text " <Filter Include=\"Source files\">\n"
1609 append text " <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1610 append text " </Filter>\n"
cf4bee7c 1611 append text " <Filter Include=\"Header files\">\n"
1612 append text " <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1613 append text " </Filter>\n"
1614 foreach unit $aCxxFilesMap(units) {
910970ab 1615 append text " <Filter Include=\"Source files\\${unit}\">\n"
1616 append text " <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1617 append text " </Filter>\n"
1618 }
cf4bee7c 1619 foreach unit $aHxxFilesMap(units) {
1620 append text " <Filter Include=\"Header files\\${unit}\">\n"
1621 append text " <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1622 append text " </Filter>\n"
1623 }
910970ab 1624 append text " </ItemGroup>\n"
1625
cf4bee7c 1626 # list of cxx files
910970ab 1627 append text " <ItemGroup>\n"
cf4bee7c 1628 foreach unit $aCxxFilesMap(units) {
1629 foreach file $aCxxFilesMap($unit) {
910970ab 1630 append text " <ClCompile Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $file 3]]\">\n"
1631 append text " <Filter>Source files\\${unit}</Filter>\n"
1632 append text " </ClCompile>\n"
1633 }
1634 }
1635 append text " </ItemGroup>\n"
1636
cf4bee7c 1637 # list of hxx files
910970ab 1638 append text " <ItemGroup>\n"
cf4bee7c 1639 foreach unit $aHxxFilesMap(units) {
1640 foreach file $aHxxFilesMap($unit) {
1641 append text " <ClInclude Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $file 3]]\">\n"
1642 append text " <Filter>Header files\\${unit}</Filter>\n"
1643 append text " </ClInclude>\n"
910970ab 1644 }
1645 }
1646 append text " </ItemGroup>\n"
1647
1648 append text " <ItemGroup>\n"
cf4bee7c 1649 append text " <ResourceCompile Include=\"${proj}.rc\" />\n"
910970ab 1650 append text " </ItemGroup>\n"
1651
1652 # end
1653 append text "</Project>"
1654
1655 # write file
1656 set fp [open [set fvcproj [file join $dir ${proj}.vcxproj.filters]] w]
1657 fconfigure $fp -translation crlf
1658 puts $fp $text
1659 close $fp
1660
1661 return ${proj}.vcxproj.filters
1662}
1663
1664# Generate RC file content for ToolKit from template
1665proc osutils:readtemplate:rc {theOutDir theToolKit} {
e31a8e52 1666 set aLoc "$::THE_CASROOT/adm/templates/template_dll.rc"
910970ab 1667 set aBody [wokUtils:FILES:FileToString $aLoc]
1668 regsub -all -- {__TKNAM__} $aBody $theToolKit aBody
1669
1670 set aFile [open "${theOutDir}/${theToolKit}.rc" "w"]
1671 fconfigure $aFile -translation lf
1672 puts $aFile $aBody
1673 close $aFile
1674 return "${theOutDir}/${theToolKit}.rc"
1675}
1676
1677# Generate Visual Studio project file for ToolKit
d6cda17a 1678proc osutils:vcproj { theVcVer isUWP theOutDir theToolKit theGuidsMap } {
1679 set theProjTmpl [osutils:vcproj:readtemplate $theVcVer $isUWP 0]
910970ab 1680
944d808c 1681 set l_compilable [osutils:compilable wnt]
910970ab 1682 regsub -all -- {__TKNAM__} $theProjTmpl $theToolKit theProjTmpl
1683
1684 upvar $theGuidsMap aGuidsMap
1685 if { ! [info exists aGuidsMap($theToolKit)] } {
1686 set aGuidsMap($theToolKit) [OS:genGUID]
1687 }
1688 regsub -all -- {__PROJECT_GUID__} $theProjTmpl $aGuidsMap($theToolKit) theProjTmpl
1689
d6cda17a 1690 set theProjTmpl [osutils:uwp:proj $isUWP ${theProjTmpl}]
7fbac3c2 1691
7c65581d 1692 set aUsedLibs [list]
7fbac3c2 1693
d6cda17a 1694 if { $isUWP } {
7fbac3c2 1695 lappend aUsedLibs "WindowsApp.lib"
1696 }
1697
910970ab 1698 foreach tkx [osutils:commonUsedTK $theToolKit] {
7c65581d 1699 lappend aUsedLibs "${tkx}.lib"
910970ab 1700 }
1701
c7d774c5 1702 osutils:usedOsLibs $theToolKit "wnt" aLibs aFrameworks
7c65581d 1703 foreach aLibIter $aLibs {
1704 lappend aUsedLibs "${aLibIter}.lib"
1705 }
910970ab 1706
1707 # correct names of referred third-party libraries that are named with suffix
1708 # depending on VC version
d6cda17a 1709 set aVCRTVer [string range $theVcVer 0 3]
1710 regsub -all -- {vc[0-9]+} $aUsedLibs $aVCRTVer aUsedLibs
910970ab 1711
1712 # and put this list to project file
7c65581d 1713 #puts "$theToolKit requires $aUsedLibs"
39bff09c 1714 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
7c65581d 1715 set aUsedLibs [join $aUsedLibs {;}]
910970ab 1716 }
7c65581d 1717 regsub -all -- {__TKDEP__} $theProjTmpl $aUsedLibs theProjTmpl
910970ab 1718
1719 set anIncPaths "..\\..\\..\\inc"
68df8478 1720# set aTKDefines ""
910970ab 1721 set aFilesSection ""
cf4bee7c 1722 set aVcFilesCxx(units) ""
1723 set aVcFilesHxx(units) ""
910970ab 1724 set listloc [osutils:tk:units $theToolKit]
910970ab 1725 if [array exists written] { unset written }
1726 #puts "\t1 [wokparam -v %CMPLRS_CXX_Options [w_info -f]] father"
1727 #puts "\t2 [wokparam -v %CMPLRS_CXX_Options] branch"
1728 #puts "\t1 [wokparam -v %CMPLRS_C_Options [w_info -f]] father"
1729 #puts "\t2 [wokparam -v %CMPLRS_C_Options] branch"
1730 set fxloparamfcxx [lindex [osutils:intersect3 [_get_options wnt cmplrs_cxx f] [_get_options wnt cmplrs_cxx b]] 2]
1731 set fxloparamfc [lindex [osutils:intersect3 [_get_options wnt cmplrs_c f] [_get_options wnt cmplrs_c b]] 2]
1732 set fxloparam ""
cf4bee7c 1733 foreach fxlo $listloc {
910970ab 1734 set xlo $fxlo
cf4bee7c 1735 set aSrcFiles [osutils:tk:cxxfiles $xlo wnt]
1736 set aHxxFiles [osutils:tk:hxxfiles $xlo wnt]
910970ab 1737 set fxlo_cmplrs_options_cxx [_get_options wnt cmplrs_cxx $fxlo]
1738 if {$fxlo_cmplrs_options_cxx == ""} {
1739 set fxlo_cmplrs_options_cxx [_get_options wnt cmplrs_cxx b]
1740 }
1741 set fxlo_cmplrs_options_c [_get_options wnt cmplrs_c $fxlo]
1742 if {$fxlo_cmplrs_options_c == ""} {
1743 set fxlo_cmplrs_options_c [_get_options wnt cmplrs_c b]
1744 }
1745 set fxloparam "$fxloparam [lindex [osutils:intersect3 [_get_options wnt cmplrs_cxx b] $fxlo_cmplrs_options_cxx] 2]"
1746 set fxloparam "$fxloparam [lindex [osutils:intersect3 [_get_options wnt cmplrs_c b] $fxlo_cmplrs_options_c] 2]"
1747 #puts "\t3 [wokparam -v %CMPLRS_CXX_Options] branch CXX "
1748 #puts "\t4 [wokparam -v %CMPLRS_CXX_Options $fxlo] $fxlo CXX"
1749 #puts "\t5 [wokparam -v %CMPLRS_C_Options] branch C"
1750 #puts "\t6 [wokparam -v %CMPLRS_C_Options $fxlo] $fxlo C"
1751 set needparam ""
1752 foreach partopt $fxloparam {
1753 if {[string first "-I" $partopt] == "0"} {
1754 # this is an additional includes search path
1755 continue
1756 }
1757 set needparam "$needparam $partopt"
1758 }
1759
39bff09c 1760 # Format of projects in vc10+ is different from vc7-9
1761 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
910970ab 1762 foreach aSrcFile [lsort $aSrcFiles] {
1763 if { ![info exists written([file tail $aSrcFile])] } {
1764 set written([file tail $aSrcFile]) 1
cf4bee7c 1765 append aFilesSection [osutils:vcxproj:cxxfile $aSrcFile $needparam]
910970ab 1766 } else {
1767 puts "Warning : in vcproj more than one occurences for [file tail $aSrcFile]"
1768 }
cf4bee7c 1769 if { ! [info exists aVcFilesCxx($xlo)] } { lappend aVcFilesCxx(units) $xlo }
1770 lappend aVcFilesCxx($xlo) $aSrcFile
1771 }
1772 foreach aHxxFile [lsort $aHxxFiles] {
1773 if { ![info exists written([file tail $aHxxFile])] } {
1774 set written([file tail $aHxxFile]) 1
1775 append aFilesSection [osutils:vcxproj:hxxfile $aHxxFile]
1776 } else {
1777 puts "Warning : in vcproj more than one occurences for [file tail $aHxxFile]"
1778 }
1779 if { ! [info exists aVcFilesHxx($xlo)] } { lappend aVcFilesHxx(units) $xlo }
1780 lappend aVcFilesHxx($xlo) $aHxxFile
910970ab 1781 }
1782 } else {
1783 append aFilesSection "\t\t\t<Filter\n"
1784 append aFilesSection "\t\t\t\tName=\"${xlo}\"\n"
1785 append aFilesSection "\t\t\t\t>\n"
1786 foreach aSrcFile [lsort $aSrcFiles] {
1787 if { ![info exists written([file tail $aSrcFile])] } {
1788 set written([file tail $aSrcFile]) 1
1789 append aFilesSection [osutils:vcproj:file $theVcVer $aSrcFile $needparam]
1790 } else {
1791 puts "Warning : in vcproj more than one occurences for [file tail $aSrcFile]"
1792 }
1793 }
1794 append aFilesSection "\t\t\t</Filter>\n"
1795 }
910970ab 1796 }
1797
1798 regsub -all -- {__TKINC__} $theProjTmpl $anIncPaths theProjTmpl
910970ab 1799 regsub -all -- {__FILES__} $theProjTmpl $aFilesSection theProjTmpl
1800
1801 # write file
1802 set aFile [open [set aVcFiles [file join $theOutDir ${theToolKit}.[osutils:vcproj:ext $theVcVer]]] w]
1803 fconfigure $aFile -translation crlf
1804 puts $aFile $theProjTmpl
1805 close $aFile
1806
39bff09c 1807 # write filters file for vc10+
cf4bee7c 1808 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
1809 lappend aVcFiles [osutils:vcxproj:filters $theOutDir $theToolKit aVcFilesCxx aVcFilesHxx]
910970ab 1810 }
1811
1812 # write resource file
1813 lappend aVcFiles [osutils:readtemplate:rc $theOutDir $theToolKit]
1814
1815 return $aVcFiles
1816}
1817
1818# for a unit returns a map containing all its file in the current
1819# workbench
1820# local = 1 only local files
1821proc osutils:tk:loadunit { loc map } {
1822 #puts $loc
1823 upvar $map TLOC
1824 catch { unset TLOC }
1825 set lfiles [_get_used_files $loc]
1826 foreach f $lfiles {
1827 #puts "\t$f"
1828 set t [lindex $f 0]
1829 set p [lindex $f 2]
1830 if [info exists TLOC($t)] {
1831 set l $TLOC($t)
1832 lappend l $p
1833 set TLOC($t) $l
1834 } else {
1835 set TLOC($t) $p
1836 }
1837 }
1838 return
1839}
1840
cf4bee7c 1841# Returns the list of all files name in a toolkit within specified list of file extensions.
1842proc osutils:tk:files { tkloc theExtensions } {
910970ab 1843 set Tfiles(source,nocdlpack) {source pubinclude}
1844 set Tfiles(source,toolkit) {}
1845 set Tfiles(source,executable) {source pubinclude}
1846 set listloc [concat [osutils:tk:units $tkloc] $tkloc]
1847 #puts " listloc = $listloc"
944d808c 1848
944d808c 1849 set resultloc $listloc
910970ab 1850 set lret {}
1851 foreach loc $resultloc {
1852 set utyp [_get_type $loc]
1853 #puts "\"$utyp\" \"$loc\""
1854 switch $utyp {
1855 "t" { set utyp "toolkit" }
1856 "n" { set utyp "nocdlpack" }
1857 "x" { set utyp "executable" }
8c7fab9b 1858 default { error "Error: Cannot determine type of unit $loc, check adm/UDLIST!" }
910970ab 1859 }
1860 if [array exists map] { unset map }
1861 osutils:tk:loadunit $loc map
1862 #puts " loc = $loc === > [array names map]"
1863 set LType $Tfiles(source,${utyp})
1864 foreach typ [array names map] {
1865 if { [lsearch $LType $typ] == -1 } {
1866 unset map($typ)
1867 }
1868 }
1869 foreach type [array names map] {
1870 #puts $type
1871 foreach f $map($type) {
1872 #puts $f
cf4bee7c 1873 if { [lsearch $theExtensions [file extension $f]] != -1 } {
944d808c 1874 lappend lret $f
910970ab 1875 }
1876 }
1877 }
1878 }
1879 return $lret
1880}
1881
cf4bee7c 1882# Returns the list of all compilable files name in a toolkit.
1883proc osutils:tk:cxxfiles { tkloc thePlatform } { return [osutils:tk:files $tkloc [osutils:compilable $thePlatform]] }
1884
1885# Returns the list of all header files name in a toolkit.
1886proc osutils:tk:hxxfiles { tkloc thePlatform } { return [osutils:tk:files $tkloc [osutils:fileExtensionsHeaders $thePlatform]] }
1887
910970ab 1888# Generate Visual Studio project file for executable
d6cda17a 1889proc osutils:vcprojx { theVcVer isUWP theOutDir theToolKit theGuidsMap } {
910970ab 1890 set aVcFiles {}
cf4bee7c 1891 foreach f [osutils:tk:cxxfiles $theToolKit wnt] {
d6cda17a 1892 set aProjTmpl [osutils:vcproj:readtemplate $theVcVer $isUWP 1]
1893
910970ab 1894 set aProjName [file rootname [file tail $f]]
944d808c 1895 set l_compilable [osutils:compilable wnt]
910970ab 1896 regsub -all -- {__XQTNAM__} $aProjTmpl $aProjName aProjTmpl
1897
1898 upvar $theGuidsMap aGuidsMap
1899 if { ! [info exists aGuidsMap($aProjName)] } {
1900 set aGuidsMap($aProjName) [OS:genGUID]
1901 }
1902 regsub -all -- {__PROJECT_GUID__} $aProjTmpl $aGuidsMap($aProjName) aProjTmpl
1903
7c65581d 1904 set aUsedLibs [list]
910970ab 1905 foreach tkx [osutils:commonUsedTK $theToolKit] {
7c65581d 1906 lappend aUsedLibs "${tkx}.lib"
910970ab 1907 }
1908
c7d774c5 1909 osutils:usedOsLibs $theToolKit "wnt" aLibs aFrameworks
7c65581d 1910 foreach aLibIter $aLibs {
1911 lappend aUsedLibs "${aLibIter}.lib"
1912 }
910970ab 1913
1914 # correct names of referred third-party libraries that are named with suffix
1915 # depending on VC version
d6cda17a 1916 set aVCRTVer [string range $theVcVer 0 3]
1917 regsub -all -- {vc[0-9]+} $aUsedLibs $aVCRTVer aUsedLibs
910970ab 1918
7c65581d 1919# puts "$aProjName requires $aUsedLibs"
39bff09c 1920 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
7c65581d 1921 set aUsedLibs [join $aUsedLibs {;}]
910970ab 1922 }
7c65581d 1923 regsub -all -- {__TKDEP__} $aProjTmpl $aUsedLibs aProjTmpl
910970ab 1924
1925 set aFilesSection ""
cf4bee7c 1926 set aVcFilesCxx(units) ""
1927 set aVcFilesHxx(units) ""
910970ab 1928
1929 if { ![info exists written([file tail $f])] } {
1930 set written([file tail $f]) 1
1931
39bff09c 1932 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
cf4bee7c 1933 append aFilesSection [osutils:vcxproj:cxxfile $f ""]
1934 if { ! [info exists aVcFilesCxx($theToolKit)] } { lappend aVcFilesCxx(units) $theToolKit }
1935 lappend aVcFilesCxx($theToolKit) $f
910970ab 1936 } else {
1937 append aFilesSection "\t\t\t<Filter\n"
1938 append aFilesSection "\t\t\t\tName=\"$theToolKit\"\n"
1939 append aFilesSection "\t\t\t\t>\n"
1940 append aFilesSection [osutils:vcproj:file $theVcVer $f ""]
1941 append aFilesSection "\t\t\t</Filter>"
1942 }
1943 } else {
1944 puts "Warning : in vcproj there are than one occurences for [file tail $f]"
1945 }
1946 #puts "$aProjTmpl $aFilesSection"
910970ab 1947 set anIncPaths "..\\..\\..\\inc"
1948 regsub -all -- {__TKINC__} $aProjTmpl $anIncPaths aProjTmpl
910970ab 1949 regsub -all -- {__FILES__} $aProjTmpl $aFilesSection aProjTmpl
1c29294e 1950 regsub -all -- {__CONF__} $aProjTmpl Application aProjTmpl
1951
1952 regsub -all -- {__XQTEXT__} $aProjTmpl "exe" aProjTmpl
910970ab 1953
1954 set aFile [open [set aVcFilePath [file join $theOutDir ${aProjName}.[osutils:vcproj:ext $theVcVer]]] w]
1955 fconfigure $aFile -translation crlf
1956 puts $aFile $aProjTmpl
1957 close $aFile
1958
1959 set aCommonSettingsFile "$aVcFilePath.user"
1960 lappend aVcFiles $aVcFilePath
1961
1962 # write filters file for vc10
39bff09c 1963 if { "$theVcVer" != "vc7" && "$theVcVer" != "vc8" && "$theVcVer" != "vc9" } {
cf4bee7c 1964 lappend aVcFiles [osutils:vcxproj:filters $theOutDir $aProjName aVcFilesCxx aVcFilesHxx]
910970ab 1965 }
1966
cf4bee7c 1967 # write resource file
1968 lappend aVcFiles [osutils:readtemplate:rc $theOutDir $aProjName]
1969
910970ab 1970 set aCommonSettingsFileTmpl ""
39bff09c 1971 if { "$theVcVer" == "vc7" || "$theVcVer" == "vc8" } {
1972 # nothing
1973 } elseif { "$theVcVer" == "vc9" } {
e31a8e52 1974 set aCommonSettingsFileTmpl [wokUtils:FILES:FileToString "$::THE_CASROOT/adm/templates/vcproj.user.vc9x"]
39bff09c 1975 } else {
e31a8e52 1976 set aCommonSettingsFileTmpl [wokUtils:FILES:FileToString "$::THE_CASROOT/adm/templates/vcxproj.user.vc10x"]
910970ab 1977 }
1978 if { "$aCommonSettingsFileTmpl" != "" } {
d6cda17a 1979 regsub -all -- {__VCVER__} $aCommonSettingsFileTmpl $aVCRTVer aCommonSettingsFileTmpl
39bff09c 1980
1981 set aFile [open [set aVcFilePath "$aCommonSettingsFile"] w]
1982 fconfigure $aFile -translation crlf
1983 puts $aFile $aCommonSettingsFileTmpl
1984 close $aFile
1985
910970ab 1986 lappend aVcFiles "$aCommonSettingsFile"
1987 }
1988 }
1989 return $aVcFiles
1990}
1991
1992# Generate entry for one source file in Visual Studio 7 - 9 project file
1993proc osutils:vcproj:file { theVcVer theFile theOptions } {
1994 append aText "\t\t\t\t<File\n"
1995 append aText "\t\t\t\t\tRelativePath=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $theFile 3]]\">\n"
1996 if { $theOptions == "" } {
1997 append aText "\t\t\t\t</File>\n"
1998 return $aText
1999 }
2000
2001 append aText "\t\t\t\t\t<FileConfiguration\n"
2002 append aText "\t\t\t\t\t\tName=\"Release\|Win32\">\n"
2003 append aText "\t\t\t\t\t\t<Tool\n"
2004 append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
2005 append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
2006 foreach aParam $theOptions {
2007 append aText "$aParam "
2008 }
2009 append aText "\"\n"
2010 append aText "\t\t\t\t\t\t/>\n"
2011 append aText "\t\t\t\t\t</FileConfiguration>\n"
2012
2013 append aText "\t\t\t\t\t<FileConfiguration\n"
2014 append aText "\t\t\t\t\t\tName=\"Debug\|Win32\">\n"
2015 append aText "\t\t\t\t\t\t<Tool\n"
2016 append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
2017 append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
2018 foreach aParam $theOptions {
2019 append aText "$aParam "
2020 }
2021 append aText "\"\n"
2022 append aText "\t\t\t\t\t\t/>\n"
2023 append aText "\t\t\t\t\t</FileConfiguration>\n"
2024 if { "$theVcVer" == "vc7" } {
2025 append aText "\t\t\t\t</File>\n"
2026 return $aText
2027 }
2028
2029 append aText "\t\t\t\t\t<FileConfiguration\n"
2030 append aText "\t\t\t\t\t\tName=\"Release\|x64\">\n"
2031 append aText "\t\t\t\t\t\t<Tool\n"
2032 append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
2033 append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
2034 foreach aParam $theOptions {
2035 append aText "$aParam "
2036 }
2037 append aText "\"\n"
2038 append aText "\t\t\t\t\t\t/>\n"
2039 append aText "\t\t\t\t\t</FileConfiguration>\n"
2040
2041 append aText "\t\t\t\t\t<FileConfiguration\n"
2042 append aText "\t\t\t\t\t\tName=\"Debug\|x64\">\n"
2043 append aText "\t\t\t\t\t\t<Tool\n"
2044 append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
2045 append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
2046 foreach aParam $theOptions {
2047 append aText "$aParam "
2048 }
2049 append aText "\"\n"
2050 append aText "\t\t\t\t\t\t/>\n"
2051 append aText "\t\t\t\t\t</FileConfiguration>\n"
2052
2053 append aText "\t\t\t\t</File>\n"
2054 return $aText
2055}
2056
910970ab 2057proc wokUtils:FILES:mkdir { d } {
2058 global tcl_version
2059 regsub -all {\.[^.]*} $tcl_version "" major
2060 if { $major == 8 } {
2061 file mkdir $d
2062 } else {
2063 if ![file exists $d] {
2064 if { "[info command mkdir]" == "mkdir" } {
2065 mkdir -path $d
2066 } else {
2067 puts stderr "wokUtils:FILES:mkdir : Error unable to find a mkdir command."
2068 }
2069 }
2070 }
2071 if [file exists $d] {
2072 return $d
2073 } else {
2074 return {}
2075 }
2076}
2077
910970ab 2078# remove from listloc OpenCascade units indesirables on Unix
2079proc osutils:justunix { listloc } {
c7d774c5 2080 if { "$::tcl_platform(os)" == "Darwin" } {
910970ab 2081 set goaway [list Xw WNT]
2082 } else {
2083 set goaway [list WNT]
2084 }
2085 return [osutils:juststation $goaway $listloc]
2086}
2087
910970ab 2088
2089####### CODEBLOCK ###################################################################
2090# Function to generate Code Blocks workspace and project files
944d808c 2091proc OS:MKCBP { theOutDir theModules theAllSolution thePlatform theCmpl } {
910970ab 2092 puts stderr "Generating project files for Code Blocks"
2093
2094 # Generate projects for toolkits and separate workspace for each module
2095 foreach aModule $theModules {
7c65581d 2096 OS:cworkspace $aModule $aModule $theOutDir
944d808c 2097 OS:cbp $theCmpl $aModule $theOutDir $thePlatform
910970ab 2098 }
2099
2100 # Generate single workspace "OCCT" containing projects from all modules
2101 if { "$theAllSolution" != "" } {
2102 OS:cworkspace $theAllSolution $theModules $theOutDir
2103 }
2104
2105 puts "The Code Blocks workspace and project files are stored in the $theOutDir directory"
2106}
2107
2108# Generate Code Blocks projects
944d808c 2109proc OS:cbp { theCmpl theModules theOutDir thePlatform } {
910970ab 2110 set aProjectFiles {}
2111 foreach aModule $theModules {
2112 foreach aToolKit [${aModule}:toolkits] {
944d808c 2113 lappend aProjectFiles [osutils:cbptk $theCmpl $theOutDir $aToolKit $thePlatform]
910970ab 2114 }
2115 foreach anExecutable [OS:executable ${aModule}] {
944d808c 2116 lappend aProjectFiles [osutils:cbpx $theCmpl $theOutDir $anExecutable $thePlatform]
910970ab 2117 }
2118 }
2119 return $aProjectFiles
2120}
2121
2122# Generate Code::Blocks project file for ToolKit
944d808c 2123proc osutils:cbptk { theCmpl theOutDir theToolKit thePlatform} {
7c65581d 2124 set aUsedLibs [list]
910970ab 2125 set aFrameworks [list]
2126 set anIncPaths [list]
2127 set aTKDefines [list]
2128 set aTKSrcFiles [list]
2129
7c65581d 2130 # collect list of referred libraries to link with
944d808c 2131 osutils:usedOsLibs $theToolKit $thePlatform aUsedLibs aFrameworks
7c65581d 2132 set aDepToolkits [wokUtils:LIST:Purge [osutils:tk:close $theToolKit]]
2133 foreach tkx $aDepToolkits {
2134 lappend aUsedLibs "${tkx}"
2135 }
2136
2137 lappend anIncPaths "../../../inc"
2138 set listloc [osutils:tk:units $theToolKit]
2139
2140 if { [llength $listloc] == 0 } {
2141 set listloc $theToolKit
2142 }
2143
d6cda17a 2144 if { $thePlatform == "wnt" || $thePlatform == "uwp" } {
7c65581d 2145 set resultloc [osutils:justwnt $listloc]
2146 } else {
2147 set resultloc [osutils:justunix $listloc]
2148 }
2149 if [array exists written] { unset written }
2150 foreach fxlo $resultloc {
2151 set xlo $fxlo
cf4bee7c 2152 set aSrcFiles [osutils:tk:cxxfiles $xlo $thePlatform]
7c65581d 2153 foreach aSrcFile [lsort $aSrcFiles] {
2154 if { ![info exists written([file tail $aSrcFile])] } {
2155 set written([file tail $aSrcFile]) 1
2156 lappend aTKSrcFiles "../../../[wokUtils:FILES:wtail $aSrcFile 3]"
2157 } else {
2158 puts "Warning : more than one occurences for [file tail $aSrcFile]"
2159 }
2160 }
2161
2162 # macros for correct DLL exports
68df8478 2163# if { $thePlatform == "wnt" || $thePlatform == "uwp" } {
2164# lappend aTKDefines "__${xlo}_DLL"
2165# }
7c65581d 2166 }
910970ab 2167
944d808c 2168 return [osutils:cbp $theCmpl $theOutDir $theToolKit $thePlatform $aTKSrcFiles $aUsedLibs $aFrameworks $anIncPaths $aTKDefines]
910970ab 2169}
2170
2171# Generates Code Blocks workspace.
2172proc OS:cworkspace { theSolName theModules theOutDir } {
2173 global path
2174 set aWsFilePath "${theOutDir}/${theSolName}.workspace"
2175 set aFile [open $aWsFilePath "w"]
2176 set isActiveSet 0
2177 puts $aFile "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
2178 puts $aFile "<CodeBlocks_workspace_file>"
2179 puts $aFile "\t<Workspace title=\"${theSolName}\">"
2180
2181 # collect list of projects to be created
2182 foreach aModule $theModules {
2183 # toolkits
2184 foreach aToolKit [osutils:tk:sort [${aModule}:toolkits]] {
2185 set aDependencies [LibToLink $aToolKit]
2186 if { [llength $aDependencies] == 0 } {
2187 puts $aFile "\t\t<Project filename=\"${aToolKit}.cbp\" />"
2188 } else {
2189 puts $aFile "\t\t<Project filename=\"${aToolKit}.cbp\" >"
2190 foreach aDepTk $aDependencies {
2191 puts $aFile "\t\t\t<Depends filename=\"${aDepTk}.cbp\" />"
2192 }
2193 puts $aFile "\t\t</Project>"
2194 }
2195 }
2196
2197 # executables, assume one project per cxx file...
2198 foreach aUnit [OS:executable ${aModule}] {
2199 set aUnitLoc $aUnit
2200 set src_files [_get_used_files $aUnit false]
2201 set aSrcFiles {}
2202 foreach s $src_files {
2203 regexp {source ([^\s]+)} $s dummy name
2204 lappend aSrcFiles $name
2205 }
2206 foreach aSrcFile $aSrcFiles {
2207 set aFileExtension [file extension $aSrcFile]
2208 if { $aFileExtension == ".cxx" } {
2209 set aPrjName [file rootname $aSrcFile]
2210 set aDependencies [list]
2211 if {[file isdirectory $path/src/$aUnitLoc]} {
2212 set aDependencies [LibToLinkX $aUnitLoc [file rootname $aSrcFile]]
2213 }
2214 set anActiveState ""
2215 if { $isActiveSet == 0 } {
2216 set anActiveState " active=\"1\""
2217 set isActiveSet 1
2218 }
2219 if { [llength $aDependencies] == 0 } {
2220 puts $aFile "\t\t<Project filename=\"${aPrjName}.cbp\"${anActiveState}/>"
2221 } else {
2222 puts $aFile "\t\t<Project filename=\"${aPrjName}.cbp\"${anActiveState}>"
2223 foreach aDepTk $aDependencies {
2224 puts $aFile "\t\t\t<Depends filename=\"${aDepTk}.cbp\" />"
2225 }
2226 puts $aFile "\t\t</Project>"
2227 }
2228 }
2229 }
2230 }
2231 }
2232
2233 puts $aFile "\t</Workspace>"
2234 puts $aFile "</CodeBlocks_workspace_file>"
2235 close $aFile
2236
2237 return $aWsFilePath
2238}
2239
2240# Generate Code::Blocks project file for Executable
944d808c 2241proc osutils:cbpx { theCmpl theOutDir theToolKit thePlatform } {
2242 global path
910970ab 2243 set aWokArch "$::env(ARCH)"
2244
2245 set aCbpFiles {}
cf4bee7c 2246 foreach aSrcFile [osutils:tk:cxxfiles $theToolKit $thePlatform] {
910970ab 2247 # collect list of referred libraries to link with
7c65581d 2248 set aUsedLibs [list]
910970ab 2249 set aFrameworks [list]
2250 set anIncPaths [list]
2251 set aTKDefines [list]
2252 set aTKSrcFiles [list]
2253 set aProjName [file rootname [file tail $aSrcFile]]
2254
944d808c 2255 osutils:usedOsLibs $theToolKit $thePlatform aUsedLibs aFrameworks
7c65581d 2256
910970ab 2257 set aDepToolkits [LibToLinkX $theToolKit $aProjName]
2258 foreach tkx $aDepToolkits {
2259 if {[_get_type $tkx] == "t"} {
7c65581d 2260 lappend aUsedLibs "${tkx}"
910970ab 2261 }
2262 if {[lsearch [glob -tails -directory "$path/src" -types d *] $tkx] == "-1"} {
7c65581d 2263 lappend aUsedLibs "${tkx}"
910970ab 2264 }
2265 }
2266
910970ab 2267 set WOKSteps_exec_link [_get_options lin WOKSteps_exec_link $theToolKit]
2268 if { [regexp {WOKStep_DLLink} $WOKSteps_exec_link] || [regexp {WOKStep_Libink} $WOKSteps_exec_link] } {
2269 set isExecutable "false"
2270 } else {
2271 set isExecutable "true"
2272 }
2273
2274 if { ![info exists written([file tail $aSrcFile])] } {
2275 set written([file tail $aSrcFile]) 1
7c65581d 2276 lappend aTKSrcFiles "../../../[wokUtils:FILES:wtail $aSrcFile 3]"
910970ab 2277 } else {
2278 puts "Warning : in cbp there are more than one occurences for [file tail $aSrcFile]"
2279 }
2280
2281 # macros for correct DLL exports
68df8478 2282# if { $thePlatform == "wnt" || $thePlatform == "uwp" } {
2283# lappend aTKDefines "__${theToolKit}_DLL"
2284# }
910970ab 2285
2286 # common include paths
2287 lappend anIncPaths "../../../inc"
2288
944d808c 2289 lappend aCbpFiles [osutils:cbp $theCmpl $theOutDir $aProjName $thePlatform $aTKSrcFiles $aUsedLibs $aFrameworks $anIncPaths $aTKDefines $isExecutable]
910970ab 2290 }
2291
2292 return $aCbpFiles
2293}
2294
910970ab 2295# This function intended to generate Code::Blocks project file
7c65581d 2296# @param theCmpl - the compiler (gcc or msvc)
910970ab 2297# @param theOutDir - output directory to place project file
2298# @param theProjName - project name
2299# @param theSrcFiles - list of source files
2300# @param theLibsList - dependencies (libraries list)
2301# @param theFrameworks - dependencies (frameworks list, Mac OS X specific)
2302# @param theIncPaths - header search paths
2303# @param theDefines - compiler macro definitions
2304# @param theIsExe - flag to indicate executable / library target
944d808c 2305proc osutils:cbp { theCmpl theOutDir theProjName thePlatform theSrcFiles theLibsList theFrameworks theIncPaths theDefines {theIsExe "false"} } {
910970ab 2306 set aWokArch "$::env(ARCH)"
2307
7c65581d 2308 set aCmplCbp "gcc"
2309 set aCmplFlags [list]
2310 set aCmplFlagsRelease [list]
2311 set aCmplFlagsDebug [list]
2312 set toPassArgsByFile 0
2313 set aLibPrefix "lib"
aafe169f 2314 set aPlatformAndCompiler "${thePlatform}/gcc"
2315 if { "$thePlatform" == "mac" || "$thePlatform" == "ios" } {
2316 set aPlatformAndCompiler "${thePlatform}/clang"
2317 }
d6cda17a 2318 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" || "$thePlatform" == "qnx" } {
7c65581d 2319 set toPassArgsByFile 1
2320 }
2321 if { "$theCmpl" == "msvc" } {
2322 set aCmplCbp "msvc8"
2323 set aLibPrefix ""
2324 }
2325
2326 if { "$theCmpl" == "msvc" } {
2327 set aCmplFlags "-arch:SSE2 -EHsc -W4 -MP"
2328 set aCmplFlagsRelease "-MD -O2"
2329 set aCmplFlagsDebug "-MDd -Od -Zi"
2330 lappend aCmplFlags "-D_CRT_SECURE_NO_WARNINGS"
2331 lappend aCmplFlags "-D_CRT_NONSTDC_NO_DEPRECATE"
2332 } elseif { "$theCmpl" == "gcc" } {
d6cda17a 2333 if { "$thePlatform" != "qnx" } {
7c65581d 2334 set aCmplFlags "-mmmx -msse -msse2 -mfpmath=sse"
2335 }
2336 set aCmplFlagsRelease "-O2"
2337 set aCmplFlagsDebug "-O0 -g"
d6cda17a 2338 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" } {
7c65581d 2339 lappend aCmplFlags "-std=gnu++0x"
2340 lappend aCmplFlags "-D_WIN32_WINNT=0x0501"
2341 } else {
2342 lappend aCmplFlags "-std=c++0x"
2343 lappend aCmplFlags "-fPIC"
2344 lappend aCmplFlags "-DOCC_CONVERT_SIGNALS"
2345 }
2346 lappend aCmplFlags "-Wall"
2347 lappend aCmplFlags "-fexceptions"
2348 }
2349 lappend aCmplFlagsRelease "-DNDEBUG"
2350 lappend aCmplFlagsRelease "-DNo_Exception"
2351 lappend aCmplFlagsDebug "-D_DEBUG"
d6cda17a 2352 if { "$thePlatform" == "qnx" } {
7c65581d 2353 lappend aCmplFlags "-D_QNX_SOURCE"
2354 }
2355
2356 set aCbpFilePath "${theOutDir}/${theProjName}.cbp"
2357 set aLnkFileName "${theProjName}_obj.link"
2358 set aLnkDebFileName "${theProjName}_objd.link"
2359 set aLnkFilePath "${theOutDir}/${aLnkFileName}"
2360 set aLnkDebFilePath "${theOutDir}/${aLnkDebFileName}"
910970ab 2361 set aFile [open $aCbpFilePath "w"]
2362 puts $aFile "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
2363 puts $aFile "<CodeBlocks_project_file>"
2364 puts $aFile "\t<FileVersion major=\"1\" minor=\"6\" />"
2365 puts $aFile "\t<Project>"
2366 puts $aFile "\t\t<Option title=\"$theProjName\" />"
2367 puts $aFile "\t\t<Option pch_mode=\"2\" />"
7c65581d 2368 puts $aFile "\t\t<Option compiler=\"$aCmplCbp\" />"
910970ab 2369 puts $aFile "\t\t<Build>"
2370
2371 # Release target configuration
2372 puts $aFile "\t\t\t<Target title=\"Release\">"
2373 if { "$theIsExe" == "true" } {
aafe169f 2374 puts $aFile "\t\t\t\t<Option output=\"../../../${aPlatformAndCompiler}/bin/${theProjName}\" prefix_auto=\"0\" extension_auto=\"0\" />"
910970ab 2375 puts $aFile "\t\t\t\t<Option type=\"1\" />"
2376 } else {
d6cda17a 2377 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" } {
aafe169f 2378 puts $aFile "\t\t\t\t<Option output=\"../../../${aPlatformAndCompiler}/bin/${aLibPrefix}${theProjName}\" imp_lib=\"../../../${aPlatformAndCompiler}/lib/\$(TARGET_OUTPUT_BASENAME)\" prefix_auto=\"1\" extension_auto=\"1\" />"
910970ab 2379 } else {
aafe169f 2380 puts $aFile "\t\t\t\t<Option output=\"../../../${aPlatformAndCompiler}/lib/lib${theProjName}.so\" prefix_auto=\"0\" extension_auto=\"0\" />"
910970ab 2381 }
2382 puts $aFile "\t\t\t\t<Option type=\"3\" />"
2383 }
aafe169f 2384 puts $aFile "\t\t\t\t<Option object_output=\"../../../${aPlatformAndCompiler}/obj\" />"
7c65581d 2385 puts $aFile "\t\t\t\t<Option compiler=\"$aCmplCbp\" />"
2386 puts $aFile "\t\t\t\t<Option createDefFile=\"0\" />"
d6cda17a 2387 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" } {
7c65581d 2388 puts $aFile "\t\t\t\t<Option createStaticLib=\"1\" />"
910970ab 2389 } else {
7c65581d 2390 puts $aFile "\t\t\t\t<Option createStaticLib=\"0\" />"
910970ab 2391 }
910970ab 2392
2393 # compiler options per TARGET (including defines)
2394 puts $aFile "\t\t\t\t<Compiler>"
7c65581d 2395 foreach aFlagIter $aCmplFlagsRelease {
2396 puts $aFile "\t\t\t\t\t<Add option=\"$aFlagIter\" />"
910970ab 2397 }
2398 foreach aMacro $theDefines {
2399 puts $aFile "\t\t\t\t\t<Add option=\"-D${aMacro}\" />"
2400 }
910970ab 2401 puts $aFile "\t\t\t\t</Compiler>"
2402
2403 puts $aFile "\t\t\t\t<Linker>"
7c65581d 2404 if { $toPassArgsByFile == 1 } {
2405 puts $aFile "\t\t\t\t\t<Add option=\"\@$aLnkFileName\" />"
2406 }
aafe169f 2407 puts $aFile "\t\t\t\t\t<Add directory=\"../../../${aPlatformAndCompiler}/lib\" />"
d6cda17a 2408 if { "$thePlatform" == "mac" } {
7c65581d 2409 if { [ lsearch $theLibsList X11 ] >= 0} {
2410 puts $aFile "\t\t\t\t\t<Add directory=\"/usr/X11/lib\" />"
2411 }
910970ab 2412 }
2413 puts $aFile "\t\t\t\t\t<Add option=\"\$(CSF_OPT_LNK${aWokArch})\" />"
d6cda17a 2414 if { "$thePlatform" == "lin" } {
aafe169f 2415 puts $aFile "\t\t\t\t\t<Add option=\"-Wl,-rpath-link=../../../${aPlatformAndCompiler}/lib\" />"
55fb31da 2416 }
910970ab 2417 puts $aFile "\t\t\t\t</Linker>"
2418
2419 puts $aFile "\t\t\t</Target>"
2420
2421 # Debug target configuration
2422 puts $aFile "\t\t\t<Target title=\"Debug\">"
2423 if { "$theIsExe" == "true" } {
aafe169f 2424 puts $aFile "\t\t\t\t<Option output=\"../../../${aPlatformAndCompiler}/bind/${theProjName}\" prefix_auto=\"0\" extension_auto=\"0\" />"
910970ab 2425 puts $aFile "\t\t\t\t<Option type=\"1\" />"
2426 } else {
d6cda17a 2427 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" } {
aafe169f 2428 puts $aFile "\t\t\t\t<Option output=\"../../../${aPlatformAndCompiler}/bind/${aLibPrefix}${theProjName}\" imp_lib=\"../../../${aPlatformAndCompiler}/libd/\$(TARGET_OUTPUT_BASENAME)\" prefix_auto=\"1\" extension_auto=\"1\" />"
910970ab 2429 } else {
aafe169f 2430 puts $aFile "\t\t\t\t<Option output=\"../../../${aPlatformAndCompiler}/libd/lib${theProjName}.so\" prefix_auto=\"0\" extension_auto=\"0\" />"
910970ab 2431 }
2432 puts $aFile "\t\t\t\t<Option type=\"3\" />"
2433 }
aafe169f 2434 puts $aFile "\t\t\t\t<Option object_output=\"../../../${aPlatformAndCompiler}/objd\" />"
7c65581d 2435 puts $aFile "\t\t\t\t<Option compiler=\"$aCmplCbp\" />"
2436 puts $aFile "\t\t\t\t<Option createDefFile=\"0\" />"
d6cda17a 2437 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" } {
7c65581d 2438 puts $aFile "\t\t\t\t<Option createStaticLib=\"1\" />"
910970ab 2439 } else {
7c65581d 2440 puts $aFile "\t\t\t\t<Option createStaticLib=\"0\" />"
910970ab 2441 }
910970ab 2442
2443 # compiler options per TARGET (including defines)
2444 puts $aFile "\t\t\t\t<Compiler>"
7c65581d 2445 foreach aFlagIter $aCmplFlagsDebug {
2446 puts $aFile "\t\t\t\t\t<Add option=\"$aFlagIter\" />"
910970ab 2447 }
2448 foreach aMacro $theDefines {
2449 puts $aFile "\t\t\t\t\t<Add option=\"-D${aMacro}\" />"
2450 }
910970ab 2451 puts $aFile "\t\t\t\t</Compiler>"
2452
2453 puts $aFile "\t\t\t\t<Linker>"
7c65581d 2454 if { $toPassArgsByFile == 1 } {
2455 puts $aFile "\t\t\t\t\t<Add option=\"\@$aLnkDebFileName\" />"
2456 }
aafe169f 2457 puts $aFile "\t\t\t\t\t<Add directory=\"../../../${aPlatformAndCompiler}/libd\" />"
d6cda17a 2458 if { "$thePlatform" == "mac" } {
7c65581d 2459 if { [ lsearch $theLibsList X11 ] >= 0} {
2460 puts $aFile "\t\t\t\t\t<Add directory=\"/usr/X11/lib\" />"
2461 }
910970ab 2462 }
2463 puts $aFile "\t\t\t\t\t<Add option=\"\$(CSF_OPT_LNK${aWokArch}D)\" />"
d6cda17a 2464 if { "$thePlatform" == "lin" } {
aafe169f 2465 puts $aFile "\t\t\t\t\t<Add option=\"-Wl,-rpath-link=../../../${aPlatformAndCompiler}/libd\" />"
55fb31da 2466 }
910970ab 2467 puts $aFile "\t\t\t\t</Linker>"
2468
2469 puts $aFile "\t\t\t</Target>"
2470
2471 puts $aFile "\t\t</Build>"
2472
2473 # COMMON compiler options
2474 puts $aFile "\t\t<Compiler>"
7c65581d 2475 foreach aFlagIter $aCmplFlags {
2476 puts $aFile "\t\t\t<Add option=\"$aFlagIter\" />"
2477 }
910970ab 2478 puts $aFile "\t\t\t<Add option=\"\$(CSF_OPT_CMPL)\" />"
2479 foreach anIncPath $theIncPaths {
2480 puts $aFile "\t\t\t<Add directory=\"$anIncPath\" />"
2481 }
2482 puts $aFile "\t\t</Compiler>"
2483
2484 # COMMON linker options
2485 puts $aFile "\t\t<Linker>"
d6cda17a 2486 if { "$thePlatform" == "wnt" && "$theCmpl" == "gcc" } {
7c65581d 2487 puts $aFile "\t\t\t<Add option=\"-Wl,--export-all-symbols\" />"
2488 }
910970ab 2489 foreach aFrameworkName $theFrameworks {
2490 if { "$aFrameworkName" != "" } {
2491 puts $aFile "\t\t\t<Add option=\"-framework $aFrameworkName\" />"
2492 }
2493 }
2494 foreach aLibName $theLibsList {
2495 if { "$aLibName" != "" } {
7c65581d 2496 if { "$theCmpl" == "msvc" } {
2497 puts $aFile "\t\t\t<Add library=\"${aLibName}.lib\" />"
2498 } else {
2499 puts $aFile "\t\t\t<Add library=\"${aLibName}\" />"
2500 }
910970ab 2501 }
2502 }
2503 puts $aFile "\t\t</Linker>"
2504
2505 # list of sources
7c65581d 2506
2507 set aFileLnkObj ""
2508 set aFileLnkObjd ""
2509 set isFirstSrcFile 1
2510 if { $toPassArgsByFile == 1 } {
2511 set aFileLnkObj [open $aLnkFilePath "w"]
2512 set aFileLnkObjd [open $aLnkDebFilePath "w"]
2513 }
2514
910970ab 2515 foreach aSrcFile $theSrcFiles {
2516 if {[string equal -nocase [file extension $aSrcFile] ".mm"]} {
2517 puts $aFile "\t\t<Unit filename=\"$aSrcFile\">"
2518 puts $aFile "\t\t\t<Option compile=\"1\" />"
2519 puts $aFile "\t\t\t<Option link=\"1\" />"
2520 puts $aFile "\t\t</Unit>"
2521 } elseif {[string equal -nocase [file extension $aSrcFile] ".c"]} {
2522 puts $aFile "\t\t<Unit filename=\"$aSrcFile\">"
2523 puts $aFile "\t\t\t<Option compilerVar=\"CC\" />"
2524 puts $aFile "\t\t</Unit>"
7c65581d 2525 } elseif { $toPassArgsByFile == 1 && $isFirstSrcFile == 0 && [string equal -nocase [file extension $aSrcFile] ".cxx" ] } {
2526 # pass at list single source file to Code::Blocks as is
2527 # and pack the list of other files into the dedicated file to workaround process arguments limits on systems like Windows
2528 puts $aFile "\t\t<Unit filename=\"$aSrcFile\">"
2529 puts $aFile "\t\t\t<Option link=\"0\" />"
2530 puts $aFile "\t\t</Unit>"
2531
aafe169f 2532 set aFileObj [string map {.cxx .o} [string map [list "/src/" "/${aPlatformAndCompiler}/obj/src/"] $aSrcFile]]
2533 set aFileObjd [string map {.cxx .o} [string map [list "/src/" "/${aPlatformAndCompiler}/objd/src/"] $aSrcFile]]
7c65581d 2534 puts -nonewline $aFileLnkObj "$aFileObj "
2535 puts -nonewline $aFileLnkObjd "$aFileObjd "
910970ab 2536 } else {
2537 puts $aFile "\t\t<Unit filename=\"$aSrcFile\" />"
7c65581d 2538 set isFirstSrcFile 0
910970ab 2539 }
2540 }
2541
d6cda17a 2542 if { "$thePlatform" == "wnt" || "$thePlatform" == "uwp" } {
7c65581d 2543 close $aFileLnkObj
2544 close $aFileLnkObjd
2545 }
2546
910970ab 2547 puts $aFile "\t</Project>"
2548 puts $aFile "</CodeBlocks_project_file>"
2549 close $aFile
2550
2551 return $aCbpFilePath
2552}
2553
910970ab 2554# Define libraries to link using only EXTERNLIB file
2555proc LibToLinkX {thePackage theDummyName} {
2556 set aToolKits [LibToLink $thePackage]
2557 return $aToolKits
2558}
2559
c7d774c5 2560# Function to generate Xcode workspace and project files
2561proc OS:MKXCD { theOutDir {theModules {}} {theAllSolution ""} {theLibType "dynamic"} {thePlatform ""} } {
2562
2563 puts stderr "Generating project files for Xcode"
2564
2565 # Generate projects for toolkits and separate workspace for each module
2566 foreach aModule $theModules {
2567 OS:xcworkspace $aModule $aModule $theOutDir
2568 OS:xcodeproj $aModule $theOutDir ::THE_GUIDS_LIST $theLibType $thePlatform
2569 }
2570
2571 # Generate single workspace "OCCT" containing projects from all modules
2572 if { "$theAllSolution" != "" } {
2573 OS:xcworkspace $theAllSolution $theModules $theOutDir
2574 }
2575}
2576
2577# Generates toolkits sections for Xcode workspace file.
2578proc OS:xcworkspace:toolkits { theModule } {
2579 set aBuff ""
2580
2581 # Adding toolkits for module in workspace.
2582 foreach aToolKit [osutils:tk:sort [${theModule}:toolkits]] {
2583 append aBuff " <FileRef\n"
2584 append aBuff " location = \"group:${aToolKit}.xcodeproj\">\n"
2585 append aBuff " </FileRef>\n"
2586 }
2587
2588 # Adding executables for module, assume one project per cxx file...
2589 foreach aUnit [OS:executable ${theModule}] {
2590 set aUnitLoc $aUnit
2591 set src_files [_get_used_files $aUnit false]
2592 set aSrcFiles {}
2593 foreach s $src_files {
2594 regexp {source ([^\s]+)} $s dummy name
2595 lappend aSrcFiles $name
2596 }
2597 foreach aSrcFile $aSrcFiles {
2598 set aFileExtension [file extension $aSrcFile]
2599 if { $aFileExtension == ".cxx" } {
2600 set aPrjName [file rootname $aSrcFile]
2601 append aBuff " <FileRef\n"
2602 append aBuff " location = \"group:${aPrjName}.xcodeproj\">\n"
2603 append aBuff " </FileRef>\n"
2604 }
2605 }
2606 }
2607
2608 # Removing unnecessary newline character from the end.
2609 set aBuff [string replace $aBuff end end]
2610 return $aBuff
2611}
2612
2613# Generates workspace files for Xcode.
2614proc OS:xcworkspace { theWorkspaceName theModules theOutDir } {
2615 # Creating workspace directory for Xcode.
2616 set aWorkspaceDir "${theOutDir}/${theWorkspaceName}.xcworkspace"
2617 wokUtils:FILES:mkdir $aWorkspaceDir
2618 if { ! [file exists $aWorkspaceDir] } {
2619 puts stderr "Error: Could not create workspace directory \"$aWorkspaceDir\""
2620 return
2621 }
2622
2623 # Creating workspace file.
2624 set aWsFilePath "${aWorkspaceDir}/contents.xcworkspacedata"
2625 set aFile [open $aWsFilePath "w"]
2626
2627 # Adding header and section for main Group.
2628 puts $aFile "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
2629 puts $aFile "<Workspace"
2630 puts $aFile " version = \"1.0\">"
2631 puts $aFile " <Group"
2632 puts $aFile " location = \"container:\""
2633 puts $aFile " name = \"${theWorkspaceName}\">"
2634
2635 # Adding modules.
2636 if { [llength "$theModules"] > 1 } {
2637 foreach aModule $theModules {
2638 puts $aFile " <Group"
2639 puts $aFile " location = \"container:\""
2640 puts $aFile " name = \"${aModule}\">"
2641 puts $aFile [OS:xcworkspace:toolkits $aModule]
2642 puts $aFile " </Group>"
2643 }
2644 } else {
2645 puts $aFile [OS:xcworkspace:toolkits $theModules]
2646 }
2647
2648 # Adding footer.
2649 puts $aFile " </Group>"
2650 puts $aFile "</Workspace>"
2651 close $aFile
2652}
2653
2654# Generates Xcode project files.
2655proc OS:xcodeproj { theModules theOutDir theGuidsMap theLibType thePlatform} {
2656 upvar $theGuidsMap aGuidsMap
2657
2658 set isStatic 0
2659 if { "$theLibType" == "static" } {
2660 set isStatic 1
2661 } elseif { "$thePlatform" == "ios" } {
2662 set isStatic 1
2663 }
2664
2665 set aProjectFiles {}
2666 foreach aModule $theModules {
2667 foreach aToolKit [${aModule}:toolkits] {
2668 lappend aProjectFiles [osutils:xcdtk $theOutDir $aToolKit aGuidsMap $isStatic $thePlatform "dylib"]
2669 }
2670 foreach anExecutable [OS:executable ${aModule}] {
2671 lappend aProjectFiles [osutils:xcdtk $theOutDir $anExecutable aGuidsMap $isStatic $thePlatform "executable"]
2672 }
2673 }
2674 return $aProjectFiles
2675}
2676
2677# Generates dependencies section for Xcode project files.
48ba1811 2678proc osutils:xcdtk:deps {theToolKit theTargetType theGuidsMap theFileRefSection theDepsGuids theDepsRefGuids thePlatform theIsStatic} {
c7d774c5 2679 upvar $theGuidsMap aGuidsMap
2680 upvar $theFileRefSection aFileRefSection
2681 upvar $theDepsGuids aDepsGuids
2682 upvar $theDepsRefGuids aDepsRefGuids
2683
2684 set aBuildFileSection ""
7c65581d 2685 set aUsedLibs [wokUtils:LIST:Purge [osutils:tk:close $theToolKit]]
c7d774c5 2686 set aDepToolkits [lappend [wokUtils:LIST:Purge [osutils:tk:close $theToolKit]] $theToolKit]
2687
2688 if { "$theTargetType" == "executable" } {
cf4bee7c 2689 set aFile [osutils:tk:cxxfiles $theToolKit mac]
c7d774c5 2690 set aProjName [file rootname [file tail $aFile]]
2691 set aDepToolkits [LibToLinkX $theToolKit $aProjName]
2692 }
2693
2694 set aLibExt "dylib"
2695 if { $theIsStatic == 1 } {
2696 set aLibExt "a"
2697 if { "$theTargetType" != "executable" } {
2698 return $aBuildFileSection
2699 }
2700 }
2701
48ba1811 2702 osutils:usedOsLibs $theToolKit $thePlatform aLibs aFrameworks
7c65581d 2703 set aUsedLibs [concat $aUsedLibs $aLibs]
2704 set aUsedLibs [concat $aUsedLibs $aFrameworks]
2705 foreach tkx $aUsedLibs {
c7d774c5 2706 set aDepLib "${tkx}_Dep"
2707 set aDepLibRef "${tkx}_DepRef"
2708
2709 if { ! [info exists aGuidsMap($aDepLib)] } {
2710 set aGuidsMap($aDepLib) [OS:genGUID "xcd"]
2711 }
2712 if { ! [info exists aGuidsMap($aDepLibRef)] } {
2713 set aGuidsMap($aDepLibRef) [OS:genGUID "xcd"]
2714 }
2715
2716 append aBuildFileSection "\t\t$aGuidsMap($aDepLib) = \{isa = PBXBuildFile; fileRef = $aGuidsMap($aDepLibRef) ; \};\n"
2717 if {[lsearch -nocase $aFrameworks $tkx] == -1} {
2718 append aFileRefSection "\t\t$aGuidsMap($aDepLibRef) = \{isa = PBXFileReference; lastKnownFileType = file; name = lib${tkx}.${aLibExt}; path = lib${tkx}.${aLibExt}; sourceTree = \"<group>\"; \};\n"
2719 } else {
2720 append aFileRefSection "\t\t$aGuidsMap($aDepLibRef) = \{isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ${tkx}.framework; path = /System/Library/Frameworks/${tkx}.framework; sourceTree = \"<absolute>\"; \};\n"
2721 }
2722 append aDepsGuids "\t\t\t\t$aGuidsMap($aDepLib) ,\n"
2723 append aDepsRefGuids "\t\t\t\t$aGuidsMap($aDepLibRef) ,\n"
2724 }
2725
2726 return $aBuildFileSection
2727}
2728
2729# Generates PBXBuildFile and PBXGroup sections for project file.
2730proc osutils:xcdtk:sources {theToolKit theTargetType theSrcFileRefSection theGroupSection thePackageGuids theSrcFileGuids theGuidsMap theIncPaths} {
2731 upvar $theSrcFileRefSection aSrcFileRefSection
2732 upvar $theGroupSection aGroupSection
2733 upvar $thePackageGuids aPackagesGuids
2734 upvar $theSrcFileGuids aSrcFileGuids
2735 upvar $theGuidsMap aGuidsMap
2736 upvar $theIncPaths anIncPaths
2737
2738 set listloc [osutils:tk:units $theToolKit]
2739 set resultloc [osutils:justunix $listloc]
2740 set aBuildFileSection ""
2741 set aPackages [lsort -nocase $resultloc]
2742 if { "$theTargetType" == "executable" } {
2743 set aPackages [list "$theToolKit"]
2744 }
2745
2746 # Generating PBXBuildFile, PBXGroup sections and groups for each package.
2747 foreach fxlo $aPackages {
2748 set xlo $fxlo
2749 set aPackage "${xlo}_Package"
2750 set aSrcFileRefGuids ""
2751 if { ! [info exists aGuidsMap($aPackage)] } {
2752 set aGuidsMap($aPackage) [OS:genGUID "xcd"]
2753 }
2754
cf4bee7c 2755 set aSrcFiles [osutils:tk:cxxfiles $xlo mac]
c7d774c5 2756 foreach aSrcFile [lsort $aSrcFiles] {
2757 set aFileExt "sourcecode.cpp.cpp"
2758
2759 if { [file extension $aSrcFile] == ".c" } {
2760 set aFileExt "sourcecode.c.c"
2761 } elseif { [file extension $aSrcFile] == ".mm" } {
2762 set aFileExt "sourcecode.cpp.objcpp"
2763 }
2764
2765 if { ! [info exists aGuidsMap($aSrcFile)] } {
2766 set aGuidsMap($aSrcFile) [OS:genGUID "xcd"]
2767 }
2768 set aSrcFileRef "${aSrcFile}_Ref"
2769 if { ! [info exists aGuidsMap($aSrcFileRef)] } {
2770 set aGuidsMap($aSrcFileRef) [OS:genGUID "xcd"]
2771 }
2772 if { ! [info exists written([file tail $aSrcFile])] } {
2773 set written([file tail $aSrcFile]) 1
2774 append aBuildFileSection "\t\t$aGuidsMap($aSrcFile) = \{isa = PBXBuildFile; fileRef = $aGuidsMap($aSrcFileRef) ;\};\n"
2775 append aSrcFileRefSection "\t\t$aGuidsMap($aSrcFileRef) = \{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = ${aFileExt}; name = [wokUtils:FILES:wtail $aSrcFile 1]; path = ../../../[wokUtils:FILES:wtail $aSrcFile 3]; sourceTree = \"<group>\"; \};\n"
2776 append aSrcFileGuids "\t\t\t\t$aGuidsMap($aSrcFile) ,\n"
2777 append aSrcFileRefGuids "\t\t\t\t$aGuidsMap($aSrcFileRef) ,\n"
2778 } else {
2779 puts "Warning : more than one occurences for [file tail $aSrcFile]"
2780 }
2781 }
2782
2783 append aGroupSection "\t\t$aGuidsMap($aPackage) = \{\n"
2784 append aGroupSection "\t\t\tisa = PBXGroup;\n"
2785 append aGroupSection "\t\t\tchildren = (\n"
2786 append aGroupSection $aSrcFileRefGuids
2787 append aGroupSection "\t\t\t);\n"
2788 append aGroupSection "\t\t\tname = $xlo;\n"
2789 append aGroupSection "\t\t\tsourceTree = \"<group>\";\n"
2790 append aGroupSection "\t\t\};\n"
2791
2792 # Storing packages IDs for adding them later as a child of toolkit
2793 append aPackagesGuids "\t\t\t\t$aGuidsMap($aPackage) ,\n"
2794 }
2795
2796 # Removing unnecessary newline character from the end.
2797 set aPackagesGuids [string replace $aPackagesGuids end end]
2798
2799 return $aBuildFileSection
2800}
2801
2802# Creates folders structure and all necessary files for Xcode project.
2803proc osutils:xcdtk { theOutDir theToolKit theGuidsMap theIsStatic thePlatform {theTargetType "dylib"} } {
2804 set aPBXBuildPhase "Headers"
2805 set aRunOnlyForDeployment "0"
2806 set aProductType "library.dynamic"
2807 set anExecExtension "\t\t\t\tEXECUTABLE_EXTENSION = dylib;"
2808 set anExecPrefix "\t\t\t\tEXECUTABLE_PREFIX = lib;"
2809 set aWrapperExtension "\t\t\t\tWRAPPER_EXTENSION = dylib;"
050c18ac 2810 set aTKDefines [list "OCC_CONVERT_SIGNALS"]
d5265175 2811 if { $theIsStatic == 1 } {
2812 lappend aTKDefines "OCCT_NO_PLUGINS"
2813 }
c7d774c5 2814
2815 if { "$theTargetType" == "executable" } {
2816 set aPBXBuildPhase "CopyFiles"
2817 set aRunOnlyForDeployment "1"
2818 set aProductType "tool"
2819 set anExecExtension ""
2820 set anExecPrefix ""
2821 set aWrapperExtension ""
2822 } elseif { $theIsStatic == 1 } {
2823 set aProductType "library.static"
2824 set anExecExtension "\t\t\t\tEXECUTABLE_EXTENSION = a;"
2825 set aWrapperExtension "\t\t\t\tWRAPPER_EXTENSION = a;"
2826 }
2827
2828 set aUsername [exec whoami]
2829
2830 # Creation of folders for Xcode projectP.
2831 set aToolkitDir "${theOutDir}/${theToolKit}.xcodeproj"
2832 wokUtils:FILES:mkdir $aToolkitDir
2833 if { ! [file exists $aToolkitDir] } {
2834 puts stderr "Error: Could not create project directory \"$aToolkitDir\""
2835 return
2836 }
2837
2838 set aUserDataDir "${aToolkitDir}/xcuserdata"
2839 wokUtils:FILES:mkdir $aUserDataDir
2840 if { ! [file exists $aUserDataDir] } {
2841 puts stderr "Error: Could not create xcuserdata directorty in \"$aToolkitDir\""
2842 return
2843 }
2844
2845 set aUserDataDir "${aUserDataDir}/${aUsername}.xcuserdatad"
2846 wokUtils:FILES:mkdir $aUserDataDir
2847 if { ! [file exists $aUserDataDir] } {
2848 puts stderr "Error: Could not create ${aUsername}.xcuserdatad directorty in \"$aToolkitDir\"/xcuserdata"
2849 return
2850 }
2851
2852 set aSchemesDir "${aUserDataDir}/xcschemes"
2853 wokUtils:FILES:mkdir $aSchemesDir
2854 if { ! [file exists $aSchemesDir] } {
2855 puts stderr "Error: Could not create xcschemes directorty in \"$aUserDataDir\""
2856 return
2857 }
2858 # End of folders creation.
2859
2860 # Generating GUID for tookit.
2861 upvar $theGuidsMap aGuidsMap
2862 if { ! [info exists aGuidsMap($theToolKit)] } {
2863 set aGuidsMap($theToolKit) [OS:genGUID "xcd"]
2864 }
2865
2866 # Creating xcscheme file for toolkit from template.
2867 set aXcschemeTmpl [osutils:readtemplate "xcscheme" "xcd"]
2868 regsub -all -- {__TOOLKIT_NAME__} $aXcschemeTmpl $theToolKit aXcschemeTmpl
2869 regsub -all -- {__TOOLKIT_GUID__} $aXcschemeTmpl $aGuidsMap($theToolKit) aXcschemeTmpl
2870 set aXcschemeFile [open "$aSchemesDir/${theToolKit}.xcscheme" "w"]
2871 puts $aXcschemeFile $aXcschemeTmpl
2872 close $aXcschemeFile
2873
2874 # Creating xcschememanagement.plist file for toolkit from template.
2875 set aPlistTmpl [osutils:readtemplate "plist" "xcd"]
2876 regsub -all -- {__TOOLKIT_NAME__} $aPlistTmpl $theToolKit aPlistTmpl
2877 regsub -all -- {__TOOLKIT_GUID__} $aPlistTmpl $aGuidsMap($theToolKit) aPlistTmpl
2878 set aPlistFile [open "$aSchemesDir/xcschememanagement.plist" "w"]
2879 puts $aPlistFile $aPlistTmpl
2880 close $aPlistFile
2881
2882 # Creating project.pbxproj file for toolkit.
2883 set aPbxprojFile [open "$aToolkitDir/project.pbxproj" "w"]
2884 puts $aPbxprojFile "// !\$*UTF8*\$!"
2885 puts $aPbxprojFile "\{"
2886 puts $aPbxprojFile "\tarchiveVersion = 1;"
2887 puts $aPbxprojFile "\tclasses = \{"
2888 puts $aPbxprojFile "\t\};"
2889 puts $aPbxprojFile "\tobjectVersion = 46;"
2890 puts $aPbxprojFile "\tobjects = \{\n"
2891
2892 # Begin PBXBuildFile section
2893 set aPackagesGuids ""
2894 set aGroupSection ""
2895 set aSrcFileRefSection ""
2896 set aSrcFileGuids ""
2897 set aDepsFileRefSection ""
2898 set aDepsGuids ""
2899 set aDepsRefGuids ""
2900 set anIncPaths [list "../../../inc"]
2901 set anLibPaths ""
2902
2903 if { [info exists ::env(CSF_OPT_INC)] } {
2904 set anIncCfg [split "$::env(CSF_OPT_INC)" ":"]
2905 foreach anIncCfgPath $anIncCfg {
2906 lappend anIncPaths $anIncCfgPath
2907 }
2908 }
2909 if { [info exists ::env(CSF_OPT_LIB64)] } {
2910 set anLibCfg [split "$::env(CSF_OPT_LIB64)" ":"]
2911 foreach anLibCfgPath $anLibCfg {
2912 lappend anLibPaths $anLibCfgPath
2913 }
2914 }
2915
2916 puts $aPbxprojFile [osutils:xcdtk:sources $theToolKit $theTargetType aSrcFileRefSection aGroupSection aPackagesGuids aSrcFileGuids aGuidsMap anIncPaths]
48ba1811 2917 puts $aPbxprojFile [osutils:xcdtk:deps $theToolKit $theTargetType aGuidsMap aDepsFileRefSection aDepsGuids aDepsRefGuids $thePlatform $theIsStatic]
c7d774c5 2918 # End PBXBuildFile section
2919
2920 # Begin PBXFileReference section
2921 set aToolkitLib "lib${theToolKit}.dylib"
2922 set aPath "$aToolkitLib"
2923 if { "$theTargetType" == "executable" } {
2924 set aPath "$theToolKit"
2925 } elseif { $theIsStatic == 1 } {
2926 set aToolkitLib "lib${theToolKit}.a"
2927 }
2928
2929 if { ! [info exists aGuidsMap($aToolkitLib)] } {
2930 set aGuidsMap($aToolkitLib) [OS:genGUID "xcd"]
2931 }
2932
2933 puts $aPbxprojFile "\t\t$aGuidsMap($aToolkitLib) = {isa = PBXFileReference; explicitFileType = \"compiled.mach-o.${theTargetType}\"; includeInIndex = 0; path = $aPath; sourceTree = BUILT_PRODUCTS_DIR; };\n"
2934 puts $aPbxprojFile $aSrcFileRefSection
2935 puts $aPbxprojFile $aDepsFileRefSection
2936 # End PBXFileReference section
2937
2938
2939 # Begin PBXFrameworksBuildPhase section
2940 set aTkFrameworks "${theToolKit}_Frameworks"
2941 if { ! [info exists aGuidsMap($aTkFrameworks)] } {
2942 set aGuidsMap($aTkFrameworks) [OS:genGUID "xcd"]
2943 }
2944
2945 puts $aPbxprojFile "\t\t$aGuidsMap($aTkFrameworks) = \{"
2946 puts $aPbxprojFile "\t\t\tisa = PBXFrameworksBuildPhase;"
2947 puts $aPbxprojFile "\t\t\tbuildActionMask = 2147483647;"
2948 puts $aPbxprojFile "\t\t\tfiles = ("
2949 puts $aPbxprojFile $aDepsGuids
2950 puts $aPbxprojFile "\t\t\t);"
2951 puts $aPbxprojFile "\t\t\trunOnlyForDeploymentPostprocessing = 0;"
2952 puts $aPbxprojFile "\t\t\};\n"
2953 # End PBXFrameworksBuildPhase section
2954
2955 # Begin PBXGroup section
2956 set aTkPBXGroup "${theToolKit}_PBXGroup"
2957 if { ! [info exists aGuidsMap($aTkPBXGroup)] } {
2958 set aGuidsMap($aTkPBXGroup) [OS:genGUID "xcd"]
2959 }
2960
2961 set aTkSrcGroup "${theToolKit}_SrcGroup"
2962 if { ! [info exists aGuidsMap($aTkSrcGroup)] } {
2963 set aGuidsMap($aTkSrcGroup) [OS:genGUID "xcd"]
2964 }
2965
2966 puts $aPbxprojFile $aGroupSection
2967 puts $aPbxprojFile "\t\t$aGuidsMap($aTkPBXGroup) = \{"
2968 puts $aPbxprojFile "\t\t\tisa = PBXGroup;"
2969 puts $aPbxprojFile "\t\t\tchildren = ("
2970 puts $aPbxprojFile $aDepsRefGuids
2971 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkSrcGroup) ,"
2972 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aToolkitLib) ,"
2973 puts $aPbxprojFile "\t\t\t);"
2974 puts $aPbxprojFile "\t\t\tsourceTree = \"<group>\";"
2975 puts $aPbxprojFile "\t\t\};"
2976 puts $aPbxprojFile "\t\t$aGuidsMap($aTkSrcGroup) = \{"
2977 puts $aPbxprojFile "\t\t\tisa = PBXGroup;"
2978 puts $aPbxprojFile "\t\t\tchildren = ("
2979 puts $aPbxprojFile $aPackagesGuids
2980 puts $aPbxprojFile "\t\t\t);"
2981 puts $aPbxprojFile "\t\t\tname = \"Source files\";"
2982 puts $aPbxprojFile "\t\t\tsourceTree = \"<group>\";"
2983 puts $aPbxprojFile "\t\t\};\n"
2984 # End PBXGroup section
2985
2986 # Begin PBXHeadersBuildPhase section
2987 set aTkHeaders "${theToolKit}_Headers"
2988 if { ! [info exists aGuidsMap($aTkHeaders)] } {
2989 set aGuidsMap($aTkHeaders) [OS:genGUID "xcd"]
2990 }
2991
2992 puts $aPbxprojFile "\t\t$aGuidsMap($aTkHeaders) = \{"
2993 puts $aPbxprojFile "\t\t\tisa = PBX${aPBXBuildPhase}BuildPhase;"
2994 puts $aPbxprojFile "\t\t\tbuildActionMask = 2147483647;"
2995 puts $aPbxprojFile "\t\t\tfiles = ("
2996 puts $aPbxprojFile "\t\t\t);"
2997 puts $aPbxprojFile "\t\t\trunOnlyForDeploymentPostprocessing = ${aRunOnlyForDeployment};"
2998 puts $aPbxprojFile "\t\t\};\n"
2999 # End PBXHeadersBuildPhase section
3000
3001 # Begin PBXNativeTarget section
3002 set aTkBuildCfgListNativeTarget "${theToolKit}_BuildCfgListNativeTarget"
3003 if { ! [info exists aGuidsMap($aTkBuildCfgListNativeTarget)] } {
3004 set aGuidsMap($aTkBuildCfgListNativeTarget) [OS:genGUID "xcd"]
3005 }
3006
3007 set aTkSources "${theToolKit}_Sources"
3008 if { ! [info exists aGuidsMap($aTkSources)] } {
3009 set aGuidsMap($aTkSources) [OS:genGUID "xcd"]
3010 }
3011
3012 puts $aPbxprojFile "\t\t$aGuidsMap($theToolKit) = \{"
3013 puts $aPbxprojFile "\t\t\tisa = PBXNativeTarget;"
3014 puts $aPbxprojFile "\t\t\tbuildConfigurationList = $aGuidsMap($aTkBuildCfgListNativeTarget) ;"
3015 puts $aPbxprojFile "\t\t\tbuildPhases = ("
3016 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkSources) ,"
3017 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkFrameworks) ,"
3018 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkHeaders) ,"
3019 puts $aPbxprojFile "\t\t\t);"
3020 puts $aPbxprojFile "\t\t\tbuildRules = ("
3021 puts $aPbxprojFile "\t\t\t);"
3022 puts $aPbxprojFile "\t\t\tdependencies = ("
3023 puts $aPbxprojFile "\t\t\t);"
3024 puts $aPbxprojFile "\t\t\tname = $theToolKit;"
3025 puts $aPbxprojFile "\t\t\tproductName = $theToolKit;"
3026 puts $aPbxprojFile "\t\t\tproductReference = $aGuidsMap($aToolkitLib) ;"
3027 puts $aPbxprojFile "\t\t\tproductType = \"com.apple.product-type.${aProductType}\";"
3028 puts $aPbxprojFile "\t\t\};\n"
3029 # End PBXNativeTarget section
3030
3031 # Begin PBXProject section
3032 set aTkProjectObj "${theToolKit}_ProjectObj"
3033 if { ! [info exists aGuidsMap($aTkProjectObj)] } {
3034 set aGuidsMap($aTkProjectObj) [OS:genGUID "xcd"]
3035 }
3036
3037 set aTkBuildCfgListProj "${theToolKit}_BuildCfgListProj"
3038 if { ! [info exists aGuidsMap($aTkBuildCfgListProj)] } {
3039 set aGuidsMap($aTkBuildCfgListProj) [OS:genGUID "xcd"]
3040 }
3041
3042 puts $aPbxprojFile "\t\t$aGuidsMap($aTkProjectObj) = \{"
3043 puts $aPbxprojFile "\t\t\tisa = PBXProject;"
3044 puts $aPbxprojFile "\t\t\tattributes = \{"
3045 puts $aPbxprojFile "\t\t\t\tLastUpgradeCheck = 0430;"
3046 puts $aPbxprojFile "\t\t\t\};"
3047 puts $aPbxprojFile "\t\t\tbuildConfigurationList = $aGuidsMap($aTkBuildCfgListProj) ;"
3048 puts $aPbxprojFile "\t\t\tcompatibilityVersion = \"Xcode 3.2\";"
3049 puts $aPbxprojFile "\t\t\tdevelopmentRegion = English;"
3050 puts $aPbxprojFile "\t\t\thasScannedForEncodings = 0;"
3051 puts $aPbxprojFile "\t\t\tknownRegions = ("
3052 puts $aPbxprojFile "\t\t\t\ten,"
3053 puts $aPbxprojFile "\t\t\t);"
3054 puts $aPbxprojFile "\t\t\tmainGroup = $aGuidsMap($aTkPBXGroup);"
3055 puts $aPbxprojFile "\t\t\tproductRefGroup = $aGuidsMap($aTkPBXGroup);"
3056 puts $aPbxprojFile "\t\t\tprojectDirPath = \"\";"
3057 puts $aPbxprojFile "\t\t\tprojectRoot = \"\";"
3058 puts $aPbxprojFile "\t\t\ttargets = ("
3059 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($theToolKit) ,"
3060 puts $aPbxprojFile "\t\t\t);"
3061 puts $aPbxprojFile "\t\t\};\n"
3062 # End PBXProject section
3063
3064 # Begin PBXSourcesBuildPhase section
3065 puts $aPbxprojFile "\t\t$aGuidsMap($aTkSources) = \{"
3066 puts $aPbxprojFile "\t\t\tisa = PBXSourcesBuildPhase;"
3067 puts $aPbxprojFile "\t\t\tbuildActionMask = 2147483647;"
3068 puts $aPbxprojFile "\t\t\tfiles = ("
3069 puts $aPbxprojFile $aSrcFileGuids
3070 puts $aPbxprojFile "\t\t\t);"
3071 puts $aPbxprojFile "\t\t\trunOnlyForDeploymentPostprocessing = 0;"
3072 puts $aPbxprojFile "\t\t\};\n"
3073 # End PBXSourcesBuildPhase section
3074
3075 # Begin XCBuildConfiguration section
3076 set aTkDebugProject "${theToolKit}_DebugProject"
3077 if { ! [info exists aGuidsMap($aTkDebugProject)] } {
3078 set aGuidsMap($aTkDebugProject) [OS:genGUID "xcd"]
3079 }
3080
3081 set aTkReleaseProject "${theToolKit}_ReleaseProject"
3082 if { ! [info exists aGuidsMap($aTkReleaseProject)] } {
3083 set aGuidsMap($aTkReleaseProject) [OS:genGUID "xcd"]
3084 }
3085
3086 set aTkDebugNativeTarget "${theToolKit}_DebugNativeTarget"
3087 if { ! [info exists aGuidsMap($aTkDebugNativeTarget)] } {
3088 set aGuidsMap($aTkDebugNativeTarget) [OS:genGUID "xcd"]
3089 }
3090
3091 set aTkReleaseNativeTarget "${theToolKit}_ReleaseNativeTarget"
3092 if { ! [info exists aGuidsMap($aTkReleaseNativeTarget)] } {
3093 set aGuidsMap($aTkReleaseNativeTarget) [OS:genGUID "xcd"]
3094 }
3095
3096 # Debug target
3097 puts $aPbxprojFile "\t\t$aGuidsMap($aTkDebugProject) = \{"
3098 puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3099 puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3100
3101 puts $aPbxprojFile "\t\t\t\tDEBUG_INFORMATION_FORMAT = dwarf;"
3102 puts $aPbxprojFile "\t\t\t\tALWAYS_SEARCH_USER_PATHS = NO;"
3103 if { "$thePlatform" == "ios" } {
3104 puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphoneos\*\]\" = \"\$(ARCHS_STANDARD)\";";
3105 puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphonesimulator\*\]\" = \"x86_64\";";
c7d774c5 3106 puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_MODULES = YES;"
3107 puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_OBJC_ARC = YES;"
3108 }
3109 puts $aPbxprojFile "\t\t\t\tARCHS = \"\$(ARCHS_STANDARD_64_BIT)\";"
810b672f 3110 puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LIBRARY = \"libc++\";"
3111 puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LANGUAGE_STANDARD = \"c++0x\";"
c7d774c5 3112 puts $aPbxprojFile "\t\t\t\tCOPY_PHASE_STRIP = NO;"
3113 puts $aPbxprojFile "\t\t\t\tGCC_C_LANGUAGE_STANDARD = gnu99;"
3114 puts $aPbxprojFile "\t\t\t\tGCC_DYNAMIC_NO_PIC = NO;"
3115 puts $aPbxprojFile "\t\t\t\tGCC_ENABLE_OBJC_EXCEPTIONS = YES;"
3116 puts $aPbxprojFile "\t\t\t\tGCC_OPTIMIZATION_LEVEL = 0;"
3117 puts $aPbxprojFile "\t\t\t\tGCC_PREPROCESSOR_DEFINITIONS = ("
3118 puts $aPbxprojFile "\t\t\t\t\t\"DEBUG=1\","
3119 puts $aPbxprojFile "\t\t\t\t\t\"\$\(inherited\)\","
3120 puts $aPbxprojFile "\t\t\t\t);"
3121 puts $aPbxprojFile "\t\t\t\tGCC_SYMBOLS_PRIVATE_EXTERN = NO;"
3122 puts $aPbxprojFile "\t\t\t\tGCC_VERSION = com.apple.compilers.llvm.clang.1_0;"
3123 puts $aPbxprojFile "\t\t\t\tGCC_WARN_64_TO_32_BIT_CONVERSION = YES;"
3124 puts $aPbxprojFile "\t\t\t\tGCC_WARN_ABOUT_RETURN_TYPE = YES;"
3125 puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNINITIALIZED_AUTOS = YES;"
3126 puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNUSED_VARIABLE = YES;"
3127 puts $aPbxprojFile "\t\t\t\tOTHER_LDFLAGS = \"\$(CSF_OPT_LNK64D)\"; "
3128 if { "$thePlatform" == "ios" } {
3129 puts $aPbxprojFile "\t\t\t\tONLY_ACTIVE_ARCH = NO;"
3130 puts $aPbxprojFile "\t\t\t\tSDKROOT = iphoneos;"
3131 } else {
3132 puts $aPbxprojFile "\t\t\t\tONLY_ACTIVE_ARCH = YES;"
3133 }
3134 puts $aPbxprojFile "\t\t\t\};"
3135
3136 puts $aPbxprojFile "\t\t\tname = Debug;"
3137 puts $aPbxprojFile "\t\t\};"
3138
3139 # Release target
3140 puts $aPbxprojFile "\t\t$aGuidsMap($aTkReleaseProject) = \{"
3141 puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3142 puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3143
3144 puts $aPbxprojFile "\t\t\t\tDEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\";"
3145 puts $aPbxprojFile "\t\t\t\tALWAYS_SEARCH_USER_PATHS = NO;"
3146 if { "$thePlatform" == "ios" } {
3147 puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphoneos\*\]\" = \"\$(ARCHS_STANDARD)\";";
3148 puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphonesimulator\*\]\" = \"x86_64\";";
c7d774c5 3149 puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_MODULES = YES;"
3150 puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_OBJC_ARC = YES;"
3151 }
3152 puts $aPbxprojFile "\t\t\t\tARCHS = \"\$(ARCHS_STANDARD_64_BIT)\";"
810b672f 3153 puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LIBRARY = \"libc++\";"
3154 puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LANGUAGE_STANDARD = \"c++0x\";"
c7d774c5 3155 puts $aPbxprojFile "\t\t\t\tCOPY_PHASE_STRIP = YES;"
3156 puts $aPbxprojFile "\t\t\t\tGCC_C_LANGUAGE_STANDARD = gnu99;"
3157 puts $aPbxprojFile "\t\t\t\tGCC_ENABLE_OBJC_EXCEPTIONS = YES;"
3158 puts $aPbxprojFile "\t\t\t\tDEAD_CODE_STRIPPING = NO;"
3159 puts $aPbxprojFile "\t\t\t\tGCC_OPTIMIZATION_LEVEL = 2;"
3160 puts $aPbxprojFile "\t\t\t\tGCC_VERSION = com.apple.compilers.llvm.clang.1_0;"
3161 puts $aPbxprojFile "\t\t\t\tGCC_WARN_64_TO_32_BIT_CONVERSION = YES;"
3162 puts $aPbxprojFile "\t\t\t\tGCC_WARN_ABOUT_RETURN_TYPE = YES;"
3163 puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNINITIALIZED_AUTOS = YES;"
3164 puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNUSED_VARIABLE = YES;"
3165 puts $aPbxprojFile "\t\t\t\tOTHER_LDFLAGS = \"\$(CSF_OPT_LNK64)\";"
3166 if { "$thePlatform" == "ios" } {
3167 puts $aPbxprojFile "\t\t\t\tIPHONEOS_DEPLOYMENT_TARGET = 7.0;"
3168 puts $aPbxprojFile "\t\t\t\tSDKROOT = iphoneos;"
3169 }
3170 puts $aPbxprojFile "\t\t\t\};"
3171 puts $aPbxprojFile "\t\t\tname = Release;"
3172 puts $aPbxprojFile "\t\t\};"
3173 puts $aPbxprojFile "\t\t$aGuidsMap($aTkDebugNativeTarget) = \{"
3174 puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3175 puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3176 puts $aPbxprojFile "${anExecExtension}"
3177 puts $aPbxprojFile "${anExecPrefix}"
3178 puts $aPbxprojFile "\t\t\t\tGCC_PREPROCESSOR_DEFINITIONS = ("
3179 foreach aMacro $aTKDefines {
3180 puts $aPbxprojFile "\t\t\t\t\t${aMacro} ,"
3181 }
3182 puts $aPbxprojFile "\t\t\t\t);"
3183
3184 puts $aPbxprojFile "\t\t\t\tHEADER_SEARCH_PATHS = ("
3185 foreach anIncPath $anIncPaths {
3186 puts $aPbxprojFile "\t\t\t\t\t${anIncPath},"
3187 }
3188 puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_INC)\","
3189 puts $aPbxprojFile "\t\t\t\t);"
3190
3191 puts $aPbxprojFile "\t\t\t\tLIBRARY_SEARCH_PATHS = ("
3192 foreach anLibPath $anLibPaths {
3193 puts $aPbxprojFile "\t\t\t\t\t${anLibPath},"
3194 }
3195 puts $aPbxprojFile "\t\t\t\t);"
3196
3197 puts $aPbxprojFile "\t\t\t\tOTHER_CFLAGS = ("
3198 puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_CMPL)\","
3199 puts $aPbxprojFile "\t\t\t\t);"
3200 puts $aPbxprojFile "\t\t\t\tOTHER_CPLUSPLUSFLAGS = ("
3201 puts $aPbxprojFile "\t\t\t\t\t\"\$(OTHER_CFLAGS)\","
3202 puts $aPbxprojFile "\t\t\t\t);"
3203 puts $aPbxprojFile "\t\t\t\tPRODUCT_NAME = \"\$(TARGET_NAME)\";"
3204 set anUserHeaderSearchPath "\t\t\t\tUSER_HEADER_SEARCH_PATHS = \""
3205 foreach anIncPath $anIncPaths {
3206 append anUserHeaderSearchPath " ${anIncPath}"
3207 }
3208 append anUserHeaderSearchPath "\";"
3209 puts $aPbxprojFile $anUserHeaderSearchPath
3210 puts $aPbxprojFile "${aWrapperExtension}"
3211 puts $aPbxprojFile "\t\t\t\};"
3212 puts $aPbxprojFile "\t\t\tname = Debug;"
3213 puts $aPbxprojFile "\t\t\};"
3214 puts $aPbxprojFile "\t\t$aGuidsMap($aTkReleaseNativeTarget) = \{"
3215 puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3216 puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3217 puts $aPbxprojFile "${anExecExtension}"
3218 puts $aPbxprojFile "${anExecPrefix}"
3219 puts $aPbxprojFile "\t\t\t\tGCC_PREPROCESSOR_DEFINITIONS = ("
3220 foreach aMacro $aTKDefines {
3221 puts $aPbxprojFile "\t\t\t\t\t${aMacro} ,"
3222 }
3223 puts $aPbxprojFile "\t\t\t\t);"
3224 puts $aPbxprojFile "\t\t\t\tHEADER_SEARCH_PATHS = ("
3225 foreach anIncPath $anIncPaths {
3226 puts $aPbxprojFile "\t\t\t\t\t${anIncPath},"
3227 }
3228 puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_INC)\","
3229 puts $aPbxprojFile "\t\t\t\t);"
3230
3231 puts $aPbxprojFile "\t\t\t\tLIBRARY_SEARCH_PATHS = ("
3232 foreach anLibPath $anLibPaths {
3233 puts $aPbxprojFile "\t\t\t\t\t${anLibPath},"
3234 }
3235 puts $aPbxprojFile "\t\t\t\t);"
3236
3237 puts $aPbxprojFile "\t\t\t\tOTHER_CFLAGS = ("
3238 puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_CMPL)\","
3239 puts $aPbxprojFile "\t\t\t\t);"
3240 puts $aPbxprojFile "\t\t\t\tOTHER_CPLUSPLUSFLAGS = ("
3241 puts $aPbxprojFile "\t\t\t\t\t\"\$(OTHER_CFLAGS)\","
3242 puts $aPbxprojFile "\t\t\t\t);"
3243 puts $aPbxprojFile "\t\t\t\tPRODUCT_NAME = \"\$(TARGET_NAME)\";"
3244 puts $aPbxprojFile $anUserHeaderSearchPath
3245 puts $aPbxprojFile "${aWrapperExtension}"
3246 puts $aPbxprojFile "\t\t\t\};"
3247 puts $aPbxprojFile "\t\t\tname = Release;"
3248 puts $aPbxprojFile "\t\t\};\n"
3249 # End XCBuildConfiguration section
3250
3251 # Begin XCConfigurationList section
3252 puts $aPbxprojFile "\t\t$aGuidsMap($aTkBuildCfgListProj) = \{"
3253 puts $aPbxprojFile "\t\t\tisa = XCConfigurationList;"
3254 puts $aPbxprojFile "\t\tbuildConfigurations = ("
3255 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkDebugProject) ,"
3256 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkReleaseProject) ,"
3257 puts $aPbxprojFile "\t\t\t);"
3258 puts $aPbxprojFile "\t\t\tdefaultConfigurationIsVisible = 0;"
3259 puts $aPbxprojFile "\t\t\tdefaultConfigurationName = Release;"
3260 puts $aPbxprojFile "\t\t\};"
3261 puts $aPbxprojFile "\t\t$aGuidsMap($aTkBuildCfgListNativeTarget) = \{"
3262 puts $aPbxprojFile "\t\t\tisa = XCConfigurationList;"
3263 puts $aPbxprojFile "\t\t\tbuildConfigurations = ("
3264 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkDebugNativeTarget) ,"
3265 puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkReleaseNativeTarget) ,"
3266 puts $aPbxprojFile "\t\t\t);"
3267 puts $aPbxprojFile "\t\t\tdefaultConfigurationIsVisible = 0;"
3268 puts $aPbxprojFile "\t\t\tdefaultConfigurationName = Release;"
3269 puts $aPbxprojFile "\t\t\};\n"
3270 # End XCConfigurationList section
3271
3272 puts $aPbxprojFile "\t\};"
3273 puts $aPbxprojFile "\trootObject = $aGuidsMap($aTkProjectObj) ;"
3274 puts $aPbxprojFile "\}"
3275
3276 close $aPbxprojFile
3277}
3278
3279proc osutils:xcdx { theOutDir theExecutable theGuidsMap } {
3280 set aUsername [exec whoami]
3281
3282 # Creating folders for Xcode project file.
3283 set anExecutableDir "${theOutDir}/${theExecutable}.xcodeproj"
3284 wokUtils:FILES:mkdir $anExecutableDir
3285 if { ! [file exists $anExecutableDir] } {
3286 puts stderr "Error: Could not create project directory \"$anExecutableDir\""
3287 return
3288 }
3289
3290 set aUserDataDir "${anExecutableDir}/xcuserdata"
3291 wokUtils:FILES:mkdir $aUserDataDir
3292 if { ! [file exists $aUserDataDir] } {
3293 puts stderr "Error: Could not create xcuserdata directorty in \"$anExecutableDir\""
3294 return
3295 }
3296
3297 set aUserDataDir "${aUserDataDir}/${aUsername}.xcuserdatad"
3298 wokUtils:FILES:mkdir $aUserDataDir
3299 if { ! [file exists $aUserDataDir] } {
3300 puts stderr "Error: Could not create ${aUsername}.xcuserdatad directorty in \"$anExecutableDir\"/xcuserdata"
3301 return
3302 }
3303
3304 set aSchemesDir "${aUserDataDir}/xcschemes"
3305 wokUtils:FILES:mkdir $aSchemesDir
3306 if { ! [file exists $aSchemesDir] } {
3307 puts stderr "Error: Could not create xcschemes directorty in \"$aUserDataDir\""
3308 return
3309 }
3310 # End folders creation.
3311
3312 # Generating GUID for tookit.
3313 upvar $theGuidsMap aGuidsMap
3314 if { ! [info exists aGuidsMap($theExecutable)] } {
3315 set aGuidsMap($theExecutable) [OS:genGUID "xcd"]
3316 }
3317
3318 # Creating xcscheme file for toolkit from template.
3319 set aXcschemeTmpl [osutils:readtemplate "xcscheme" "xcode"]
3320 regsub -all -- {__TOOLKIT_NAME__} $aXcschemeTmpl $theExecutable aXcschemeTmpl
3321 regsub -all -- {__TOOLKIT_GUID__} $aXcschemeTmpl $aGuidsMap($theExecutable) aXcschemeTmpl
3322 set aXcschemeFile [open "$aSchemesDir/${theExecutable}.xcscheme" "w"]
3323 puts $aXcschemeFile $aXcschemeTmpl
3324 close $aXcschemeFile
3325
3326 # Creating xcschememanagement.plist file for toolkit from template.
3327 set aPlistTmpl [osutils:readtemplate "plist" "xcode"]
3328 regsub -all -- {__TOOLKIT_NAME__} $aPlistTmpl $theExecutable aPlistTmpl
3329 regsub -all -- {__TOOLKIT_GUID__} $aPlistTmpl $aGuidsMap($theExecutable) aPlistTmpl
3330 set aPlistFile [open "$aSchemesDir/xcschememanagement.plist" "w"]
3331 puts $aPlistFile $aPlistTmpl
3332 close $aPlistFile
3333}
7fbac3c2 3334
3335# Returns available Windows SDKs versions
3336proc osutils:sdk { theSdkMajorVer {isQuietMode false} {theSdkDirectories {}} } {
3337 if { ![llength ${theSdkDirectories}] } {
3338 foreach anEnvVar { "ProgramFiles" "ProgramFiles\(x86\)" "ProgramW6432" } {
3339 if {[ info exists ::env(${anEnvVar}) ]} {
3340 lappend theSdkDirectories "$::env(${anEnvVar})/Windows Kits/${theSdkMajorVer}/Include"
3341 }
3342 }
3343 }
3344
3345 set sdk_versions {}
3346 foreach sdk_dir ${theSdkDirectories} {
3347 if { [file isdirectory ${sdk_dir}] } {
3348 lappend sdk_versions [glob -tails -directory "${sdk_dir}" -type d *]
3349 }
3350 }
3351
3352 if {![llength ${sdk_versions}] && !${isQuietMode}} {
3353 error "Error : Could not find Windows SDK ${theSdkMajorVer}"
3354 }
3355
3356 return [join [lsort -unique ${sdk_versions}] " "]
3357}
3358
3359# Generate global properties to Visual Studio project file for UWP solution
d6cda17a 3360proc osutils:uwp:proj { isUWP theProjTmpl } {
7fbac3c2 3361
3362 set uwp_properties ""
3363 set uwp_generate_metadata ""
3364 set uwp_app_container ""
3365
3366 set format_template ""
3367
d6cda17a 3368 if { $isUWP } {
7fbac3c2 3369 set sdk_versions [osutils:sdk 10]
3370 set sdk_max_ver [lindex ${sdk_versions} end]
3371
3372 set uwp_properties "<DefaultLanguage>en-US</DefaultLanguage>\n \
3373<ApplicationType>Windows Store</ApplicationType>\n \
3374<ApplicationTypeRevision>10.0</ApplicationTypeRevision>\n \
3375<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>\n \
3376<AppContainerApplication>true</AppContainerApplication>\n \
3377<WindowsTargetPlatformVersion>${sdk_max_ver}</WindowsTargetPlatformVersion>\n \
3378<WindowsTargetPlatformMinVersion>${sdk_max_ver}</WindowsTargetPlatformMinVersion>"
3379
3380 set uwp_generate_metadata "<GenerateWindowsMetadata>false</GenerateWindowsMetadata>"
3381
3382 regsub -all -- {[\r\n\s]*<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>} ${theProjTmpl} "" theProjTmpl
3383 } else {
3384 set format_template "\[\\r\\n\\s\]*"
3385 }
3386
3387 regsub -all -- "${format_template}__UWP_PROPERTIES__" ${theProjTmpl} "${uwp_properties}" theProjTmpl
3388 regsub -all -- "${format_template}__UWP_GENERATE_METADATA__" ${theProjTmpl} "${uwp_generate_metadata}" theProjTmpl
3389
3390 return ${theProjTmpl}
3391}
5da3dfdf 3392
3393# Report all files found in package directory but not listed in FILES
3394proc osutils:checksrcfiles { theUnit } {
3395 global path
3396 set aCasRoot [file normalize ${path}]
3397
3398 if {![file isdirectory ${aCasRoot}]} {
3399 puts "OCCT directory is not defined correctly: ${aCasRoot}"
3400 return
3401 }
3402
3403 set anUnitAbsPath [file normalize "${aCasRoot}/src/${theUnit}"]
3404
3405 if {[file exists "${anUnitAbsPath}/FILES"]} {
3406 set aFilesFile [open "${anUnitAbsPath}/FILES" rb]
3407 set aFilesFileList [split [read ${aFilesFile}] "\n"]
3408 close ${aFilesFile}
3409
3410 set aFilesFileList [lsearch -inline -all -not -exact ${aFilesFileList} ""]
3411
3412 # report all files not listed in FILES
3413 set anAllFiles [glob -tails -nocomplain -dir ${anUnitAbsPath} "*"]
3414 foreach aFile ${anAllFiles} {
3415 if { "${aFile}" == "FILES" } {
3416 continue
3417 }
3418 if { [lsearch -exact ${aFilesFileList} ${aFile}] == -1 } {
3419 puts "Warning: file ${anUnitAbsPath}/${aFile} is not listed in ${anUnitAbsPath}/FILES!"
3420 }
3421 }
3422 }
3423}