Exemple #1
0
    def test_write_flags(self):
        """Write Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = Flags(self.data_test)
        self.assertFalse(under_test.win_deb_flags)
        self.assertFalse(under_test.win_rel_flags)

        under_test.write_flags()

        self.assertTrue(under_test.win_deb_flags)
        self.assertEqual(' /W4 /MD /Od /Zi /EHsc', under_test.win_deb_flags)
        self.assertTrue(under_test.win_rel_flags)
        self.assertEqual(' /W4 /GL /Od /Oi /Gy /Zi /EHsc',
                         under_test.win_rel_flags)

        self.data_test['cmake'].close()

        cmakelists_test = open('CMakeLists.txt', 'r')
        content_test = cmakelists_test.read()

        self.assertTrue(' /W4 /MD /Od /Zi /EHsc' in content_test)
        self.assertTrue(' /W4 /GL /Od /Oi /Gy /Zi /EHsc' in content_test)

        cmakelists_test.close()
Exemple #2
0
    def test_define_group_properties(self):
        """Define XML Groups Properties"""

        under_test = Flags(self.data_test)

        self.assertIsNone(under_test.propertygroup['debug']['x86'])
        self.assertIsNone(under_test.propertygroup['debug']['x64'])
        self.assertIsNone(under_test.propertygroup['release']['x86'])
        self.assertIsNone(under_test.propertygroup['release']['x64'])

        self.assertIsNone(under_test.definitiongroups['debug']['x86'])
        self.assertIsNone(under_test.definitiongroups['debug']['x64'])
        self.assertIsNone(under_test.definitiongroups['release']['x86'])
        self.assertIsNone(under_test.definitiongroups['release']['x64'])

        under_test.define_group_properties()

        self.assertIsNotNone(under_test.propertygroup['debug']['x86'])
        self.assertIsNotNone(under_test.propertygroup['debug']['x64'])
        self.assertIsNotNone(under_test.propertygroup['release']['x86'])
        self.assertIsNotNone(under_test.propertygroup['release']['x64'])

        self.assertIsNotNone(under_test.definitiongroups['debug']['x86'])
        self.assertIsNotNone(under_test.definitiongroups['debug']['x64'])
        self.assertIsNotNone(under_test.definitiongroups['release']['x86'])
        self.assertIsNotNone(under_test.definitiongroups['release']['x64'])

        property_test = '//ns:PropertyGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'" and @Label="Configuration"]'
        self.assertEqual(property_test,
                         under_test.propertygroup['debug']['x86'])

        definition_test = '//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'"]'
        self.assertEqual(definition_test,
                         under_test.definitiongroups['debug']['x86'])
Exemple #3
0
    def test_set_warning_level(self):
        """Set Warning Level Flag"""

        under_test = Flags(self.data_test)

        under_test.set_warning_level()

        self.assertTrue('/W4' in under_test.win_deb_flags)
        self.assertTrue('/W4' in under_test.win_rel_flags)
Exemple #4
0
    def test_set_function_level_linking(self):
        """Set Function Level Linking"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_function_level_linking()

        self.assertTrue('/Gy' in under_test.win_rel_flags)
Exemple #5
0
    def test_set_warning_level(self):
        """Set Warning Level Flag"""

        under_test = Flags(self.data_test)

        under_test.set_warning_level()

        self.assertTrue('/W4' in under_test.win_deb_flags)
        self.assertTrue('/W4' in under_test.win_rel_flags)
Exemple #6
0
    def test_set_whole_program_optimization(self):
        """Set Whole Program Optimization Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_whole_program_optimization()

        self.assertFalse('/GL' in under_test.win_deb_flags)
        self.assertTrue('/GL' in under_test.win_rel_flags)
Exemple #7
0
    def test_set_use_debug_libraries(self):
        """Set Use Debug Libraries Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_use_debug_libraries()

        self.assertTrue('/MD' in under_test.win_deb_flags)
        self.assertFalse('/MD' in under_test.win_rel_flags)
Exemple #8
0
    def test_set_runtime_library(self):
        """Set Runtime Library Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_runtime_library()

        self.assertFalse('/MDd' in under_test.win_deb_flags)
        self.assertFalse('/MDd' in under_test.win_rel_flags)
Exemple #9
0
    def test_set_optimization(self):
        """Set Optimization Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_optimization()

        self.assertTrue('/Od' in under_test.win_deb_flags)
        self.assertTrue('/Od' in under_test.win_rel_flags)
Exemple #10
0
    def test_set_intrinsic_functions(self):
        """Set Intrinsic Functions Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_intrinsic_functions()

        self.assertFalse('/Oi' in under_test.win_deb_flags)
        self.assertTrue('/Oi' in under_test.win_rel_flags)
Exemple #11
0
    def test_set_runtime_type_info(self):
        """Set runtime Type Info Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_runtime_type_info()

        self.assertFalse('/GR' in under_test.win_deb_flags)
        self.assertFalse('/GR' in under_test.win_rel_flags)
Exemple #12
0
    def test_set_generate_debug_information(self):
        """Set Generate Debug Information"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_generate_debug_information()

        self.assertTrue('/Zi' in under_test.win_deb_flags)
        self.assertTrue('/Zi' in under_test.win_rel_flags)
Exemple #13
0
    def test_set_exception_handling(self):
        """Set Exception Handling"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_exception_handling()

        self.assertTrue('/EHsc' in under_test.win_deb_flags)
        self.assertTrue('/EHsc' in under_test.win_rel_flags)
Exemple #14
0
    def test_define_linux_flags_with_std(self):
        """Define Linux Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        self.data_test['std'] = 'c++17'
        under_test = Flags(self.data_test)
        under_test.define_linux_flags()
        self.data_test['cmake'].close()

        cmakelists_test = open('%s/CMakeLists.txt' % self.cur_dir, 'r')
        content_test = cmakelists_test.read()

        self.assertTrue('-std=c++17' in content_test)
        cmakelists_test.close()

        self.data_test['cmake'] = get_cmake_lists('./')
        self.data_test['std'] = 'c++19'
        under_test = Flags(self.data_test)
        under_test.define_linux_flags()
        self.data_test['cmake'].close()

        cmakelists_test = open('%s/CMakeLists.txt' % self.cur_dir, 'r')
        content_test = cmakelists_test.read()

        self.assertTrue('-std=c++11' in content_test)
        cmakelists_test.close()
Exemple #15
0
    def create_data(self):
        """
        Create the data and convert each part of vcxproj project

        """

        # Write variables
        variables = ProjectVariables(self.data)
        variables.add_project_variables()
        variables.add_outputs_variables()

        files = ProjectFiles(self.data)
        files.write_files_variables()
        variables.add_cmake_project(files.language)
        variables.add_default_target()

        # Write Macro
        define_and_write_macro(self.data)

        # Write Output Variables
        variables.add_artefact_target_outputs()

        # Write Include Directories
        depends = Dependencies(self.data)
        if self.data['includes']:
            depends.write_include_dir()
        else:
            send('Include Directories is not set.', '')

        # Write Dependencies
        depends.write_dependencies()

        # Add additional code or not
        if self.data['additional_code'] is not None:
            files.add_additional_code(self.data['additional_code'])

        # Write Flags
        all_flags = Flags(self.data)
        all_flags.write_flags()

        # Write and add Files
        files.write_source_files()
        files.add_target_artefact()

        # Link with other dependencies
        depends.link_dependencies()
Exemple #16
0
    def write_data(context, cmake_file):
        """
        Write data defined in converter.

        :param context: converter context
        :type context: Context
        :param cmake_file: CMakeLists IO wrapper
        :type cmake_file: _io.TextIOWrapper
        """

        context.files.write_cmake_project(context, cmake_file)

        # Add additional code or not
        if context.additional_code is not None:
            context.files.add_additional_code(context, context.additional_code,
                                              cmake_file)

        context.files.write_source_groups(context, cmake_file)

        if not context.has_only_headers:
            write_comment(cmake_file, 'Target')
            context.flags.write_target_artifact(context, cmake_file)
            context.flags.write_use_pch_function(context, cmake_file)
            context.dependencies.write_target_property_sheets(
                context, cmake_file)
            context.variables.write_target_outputs(context, cmake_file)
            context.dependencies.write_include_directories(context, cmake_file)
            context.flags.write_defines(context, cmake_file)
            context.flags.write_flags(context, cmake_file)
            context.dependencies.write_target_pre_build_events(
                context, cmake_file)
            context.dependencies.write_target_pre_link_events(
                context, cmake_file)
            context.dependencies.write_target_post_build_events(
                context, cmake_file)
            context.dependencies.write_custom_build_events_of_files(
                context, cmake_file)
            if (context.target_references or context.add_lib_deps
                    or context.sln_deps or context.packages):
                write_comment(cmake_file, 'Dependencies')
            context.dependencies.write_target_references(context, cmake_file)
            context.dependencies.write_link_dependencies(context, cmake_file)
            context.dependencies.write_target_dependency_packages(
                context, cmake_file)
        else:
            Flags.write_target_headers_only_artifact(context, cmake_file)
    def create_data(self):
        """
        Create the data and convert each part of "vcxproj" project

        """

        # Write variables
        variables = ProjectVariables(self.data)
        variables.add_project_variables()
        variables.add_outputs_variables()

        files = ProjectFiles(self.data)
        files.write_files_variables()
        variables.add_cmake_project(files.language)
        variables.add_default_target()

        # Write Macro
        define_and_write_macro(self.data)

        # Write Output Variables
        variables.add_artefact_target_outputs()

        # Write Include Directories
        depends = Dependencies(self.data)
        if self.data['includes']:
            depends.write_include_dir()
        else:
            send('Include Directories is not set.', '')

        # Write Dependencies
        depends.write_dependencies()

        # Add additional code or not
        if self.data['additional_code'] is not None:
            files.add_additional_code(self.data['additional_code'])

        # Write Flags
        all_flags = Flags(self.data)
        all_flags.write_flags()

        # Write and add Files
        files.write_source_files()
        files.add_target_artefact()

        # Link with other dependencies
        depends.link_dependencies()
Exemple #18
0
    def test_define_linux_flags(self):
        """Define Linux Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = Flags(self.data_test)

        under_test.define_linux_flags()
        self.data_test['cmake'].close()

        self.assertFalse(under_test.win_deb_flags)
        self.assertFalse(under_test.win_rel_flags)

        cmakelists_test = open('CMakeLists.txt', 'r')
        content_test = cmakelists_test.read()

        self.assertTrue('-std=c++11 -fPIC' in content_test)

        cmakelists_test.close()
Exemple #19
0
    def test_define_linux_flags(self):
        """Define Linux Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = Flags(self.data_test)

        under_test.define_linux_flags()
        self.data_test['cmake'].close()

        self.assertFalse(under_test.win_deb_flags)
        self.assertFalse(under_test.win_rel_flags)

        cmakelists_test = open('CMakeLists.txt', 'r')
        content_test = cmakelists_test.read()

        self.assertTrue('-std=c++11 -fPIC' in content_test)

        cmakelists_test.close()
Exemple #20
0
    def test_define_windows_flags(self):
        """Define Windows Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.define_windows_flags()
        self.data_test['cmake'].close()

        self.assertTrue(under_test.win_deb_flags)
        self.assertTrue(under_test.win_rel_flags)

        cmakelists_test = open('CMakeLists.txt', 'r')
        content_test = cmakelists_test.read()

        self.assertFalse('-std=c++11 -fPIC' in content_test)
        self.assertTrue(' /W4 /MD /Od /Zi /EHsc' in content_test)
        self.assertTrue(' /W4 /GL /Od /Oi /Gy /Zi /EHsc' in content_test)

        cmakelists_test.close()
Exemple #21
0
    def test_define_linux_flags_with_std(self):
        """Define Linux Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        self.data_test['std'] = 'c++17'
        under_test = Flags(self.data_test)
        under_test.define_linux_flags()
        self.data_test['cmake'].close()

        cmakelists_test = open('%s/CMakeLists.txt' % self.cur_dir, 'r')
        content_test = cmakelists_test.read()

        self.assertTrue('-std=c++17' in content_test)
        cmakelists_test.close()

        self.data_test['cmake'] = get_cmake_lists('./')
        self.data_test['std'] = 'c++19'
        under_test = Flags(self.data_test)
        under_test.define_linux_flags()
        self.data_test['cmake'].close()

        cmakelists_test = open('%s/CMakeLists.txt' % self.cur_dir, 'r')
        content_test = cmakelists_test.read()

        self.assertTrue('-std=c++11' in content_test)
        cmakelists_test.close()
Exemple #22
0
    def test_set_function_level_linking(self):
        """Set Function Level Linking"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_function_level_linking()

        self.assertTrue('/Gy' in under_test.win_rel_flags)
Exemple #23
0
    def test_define_group_properties(self):
        """Define XML Groups Properties"""

        under_test = Flags(self.data_test)

        self.assertIsNone(under_test.propertygroup['debug']['x86'])
        self.assertIsNone(under_test.propertygroup['debug']['x64'])
        self.assertIsNone(under_test.propertygroup['release']['x86'])
        self.assertIsNone(under_test.propertygroup['release']['x64'])

        self.assertIsNone(under_test.definitiongroups['debug']['x86'])
        self.assertIsNone(under_test.definitiongroups['debug']['x64'])
        self.assertIsNone(under_test.definitiongroups['release']['x86'])
        self.assertIsNone(under_test.definitiongroups['release']['x64'])

        under_test.define_group_properties()

        self.assertIsNotNone(under_test.propertygroup['debug']['x86'])
        self.assertIsNotNone(under_test.propertygroup['debug']['x64'])
        self.assertIsNotNone(under_test.propertygroup['release']['x86'])
        self.assertIsNotNone(under_test.propertygroup['release']['x64'])

        self.assertIsNotNone(under_test.definitiongroups['debug']['x86'])
        self.assertIsNotNone(under_test.definitiongroups['debug']['x64'])
        self.assertIsNotNone(under_test.definitiongroups['release']['x86'])
        self.assertIsNotNone(under_test.definitiongroups['release']['x64'])

        property_test = \
            '//ns:PropertyGroup[@Condition="\'$(Configuration)|$(Platform)\'==\'Debug|Win32\'"' \
            ' and @Label="Configuration"]'
        self.assertEqual(property_test, under_test.propertygroup['debug']['x86'])

        definition_test = \
            '//ns:ItemDefinitionGroup[@Condition="\'$(Configuration)|' \
            '$(Platform)\'==\'Debug|Win32\'"]'
        self.assertEqual(definition_test, under_test.definitiongroups['debug']['x86'])
Exemple #24
0
    def test_write_flags(self):
        """Write Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = Flags(self.data_test)
        self.assertFalse(under_test.win_deb_flags)
        self.assertFalse(under_test.win_rel_flags)

        under_test.write_flags()

        self.assertTrue(under_test.win_deb_flags)
        self.assertEqual(' /W4 /MD /Od /Zi /EHsc', under_test.win_deb_flags)
        self.assertTrue(under_test.win_rel_flags)
        self.assertEqual(' /W4 /GL /Od /Oi /Gy /Zi /EHsc', under_test.win_rel_flags)

        self.data_test['cmake'].close()

        cmakelists_test = open('CMakeLists.txt', 'r')
        content_test = cmakelists_test.read()

        self.assertTrue(' /W4 /MD /Od /Zi /EHsc' in content_test)
        self.assertTrue(' /W4 /GL /Od /Oi /Gy /Zi /EHsc' in content_test)

        cmakelists_test.close()
    def create_data(self):
        """
        Create the data and convert each part of "vcxproj" project

        """

        # Write variables
        variables = ProjectVariables(self.data)
        variables.add_project_variables()

        files = ProjectFiles(self.data)
        files.collects_source_files()
        variables.add_cmake_project(files.language)
        variables.add_default_target()

        # Write Output Variables
        variables.add_cmake_output_directories()
        variables.write_project_messages()

        # Add includes files & directories
        if self.data['includecmake'] or self.data['include']:
            title = get_title('Includes', 'Include files and directories')
            self.data['cmake'].write(title)
        # Include ".cmake" file
        if self.data['includecmake']:
            files.add_include_cmake(self.data['includecmake'])
        # Write Include Directories
        depends = Dependencies(self.data)
        if self.data['include']:
            depends.write_include_dir()
        else:
            message('Include Directories is not set.', '')

        # Write Dependencies
        depends.write_dependencies()

        # Add additional code
        if self.data['additional'] is not None:
            files.add_additional_code(self.data['additional'])

        # Write and add Files
        files.write_source_files()
        if files.sources:
            files.add_target_artefact()
            # Write Flags
            all_flags = Flags(self.data)
            all_flags.write_flags()
            # Write Macro
            all_flags.write_defines_and_flags()

        # Link with other dependencies
        title = get_title('Link & Dependencies',
                          'Add project dependencies and Link to project')
        self.data['cmake'].write(title)
        depends.add_dependencies()
        depends.link_dependencies()
Exemple #26
0
    def test_set_whole_program_optimization(self):
        """Set Whole Program Optimization Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_whole_program_optimization()

        self.assertFalse('/GL' in under_test.win_deb_flags)
        self.assertTrue('/GL' in under_test.win_rel_flags)
Exemple #27
0
    def test_set_use_debug_libraries(self):
        """Set Use Debug Libraries Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_use_debug_libraries()

        self.assertTrue('/MD' in under_test.win_deb_flags)
        self.assertFalse('/MD' in under_test.win_rel_flags)
Exemple #28
0
    def test_set_runtime_library(self):
        """Set Runtime Library Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_runtime_library()

        self.assertFalse('/MDd' in under_test.win_deb_flags)
        self.assertFalse('/MDd' in under_test.win_rel_flags)
Exemple #29
0
    def test_set_optimization(self):
        """Set Optimization Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_optimization()

        self.assertTrue('/Od' in under_test.win_deb_flags)
        self.assertTrue('/Od' in under_test.win_rel_flags)
Exemple #30
0
    def test_set_exception_handling(self):
        """Set Exception Handling"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_exception_handling()

        self.assertTrue('/EHsc' in under_test.win_deb_flags)
        self.assertTrue('/EHsc' in under_test.win_rel_flags)
Exemple #31
0
    def test_set_runtime_type_info(self):
        """Set runtime Type Info Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_runtime_type_info()

        self.assertFalse('/GR' in under_test.win_deb_flags)
        self.assertFalse('/GR' in under_test.win_rel_flags)
Exemple #32
0
    def test_set_generate_debug_information(self):
        """Set Generate Debug Information"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_generate_debug_information()

        self.assertTrue('/Zi' in under_test.win_deb_flags)
        self.assertTrue('/Zi' in under_test.win_rel_flags)
Exemple #33
0
    def test_set_intrinsic_functions(self):
        """Set Intrinsic Functions Flag"""

        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.set_intrinsic_functions()

        self.assertFalse('/Oi' in under_test.win_deb_flags)
        self.assertTrue('/Oi' in under_test.win_rel_flags)
Exemple #34
0
    def test_init_dependencies(self):
        """Initialize Flags"""

        under_test = Flags(self.data_test)

        self.assertIsNotNone(under_test.tree)
        self.assertIsNotNone(under_test.ns)

        self.assertIsNotNone(under_test.propertygroup)
        self.assertTrue('debug' in under_test.propertygroup)
        self.assertTrue('release' in under_test.propertygroup)

        self.assertIsNotNone(under_test.definitiongroups)
        self.assertTrue('debug' in under_test.definitiongroups)
        self.assertTrue('release' in under_test.definitiongroups)

        self.assertFalse(under_test.win_deb_flags)
        self.assertFalse(under_test.win_rel_flags)
Exemple #35
0
    def test_define_group_properties(self):
        """Define XML Groups Properties"""

        under_test = Flags(self.data_test)

        self.assertFalse(under_test.propertygroup)
        self.assertFalse(under_test.definitiongroups)

        under_test.define_settings()
        under_test.define_group_properties()

        self.assertTrue(under_test.propertygroup)
        self.assertTrue(under_test.definitiongroups)
Exemple #36
0
    def test_define_windows_flags(self):
        """Define Windows Flags"""

        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = Flags(self.data_test)

        under_test.define_group_properties()
        under_test.define_windows_flags()
        self.data_test['cmake'].close()

        self.assertTrue(under_test.win_deb_flags)
        self.assertTrue(under_test.win_rel_flags)

        cmakelists_test = open('CMakeLists.txt', 'r')
        content_test = cmakelists_test.read()

        self.assertFalse('-std=c++11 -fPIC' in content_test)
        self.assertTrue(' /W4 /MD /Od /Zi /EHsc' in content_test)
        self.assertTrue(' /W4 /GL /Od /Oi /Gy /Zi /EHsc' in content_test)

        cmakelists_test.close()