Пример #1
0
    def test_add_outputs_variables(self):
        """Add Outputs Variables"""

        # TODO If NO output is given
        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectVariables(self.data_test)

        under_test.add_output_variables()

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

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

        self.assertTrue('OUTPUT_DEBUG ../../../build/vc2017_x64d/bin/',
                        content_test)
        self.assertTrue(
            'OUTPUT_RELEASE ../../../build/vc2017_x64/bin/' in content_test)

        cmakelists_test.close()

        # If output is given
        # under_test.output = '../output_binaries'
        # under_test.cmake = get_cmake_lists(self.cur_dir)
        # under_test.add_outputs_directories()
        #
        # under_test.cmake.close()
        #
        # cmakelists_test = open('%s/CMakeLists.txt' % self.cur_dir)
        # content_test = cmakelists_test.read()
        #
        # self.assertTrue('OUTPUT_DEBUG ../output_binaries/${CMAKE_BUILD_TYPE}', content_test)
        # self.assertTrue('OUTPUT_REL ../output_binaries/${CMAKE_BUILD_TYPE}' in content_test)

        cmakelists_test.close()
    def test_add_artefact_target_outputs(self):
        """Add Artefact Target Outputs"""

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

        under_test.add_artefact_target_outputs()

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

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

        self.assertTrue(
            'set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")'
            in content_test)
        self.assertTrue(
            'set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")'
            in content_test)
        self.assertTrue(
            'set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}'
            in content_test)

        self.assertTrue(
            'set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")'
            in content_test)
        self.assertTrue(
            'set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")'
            in content_test)
        self.assertTrue(
            'set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}'
            in content_test)

        cmakelists_test.close()
    def test_add_artefact_target_outputs(self):
        """Add Artefact Target Outputs"""

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

        under_test.add_artefact_target_outputs()

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

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

        self.assertTrue(
            'set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")' in content_test
        )
        self.assertTrue(
            'set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")' in content_test
        )
        self.assertTrue(
            'set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}' in content_test
        )

        self.assertTrue(
            'set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")' in content_test
        )
        self.assertTrue(
            'set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")' in content_test
        )
        self.assertTrue(
            'set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}' in content_test
        )

        cmakelists_test.close()
    def test_add_outputs_variables(self):
        """Add Outputs Variables"""

        # If NO output is given
        self.data_test['cmake'] = get_cmake_lists(self.cur_dir)
        under_test = ProjectVariables(self.data_test)

        under_test.add_project_variables()
        under_test.add_outputs_variables()

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

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

        self.assertTrue('OUTPUT_DEBUG ../../../build/vc2017_x64d/bin/', content_test)
        self.assertTrue('OUTPUT_REL ../../../build/vc2017_x64/bin/' in content_test)

        cmakelists_test.close()

        # If output is given
        under_test.output = '../output_binaries'
        under_test.cmake = get_cmake_lists(self.cur_dir)
        under_test.add_outputs_variables()

        under_test.cmake.close()

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

        self.assertTrue('OUTPUT_DEBUG ../output_binaries/${CMAKE_BUILD_TYPE}', content_test)
        self.assertTrue('OUTPUT_REL ../output_binaries/${CMAKE_BUILD_TYPE}' in content_test)

        cmakelists_test.close()
    def test_add_default_target(self):
        """Add Release as Default Target"""

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

        under_test.add_default_target()

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

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

        self.assertTrue('set(CMAKE_BUILD_TYPE "Release")' in content_test)

        cmakelists_test.close()
    def test_add_default_target(self):
        """Add Release as Default Target"""

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

        under_test.add_default_target()

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

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

        self.assertTrue('set(CMAKE_BUILD_TYPE "Release")' in content_test)

        cmakelists_test.close()
Пример #7
0
    def test_add_project_variables(self):
        """Add Project Variables"""

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

        under_test.add_project_variables()

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

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

        self.assertTrue('set(PROJECT_NAME core)' in content_test)

        cmakelists_test.close()
    def test_add_project_variables(self):
        """Add Project Variables"""

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

        under_test.add_project_variables()

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

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

        self.assertTrue('cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)' in content_test)
        self.assertTrue('set(PROJECT_NAME core)' in content_test)

        cmakelists_test.close()
    def test_add_cmake_project(self):
        """Add CMake Project"""

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

        # Case CXX language
        under_test.add_cmake_project(['cpp'])

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

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

        self.assertTrue('project(${PROJECT_NAME} CXX)' in content_test)

        cmakelists_test.close()

        # Case C language
        under_test.cmake = get_cmake_lists(self.cur_dir)
        under_test.add_cmake_project(['c'])

        under_test.cmake.close()

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

        self.assertTrue('project(${PROJECT_NAME} C)' in content_test)

        cmakelists_test.close()
    def test_add_project_variables(self):
        """Add Project Variables"""

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

        under_test.add_project_variables()

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

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

        self.assertTrue('cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)' in
                        content_test)
        self.assertTrue('set(PROJECT_NAME core)' in content_test)

        cmakelists_test.close()
Пример #11
0
    def test_init_project_variables(self):
        """Initialize Project Variables"""

        under_test = ProjectVariables(self.data_test)

        self.assertTrue(under_test.tree)
        self.assertTrue(under_test.ns)
        self.assertTrue(under_test.cmake)
        self.assertFalse(under_test.output)
        self.assertIsNotNone(under_test.cmake_outputs)
    def test_add_cmake_project(self):
        """Add CMake Project"""

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

        # Case CXX language
        under_test.add_cmake_project(['cpp'])

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

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

        self.assertTrue('project(${PROJECT_NAME} CXX)' in content_test)

        cmakelists_test.close()

        # Case C language
        under_test.cmake = get_cmake_lists(self.cur_dir)
        under_test.add_cmake_project(['c'])

        under_test.cmake.close()

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

        self.assertTrue('project(${PROJECT_NAME} C)' in content_test)

        cmakelists_test.close()
    def test_add_outputs_variables(self):
        """Add Outputs Variables"""

        # If NO output is given
        self.data_test['cmake'] = get_cmake_lists('./')
        under_test = ProjectVariables(self.data_test)

        under_test.add_project_variables()
        under_test.add_outputs_variables()

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

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

        self.assertTrue('OUTPUT_DEBUG ../../../build/vc2017_x64d/bin/',
                        content_test)
        self.assertTrue(
            'OUTPUT_REL ../../../build/vc2017_x64/bin/' in content_test)

        cmakelists_test.close()

        # If output is given
        under_test.output = '../output_binaries'
        under_test.cmake = get_cmake_lists('./')
        under_test.add_outputs_variables()

        under_test.cmake.close()

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

        self.assertTrue('OUTPUT_DEBUG ../output_binaries/${CMAKE_BUILD_TYPE}',
                        content_test)
        self.assertTrue('OUTPUT_REL ../output_binaries/${CMAKE_BUILD_TYPE}' in
                        content_test)

        cmakelists_test.close()
    def test_init_project_variables(self):
        """Initialize Project Variables"""

        under_test = ProjectVariables(self.data_test)

        self.assertTrue(under_test.tree)
        self.assertTrue(under_test.ns)
        self.assertTrue(under_test.cmake)
        self.assertFalse(under_test.output)
        self.assertIsNotNone(under_test.vs_outputs)

        # Class var are not None due to other tests
        self.assertIsNotNone(under_test.out_deb)
        self.assertIsNotNone(under_test.out_rel)
Пример #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()
Пример #16
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()
Пример #17
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()
Пример #18
0
 def write_target_outputs(context, cmake_file):
     """ Set import library for Fortran projects """
     ProjectVariables.write_target_outputs(context, cmake_file)