コード例 #1
0
    def test_add_include_cmake(self):
        """Add Include CMake File"""

        self.data_test['cmake'] = get_cmake_lists(context, self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.add_include_cmake('path/to/file.cmake')
        self.data_test['cmake'].close()

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

        self.assertTrue('include("path/to/file.cmake")' in content_test)
コード例 #2
0
    def test_collects_source_files(self):
        """Collects Source Files"""

        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        self.assertFalse(under_test.sources)
        self.assertFalse(under_test.headers)

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

        self.assertTrue(under_test.sources)
        self.assertTrue(under_test.headers)
コード例 #3
0
    def test_write_source_files(self):
        """Write Source Files"""

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

        under_test.write_source_files()

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

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

        self.assertTrue('GLOB SRC_FILES' in content_test)
        self.assertTrue('CPP_DIR_1' in content_test)
        self.assertTrue('HEADER_DIR_1' in content_test)
コード例 #4
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()
コード例 #5
0
    def test_write_source_files(self):
        """Write Source Files"""

        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.write_files_variables()
        under_test.write_source_files()

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

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

        self.assertTrue('GLOB SRC_FILES' in content_test)
        self.assertTrue('CPP_DIR_1' in content_test)
        self.assertTrue('HEADER_DIR_1' in content_test)
コード例 #6
0
    def test_add_artefacts(self):
        """Add Artefact Target"""

        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.add_target_artefact()

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

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

        self.assertTrue('add_library(${PROJECT_NAME} SHARED' in content_test)
        self.assertTrue('${SRC_FILES}' in content_test)

        cmakelists_test.close()
コード例 #7
0
    def test_add_artefacts(self):
        """Add Artefact Target"""

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

        under_test.add_target_artefact()

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

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

        self.assertTrue('add_library(${PROJECT_NAME} SHARED' in content_test)
        self.assertTrue('${SRC_FILES}' in content_test)

        cmakelists_test.close()
コード例 #8
0
    def test_write_variables(self):
        """Write Files Variables"""

        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.write_files_variables()

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

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

        self.assertTrue('CPP_DIR_1' in content_test)
        self.assertTrue('HEADER_DIR_1' in content_test)

        cmakelists_test.close()
コード例 #9
0
    def test_add_additional_code(self):
        """Add Additional CMake Code"""

        # When file is empty, nothing is added
        self.data_test['cmake'] = get_cmake_lists(context, self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.add_additional_code(context, '')

        under_test.cmake.close()

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

        self.assertEqual('', content_test)
        cmakelists_test.close()

        # When file exist, code is added
        under_test.cmake = get_cmake_lists(context, self.cur_dir)
        under_test.add_additional_code(
            context, '%s/datatest/additional_code_test.cmake' % self.cur_dir)

        under_test.cmake.close()

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

        self.assertTrue('set(ADD_CODE code)' in content_test)

        cmakelists_test.close()

        # When file does not exist, nothing is added
        under_test.cmake = get_cmake_lists(context, self.cur_dir)
        under_test.add_additional_code(context,
                                       'nofile/additional_code_test.cmake')

        under_test.cmake.close()

        cmakelists_add_test = open('%s/CMakeLists.txt' % self.cur_dir)
        content_add_test = cmakelists_add_test.read()

        self.assertEqual('', content_add_test)

        cmakelists_test.close()
コード例 #10
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()
コード例 #11
0
    def test_init_project_files(self):
        """Initialize Project Files"""

        under_test = ProjectFiles(self.data_test)

        self.assertTrue(under_test.c_folder_nb)
        self.assertTrue(under_test.h_folder_nb)

        self.assertTrue(under_test.tree)
        self.assertTrue(under_test.ns)
        self.assertTrue(under_test.cmake)
        self.assertTrue(under_test.cppfiles)
        self.assertTrue(under_test.headerfiles)
コード例 #12
0
    def test_init_project_files(self):
        """Initialize Project Files"""

        under_test = ProjectFiles(self.data_test)

        self.assertTrue(under_test.tree)
        self.assertTrue(under_test.ns)
        self.assertTrue(under_test.cmake)
        self.assertTrue(under_test.cppfiles)
        self.assertTrue(under_test.headerfiles)

        self.assertFalse(under_test.language)
        self.assertFalse(under_test.sources)
        self.assertFalse(under_test.headers)
コード例 #13
0
    def test_add_additional_code(self):
        """Add Additional CMake Code"""

        # When file is empty, nothing is added
        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.add_additional_code('')

        under_test.cmake.close()

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

        self.assertEqual('', content_test)
        cmakelists_test.close()

        # When file exist, code is added
        under_test.cmake = get_cmake_lists(self.cur_dir)
        under_test.add_additional_code('%s/test_files/additional_code_test.cmake' % self.cur_dir)

        under_test.cmake.close()

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

        self.assertTrue('set(ADD_CODE code)' in content_test)

        cmakelists_test.close()

        # When file does not exist, nothing is added
        under_test.cmake = get_cmake_lists(self.cur_dir)
        under_test.add_additional_code('nofile/additional_code_test.cmake')

        under_test.cmake.close()

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

        self.assertEqual('', content_add_test)

        cmakelists_test.close()
コード例 #14
0
    def test_write_source_files(self):
        """Write Source Files"""

        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectFiles(self.data_test)

        under_test.collects_source_files()
        under_test.write_source_files()

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

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

        self.assertTrue(
            'source_group("Sources" FILES ${SRC_FILES})' in content_test)
        self.assertTrue(
            'source_group("Headers" FILES ${HEADERS_FILES})' in content_test)
コード例 #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()

        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()