Skip to content

Commit

Permalink
fix: usr: apparently cmake --build --parallel is broken in VS
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Nov 17, 2020
1 parent 6925537 commit 97b8460
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/c4/cmany/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,43 @@ def cmd(self, targets):
elif self.is_ninja:
return ['ninja', '-j', str(self.num_jobs)] + targets
else:
bt = str(self.build.build_type)
if len(targets) > 1:
raise TooManyTargets(self)
cmd = ['cmake', '--build', '.', '--config', bt, '--target', targets[0],
'--parallel', str(self.num_jobs)]
target = targets[0]
bt = str(self.build.build_type)
# NOTE:
# the `--parallel` flag to `cmake --build` is broken in VS and XCode:
# https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/10
# https://gitlab.kitware.com/cmake/cmake/-/issues/20564
if not self.is_msvc:
cmd = ['cmake', '--build', '.', '--target', target, '--config', bt,
'--parallel', str(self.num_jobs)]
# TODO XCode is also broken; the flag is this:
# -IDEBuildOperationMaxNumberOfConcurrentCompileTasks=$NUM_JOBS_BUILD
# see:
# https://stackoverflow.com/questions/5417835/how-to-modify-the-number-of-parallel-compilation-with-xcode
# https://gist.github.com/nlutsenko/ee245fbd239087d22137
else:
cmd = ['cmake', '--build', '.', '--target', target, '--config', bt,
'--', '/maxcpucount:' + str(self.num_jobs)]
# old code for building through msbuild:
# # if a target has a . in the name, it must be substituted for _
# targets_safe = [re.sub(r'\.', r'_', t) for t in targets]
# if len(targets_safe) != 1:
# raise TooManyTargets("msbuild can only build one target at a time: was " + str(targets_safe))
# t = targets_safe[0]
# pat = os.path.join(self.build.builddir, t + '*.vcxproj')
# projs = glob.glob(pat)
# if len(projs) == 0:
# msg = "could not find vcx project for this target: {} (glob={}, got={})".format(t, pat, projs)
# raise Exception(msg)
# elif len(projs) > 1:
# msg = "multiple vcx projects for this target: {} (glob={}, got={})".format(t, pat, projs)
# raise Exception(msg)
# proj = projs[0]
# cmd = [self.build.compiler.vs.msbuild, proj,
# '/property:Configuration='+bt,
# '/maxcpucount:' + str(self.num_jobs)]
return cmd

def cmd_source_file(self, target, source_file):
Expand All @@ -152,9 +184,3 @@ def cmd_source_file(self, target, source_file):
def install(self):
bt = str(self.build.build_type)
return ['cmake', '--build', '.', '--config', bt, '--target', 'install']

def clean_msbuild_target_name(self, target_name):
# if a target has a . in the name, it must be substituted for _
target_safe = re.sub(r'\.', r'_', target_name)


0 comments on commit 97b8460

Please sign in to comment.