コード例 #1
0
    async def _build(self, args, env):
        self.progress('build')

        # invoke build step
        if CMAKE_EXECUTABLE is None:
            raise RuntimeError("Could not find 'cmake' executable")
        cmd = [CMAKE_EXECUTABLE, '--build', args.build_base]
        if args.cmake_target:
            if args.cmake_target_skip_unavailable:
                if not await has_target(args.build_base, args.cmake_target):
                    return
            cmd += ['--target', args.cmake_target]
        if args.cmake_clean_first:
            cmd += ['--clean-first']
        if is_multi_configuration_generator(args.build_base, args.cmake_args):
            cmd += ['--config', self._get_configuration(args)]

            generator = get_generator(args.build_base)
            if 'Visual Studio' in generator:
                env = self._get_msbuild_environment(args, env)
        else:
            job_args = self._get_make_arguments()
            if job_args:
                cmd += ['--'] + job_args
        return await check_call(self.context,
                                cmd,
                                cwd=args.build_base,
                                env=env)
コード例 #2
0
ファイル: build.py プロジェクト: aws-ros-dev/colcon-cmake
    async def _install(self, args, env):
        self.progress('install')

        generator = get_generator(args.build_base)
        if 'Visual Studio' not in generator:
            if CMAKE_EXECUTABLE is None:
                raise RuntimeError("Could not find 'cmake' executable")
            return await check_call(
                self.context,
                [
                    CMAKE_EXECUTABLE, '--build', args.build_base,
                    '--target', 'install'],
                cwd=args.build_base, env=env)
        else:
            if MSBUILD_EXECUTABLE is None:
                raise RuntimeError("Could not find 'msbuild' executable")
            install_project_file = get_project_file(args.build_base, 'INSTALL')
            return await check_call(
                self.context,
                [
                    MSBUILD_EXECUTABLE,
                    '/p:Configuration=' +
                    self._get_configuration(args),
                    install_project_file],
                env=env)
コード例 #3
0
    async def _reconfigure(self, args, env):
        self.progress('cmake')

        cmake_cache = Path(args.build_base) / 'CMakeCache.txt'
        run_configure = args.cmake_force_configure
        if args.cmake_clean_cache and cmake_cache.exists():
            cmake_cache.unlink()
        if not run_configure:
            run_configure = not cmake_cache.exists()
        if not run_configure:
            buildfile = get_buildfile(cmake_cache)
            run_configure = not buildfile.exists()

        # check CMake args from last run to decide on need to reconfigure
        if not run_configure:
            last_cmake_args = self._get_last_cmake_args(args.build_base)
            run_configure = (args.cmake_args or []) != (last_cmake_args or [])
        self._store_cmake_args(args.build_base, args.cmake_args)

        if not run_configure:
            return

        # invoke CMake / reconfigure target
        cmake_args = [args.path]
        cmake_args += (args.cmake_args or [])
        cmake_args += ['-DCMAKE_INSTALL_PREFIX=' + args.install_base]
        generator = get_generator(args.build_base, args.cmake_args)
        if os.name == 'nt' and generator is None:
            vsv = get_visual_studio_version()
            if vsv is None:
                raise RuntimeError(
                    'VisualStudioVersion is not set, '
                    'please run within a Visual Studio Command Prompt.')
            supported_vsv = {
                '16.0': 'Visual Studio 16 2019',
                '15.0': 'Visual Studio 15 2017',
                '14.0': 'Visual Studio 14 2015',
            }
            if vsv not in supported_vsv:
                raise RuntimeError(
                    "Unknown / unsupported VS version '{vsv}'".format_map(
                        locals()))
            cmake_args += ['-G', supported_vsv[vsv]]
            # choose 'x64' on VS 14 and 15 if not specified explicitly
            # since otherwise 'Win32' is the default for those
            # newer versions default to the host architecture
            if '-A' not in cmake_args and vsv in ('14.0', '15.0'):
                cmake_args += ['-A', 'x64']
        if CMAKE_EXECUTABLE is None:
            raise RuntimeError("Could not find 'cmake' executable")
        os.makedirs(args.build_base, exist_ok=True)
        completed = await run(self.context, [CMAKE_EXECUTABLE] + cmake_args,
                              cwd=args.build_base,
                              env=env)
        return completed.returncode
コード例 #4
0
 def _get_msbuild_environment(self, args, env):
     generator = get_generator(args.build_base)
     if 'Visual Studio' in generator:
         if 'CL' in env:
             cl_split = env['CL'].split(' ')
             # check that /MP* isn't set already
             if any(x.startswith('/MP') for x in cl_split):
                 # otherwise avoid overriding existing parameters
                 return env
         else:
             cl_split = []
         # build with multiple processes using the number of processors
         cl_split.append('/MP')
         env = dict(env)
         env['CL'] = ' '.join(cl_split)
     return env
コード例 #5
0
    async def _build(self, args, env, *, additional_targets=None):
        self.progress('build')

        # invoke build step
        if CMAKE_EXECUTABLE is None:
            raise RuntimeError("Could not find 'cmake' executable")

        targets = []
        if args.cmake_target:
            targets.append(args.cmake_target)
        else:
            targets.append('')
            if additional_targets:
                targets += additional_targets

        multi_configuration_generator = is_multi_configuration_generator(
            args.build_base, args.cmake_args)
        if multi_configuration_generator:
            generator = get_generator(args.build_base)
            if 'Visual Studio' in generator:
                env = self._get_msbuild_environment(args, env)

        for i, target in enumerate(targets):
            cmd = [CMAKE_EXECUTABLE, '--build', args.build_base]
            if target:
                if args.cmake_target_skip_unavailable:
                    if not await has_target(args.build_base, target):
                        continue
                self.progress("build target '{target}'".format_map(locals()))
                cmd += ['--target', target]
            if i == 0 and args.cmake_clean_first:
                cmd += ['--clean-first']
            if multi_configuration_generator:
                cmd += ['--config', self._get_configuration(args)]
            else:
                job_args = self._get_make_arguments(env)
                if job_args:
                    cmd += ['--'] + job_args
            completed = await run(self.context,
                                  cmd,
                                  cwd=args.build_base,
                                  env=env)
            if completed.returncode:
                return completed.returncode