def install_section_check(cmake, items, install_type, directory=False, subfolder=''): section_name, destination_map = INSTALL_CONFIGS[install_type] if directory and section_name == 'FILES': section_name = 'DIRECTORY' cmds = get_commands_by_type(cmake, install_type, subfolder) if len(items) == 0: for cmd in cmds: if len(get_install_types(cmd)) == 1: cmake.remove_command(cmd) else: remove_install_section(cmd, destination_map) return cmd = None items = [os.path.join(subfolder, item) for item in items] for cmd in cmds: install_sections(cmd, destination_map, subfolder) section = cmd.get_section(section_name) if not section: if section_name != 'FILES': continue section = cmd.get_section('DIRECTORY') if not section: continue pattern = get_multiword_section(cmd, ['FILES_MATCHING', 'PATTERN']) nonmatching_items = [] for item in items: if pattern and not matches_patterns(item, pattern.values): nonmatching_items.append(item) items = nonmatching_items else: # We match the section section.values = [ value for value in section.values if value in items ] items = [item for item in items if item not in section.values] if len(items) == 0: return print '\tInstalling', ', '.join(items) if cmd is None: cmd = Command('install') cmd.add_section(section_name, items) cmake.add_command(cmd) install_sections(cmd, destination_map, subfolder) elif section: section = cmd.get_section(section_name) section.values += items section.changed = True
def target_catkin_libraries(package): CATKIN = '${catkin_LIBRARIES}' targets = package.cmake.get_libraries() + package.cmake.get_executables() for cmd in package.cmake.content_map['target_link_libraries']: tokens = cmd.get_tokens() if tokens[0] in targets: if CATKIN not in tokens: print '\tAdding %s to target_link_libraries for %s' % ( CATKIN, tokens[0]) cmd.add_token(CATKIN) targets.remove(tokens[0]) continue for target in targets: print '\tAdding target_link_libraries for %s' % target cmd = Command('target_link_libraries') cmd.add_section('', [target, CATKIN]) package.cmake.add_command(cmd)
def check_setup_py(package): if not has_python(package): return if package.setup_py is None: if not has_python_library(package): # No library, and no existing setup_py means nothing to write return package.setup_py = SetupPy(package.name, os.path.join(package.root, 'setup.py')) if 'catkin_python_setup' not in package.cmake.content_map: package.cmake.add_command(Command('catkin_python_setup'))
def check_exported_dependencies(package): targets = package.cmake.get_target_build_rules() for target, sources in targets.iteritems(): deps = get_msg_dependencies_from_source(package, sources) if len(deps) == 0: continue if package.name in deps: self_depend = True if len(deps) == 1: cat_depend = False else: cat_depend = True else: self_depend = False cat_depend = True add_deps = get_matching_add_depends(package.cmake, target) add_add_deps = False if add_deps is None: add_deps = Command('add_dependencies') add_add_deps = True # Need to wait to add the command for proper sorting if len(add_deps.sections) == 0: add_deps.add_section('', [target]) add_deps.changed = True section = add_deps.sections[0] if cat_depend and '${catkin_EXPORTED_TARGETS}' not in section.values: section.add('${catkin_EXPORTED_TARGETS}') add_deps.changed = True if self_depend: tokens = [ package.cmake.resolve_variables(s) for s in section.values ] key = '${%s_EXPORTED_TARGETS}' % package.name if key not in tokens: section.add(key) add_deps.changed = True if add_add_deps: package.cmake.add_command(add_deps)
def update_python_installs(package): execs = [ source.rel_fn for source in package.source_code.get_source_by_language('python') if source.is_executable() ] if len(execs) == 0: return cmd = 'catkin_install_python' if cmd not in package.cmake.content_map: cmake_cmd = Command(cmd) cmake_cmd.add_section('PROGRAMS', execs) cmake_cmd.add_section('DESTINATION', ['${CATKIN_PACKAGE_BIN_DESTINATION}']) package.cmake.add_command(cmake_cmd) else: package.cmake.section_check(execs, cmd, 'PROGRAMS')
def check_cmake_dependencies_helper(cmake, dependencies, check_catkin_pkg=True): if len(dependencies) == 0: return if len(cmake.content_map['find_package']) == 0: cmd = Command('find_package') cmd.add_section('', ['catkin']) cmd.add_section('REQUIRED') cmake.add_command(cmd) for cmd in cmake.content_map['find_package']: tokens = cmd.get_tokens() if tokens and tokens[0] == 'catkin' and cmd.get_section('REQUIRED'): section = cmd.get_section('COMPONENTS') if section is None: cmd.add_section('COMPONENTS', sorted(dependencies)) else: needed_items = dependencies - set(section.values) if len(needed_items) > 0: section.values += list(sorted(needed_items)) cmd.changed = True if check_catkin_pkg: cmake.section_check(dependencies, 'catkin_package', 'CATKIN_DEPENDS')