Example #1
0
    def add_target_property_sheet(context, attr_name, filename, node):
        """
        Find and set in current context property sheets

        :param context:
        :param attr_name:
        :param filename:
        :param node:
        :return:
        """

        del attr_name, node

        if 'Microsoft' in filename:  # ignore props provided by Microsoft
            return
        if filename[-8:] == '.targets':  # ignore targets files
            return

        working_path = os.path.dirname(context.vcxproj_path)
        props_cmake_path = normalize_path(context, working_path, filename,
                                          False).replace('.props', '.cmake')
        props_cmake_path = cleaning_output(context, props_cmake_path)
        message(context,
                'cmake from property sheet: {}'.format(props_cmake_path), '')
        context.settings[context.current_setting]['property_sheets'].append(
            props_cmake_path)
    def set_additional_include_directories(aid_text, setting, context):
        """
        Return additional include directories of given context

        :param aid_text: path to sources
        :type aid_text: str
        :param setting: current setting (Debug|x64, Release|Win32,...)
        :type setting: str
        :param context: current context
        :type context: Context
        :return: include directories of context, separated by semicolons
        :rtype: str
        """

        if not aid_text:
            return

        working_path = os.path.dirname(context.vcxproj_path)
        inc_dir = resolve_path_variables_of_vs(context, aid_text)
        inc_dir = inc_dir.replace('%(AdditionalIncludeDirectories)', '')
        inc_dirs = context.settings[setting]['inc_dirs']
        dirs_raw = []
        for i in inc_dir.split(';'):
            if i:
                dirs_raw.append(i)
                i = normalize_path(context, working_path, i)
                i = replace_vs_vars_with_cmake_vars(context, i)
                inc_dirs.append(i)

        context.settings[setting]['inc_dirs_list'].extend(dirs_raw)

        if inc_dirs:
            message(
                context, 'Include Directories : {0}'.format(
                    context.settings[setting]['inc_dirs']), '')
    def add_file_from_node(self, context, **kwargs):
        """
        Adds file into source group and creates file context using into from xml node
        """
        files_container = kwargs['files_container']
        file_node = kwargs['file_node']
        file_node_attr = kwargs['file_node_attr']
        source_group = kwargs['source_group']

        if file_node.get(file_node_attr) is not None:
            node_text = str(file_node.get(file_node_attr))
            if not node_text.rpartition('.')[-1] in self.languages:
                self.languages.append(node_text.rpartition('.')[-1])
            file_path, file_name = ntpath.split(node_text)
            vcxproj_dir = os.path.dirname(context.vcxproj_path)
            file_path = normalize_path(context, vcxproj_dir, file_path, False,
                                       False)
            if file_path not in self.file_lists:
                self.file_lists[file_path] = []
                if os.path.exists(os.path.join(vcxproj_dir, file_path)):
                    self.file_lists[file_path] = os.listdir(
                        os.path.join(vcxproj_dir, file_path))
            if file_path not in files_container:
                files_container[file_path] = []
            if file_name not in files_container[file_path]:
                return self.__add_file_into_container(
                    context,
                    files_container=files_container,
                    file_path=file_path,
                    file_name=file_name,
                    source_group=source_group)
        return None
Example #4
0
    def __set_additional_options(self, context, flag_name, flag_value):
        """
        Set Additional options

        """
        # for setting in context.settings:
        add_opts = flag_value
        if add_opts:
            add_opts = set_unix_slash(add_opts).split()
            ready_add_opts = []
            for add_opt in add_opts:
                add_opt = add_opt.strip()
                if '/Qprof-dir' in add_opt:
                    name_value = add_opt.split(':')
                    prof_dir = normalize_path(
                        context, os.path.dirname(context.vcxproj_path),
                        name_value[1])
                    prof_dir = cleaning_output(context, prof_dir)
                    add_opt = name_value[0] + ':' + prof_dir

                add_opt = '-' + add_opt[1:]
                ready_add_opts.append(add_opt)
                unix_option = add_opt.replace(':', ' ')
                if 'gen-interfaces' in unix_option:
                    pass
                elif 'Qprec-div' in unix_option:
                    unix_option = FortranFlags.__get_no_prefix(
                        unix_option) + '-prec-div'
                elif unix_option == '-static':
                    pass
                elif 'Qprof-dir' in unix_option:
                    unix_option = unix_option.replace('Qprof-dir', 'prof-dir')
                elif 'Qprof-gen' in unix_option:
                    unix_option = unix_option.replace('Qprof-gen', 'prof-gen')
                elif 'Qprof-use' in unix_option:
                    unix_option = unix_option.replace('Qprof-use', 'prof-use')
                elif 'Qprec-sqrt' in unix_option:
                    unix_option = FortranFlags.__get_no_prefix(
                        unix_option) + '-prec-sqrt'
                elif 'Qopenmp-lib' in unix_option:
                    unix_option = unix_option.replace('Qopenmp-lib',
                                                      'qopenmp-lib')
                    unix_option = unix_option.replace('lib ', 'lib=')
                else:
                    message(
                        context, 'Unix ifort option "{0}" may be incorrect. '
                        'Check it and set it with visual studio UI if possible.'
                        .format(unix_option), 'warn')
                if ifort_cl_win not in self.flags[flag_name]:
                    self.flags[flag_name][ifort_cl_win] = []
                self.flags[flag_name][ifort_cl_win].append(add_opt)
                if ifort_cl_unix not in self.flags[flag_name]:
                    self.flags[flag_name][ifort_cl_unix] = []
                self.flags[flag_name][ifort_cl_unix].append(unix_option)
            message(context,
                    'Additional Options : {0}'.format(str(ready_add_opts)), '')
Example #5
0
    def write_precompiled_headers(context, setting, cmake_file):
        """
        Write precompiled headers, if needed, on given CMake file

        :param context: converter Context
        :type context: Context
        :param setting: related setting (Release|x64, Debug|Win32,...)
        :type setting: str
        :param cmake_file: CMakeLIsts.txt IO wrapper
        :type cmake_file: _io.TextIOWrapper
        """

        pch_header = context.settings[setting]['PrecompiledHeaderFile']
        pch_source = context.settings[setting]['PrecompiledSourceFile']
        working_path = os.path.dirname(context.vcxproj_path)
        cmake_file.write(
            'add_precompiled_header(${{PROJECT_NAME}} "{0}" "{1}")\n\n'.format(
                os.path.basename(pch_header),
                normalize_path(context, working_path, pch_source, False)))
    def set_target_additional_library_directories(
            context, additional_library_directories):
        """
        Find and set additional library directories in context

        """

        list_depends = additional_library_directories.text.replace(
            '%(AdditionalLibraryDirectories)', '')
        working_path = os.path.dirname(context.vcxproj_path)
        if list_depends != '':
            add_lib_dirs = []
            for d in list_depends.split(';'):
                d = d.strip()
                if d:
                    d = normalize_path(context, working_path, d)
                    #d = check_for_relative_in_path(context, cleaning_output(context, d))
                    add_lib_dirs.append(d)
            message(context,
                    'Additional Library Directories = {}'.format(add_lib_dirs),
                    '')
            context.settings[
                context.current_setting]['target_link_dirs'] = add_lib_dirs
    def __add_file_into_container(self, context, **kwargs):

        files_container = kwargs['files_container']
        file_path = kwargs['file_path']
        file_name = kwargs['file_name']
        source_group = kwargs['source_group']

        real_name = take_name_from_list_case_ignore(context,
                                                    self.file_lists[file_path],
                                                    file_name)
        if real_name:
            name_to_add = real_name
        else:
            name_to_add = file_name
            message(
                context,
                'Adding absent {} file into project files'.format(file_name),
                'warn')

        files_container[file_path].append(name_to_add)
        if file_path:
            file_path = file_path + '/'
        file_path_name = file_path + name_to_add
        working_path = os.path.dirname(context.vcxproj_path)
        file_path_name = normalize_path(context, working_path, file_path_name,
                                        False)
        if source_group not in context.source_groups:
            context.source_groups[source_group] = []
        context.source_groups[source_group].append(file_path_name)
        context.source_groups[source_group].sort(key=str.lower)
        if real_name:
            self.include_directive_case_check(
                context, file_path_name, self.file_lists_for_include_paths)
        context.file_contexts[file_path_name] = self.__create_file_context(
            context)
        return context.file_contexts[file_path_name]