|
10 | 10 | from tools.export.exporters import Exporter, FailedBuildException
|
11 | 11 | import json
|
12 | 12 | from tools.export.cmsis import DeviceCMSIS
|
| 13 | +from multiprocessing import cpu_count |
13 | 14 |
|
14 | 15 | class IAR(Exporter):
|
15 | 16 | NAME = 'iar'
|
@@ -101,7 +102,7 @@ def generate(self):
|
101 | 102 | flags['c_flags'].remove('--vla')
|
102 | 103 | if '--no_static_destruction' in flags['c_flags']:
|
103 | 104 | flags['c_flags'].remove('--no_static_destruction')
|
104 |
| - #Optimizations |
| 105 | + #Optimizations |
105 | 106 | if '-Oh' in flags['c_flags']:
|
106 | 107 | flags['c_flags'].remove('-Oh')
|
107 | 108 | ctx = {
|
@@ -135,6 +136,17 @@ def build(self):
|
135 | 136 | raise Exception("IarBuild.exe not found. Add to path.")
|
136 | 137 |
|
137 | 138 | cmd = [iar_exe, proj_file, '-build', self.project_name]
|
| 139 | + |
| 140 | + # IAR does not support a '0' option to automatically use all |
| 141 | + # available CPUs, so we use Python's multiprocessing library |
| 142 | + # to detect the number of CPUs available |
| 143 | + cpus_available = cpu_count() |
| 144 | + jobs = cpus_available if cpus_available else None |
| 145 | + |
| 146 | + # Only add the parallel flag if we're using more than one CPU |
| 147 | + if jobs: |
| 148 | + cmd += ['-parallel', str(jobs)] |
| 149 | + |
138 | 150 | p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
139 | 151 | num_errors = 0
|
140 | 152 | #Parse the output for printing and errors
|
|
0 commit comments