def write_include_dir(self): """ Include Directories : Add include directories required for compilation. """ incl_dir = self.tree.find( '//ns:ItemGroup/ns:ClCompile/ns:AdditionalIncludeDirectories', namespaces=self.ns) if incl_dir is None: incl_dir = self.tree.find( '//ns:ItemDefinitionGroup/ns:ClCompile/ns:AdditionalIncludeDirectories', namespaces=self.ns) if incl_dir is not None: self.cmake.write('# Include directories \n') inc_dir = incl_dir.text.replace('$(ProjectDir)', './') for i in inc_dir.split(';'): i = i.replace('\\', '/') i = re.sub(r'\$\((.+?)\)', r'$ENV{\1}', i) self.cmake.write('include_directories(%s)\n' % i) send('Include Directories found : %s' % i, 'warn') self.cmake.write('\n') else: # pragma: no cover send('Include Directories not found for this project.', 'warn')
def write_include_dir(self): """ Write on "CMakeLists.txt" include directories required for compilation. """ incl_dir = self.tree.find( '//ns:ItemGroup/ns:ClCompile/ns:AdditionalIncludeDirectories', namespaces=self.ns ) if incl_dir is None: incl_dir = self.tree.find( '//ns:ItemDefinitionGroup/ns:ClCompile/ns:AdditionalIncludeDirectories', namespaces=self.ns ) if incl_dir is not None: self.cmake.write('# Include directories \n') inc_dir = incl_dir.text.replace('$(ProjectDir)', './') for i in inc_dir.split(';'): i = i.replace('\\', '/') i = re.sub(r'\$\((.+?)\)', r'$ENV{\1}', i) self.cmake.write('include_directories(%s)\n' % i) send('Include Directories found : %s' % i, 'warn') self.cmake.write('\n') else: # pragma: no cover send('Include Directories not found for this project.', 'warn')
def add_additional_code(self, file_to_add): """ Add additional file with CMake code inside :param file_to_add: the file who contains CMake code :type file_to_add: str """ if file_to_add != '': try: fc = open(file_to_add, 'r') self.cmake.write( '############# Additional Code #############\n') self.cmake.write( '# Provides from external file. #\n') self.cmake.write( '###########################################\n\n') for line in fc: self.cmake.write(line) fc.close() self.cmake.write('\n') send('File of Code is added = ' + file_to_add, 'warn') except OSError: send( 'Wrong data file ! Code was not added, please verify file name or path !', 'error')
def write_dependencies(self): """ Write on "CMakeLists.txt" subdirectories or link directories for external libraries. """ references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns) if references: self.cmake.write('################### Dependencies ##################\n' '# Add Dependencies to project. #\n' '###################################################\n\n') self.cmake.write( 'option(BUILD_DEPENDS \n' + ' "Build other CMake project." \n' + ' ON \n' + ')\n\n' ) self.cmake.write( '# Dependencies : disable BUILD_DEPENDS to link with lib already build.\n' ) if self.dependencies is None: self.cmake.write('if(BUILD_DEPENDS)\n') for ref in references: reference = str(ref.get('Include')) path_to_reference = os.path.splitext(ntpath.basename(reference))[0] self.cmake.write( ' add_subdirectory(platform/cmake/%s ${CMAKE_BINARY_DIR}/%s)\n' % ( path_to_reference, path_to_reference ) ) else: self.cmake.write('if(BUILD_DEPENDS)\n') d = 1 for ref in self.dependencies: self.cmake.write( ' add_subdirectory(%s ${CMAKE_BINARY_DIR}/lib%s)\n' % (ref, str(d))) send( 'Add manually dependencies : %s. Will be build in "lib%s/" !' % ( ref, str(d)), 'warn' ) d += 1 self.cmake.write('else()\n') for ref in references: reference = str(ref.get('Include')) path_to_reference = os.path.splitext(ntpath.basename(reference))[0] self.cmake.write( ' link_directories(dependencies/%s/build/)\n' % path_to_reference ) self.cmake.write('endif()\n\n') else: # pragma: no cover send('No link needed.', '')
def set_intrinsic_functions(self): """ Set Intrinsic Functions flag: /Oi """ oi_debug_x86 = self.tree.find('%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['debug']['x86'], namespaces=self.ns) oi_debug_x64 = self.tree.find('%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['debug']['x64'], namespaces=self.ns) if oi_debug_x86 is not None and oi_debug_x64 is not None: if 'true' in oi_debug_x86.text and 'true' in oi_debug_x64.text: self.win_deb_flags += ' /Oi' send('IntrinsicFunctions for Debug', 'ok') else: send('No IntrinsicFunctions for Debug', '') oi_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['release']['x86'], namespaces=self.ns) oi_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['release']['x64'], namespaces=self.ns) if oi_release_x86 is not None and oi_release_x64 is not None: if 'true' in oi_release_x86.text and 'true' in oi_release_x64.text: self.win_rel_flags += ' /Oi' send('IntrinsicFunctions for Release', 'ok') else: send('No IntrinsicFunctions for Release', '')
def set_exception_handling(self): """ Set ExceptionHandling flag: /EHsc """ ehs_debug_x86 = self.tree.find( '%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['debug']['x86'], namespaces=self.ns ) ehs_debug_x64 = self.tree.find( '%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['debug']['x64'], namespaces=self.ns ) if ehs_debug_x86 is not None and ehs_debug_x64 is not None: if 'false' in ehs_debug_x86.text and 'false' in ehs_debug_x64.text: send('No ExceptionHandling for debug.', '') else: self.win_deb_flags += ' /EHsc' send('ExceptionHandling for debug.', 'ok') ehs_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['release']['x86'], namespaces=self.ns ) ehs_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if ehs_release_x86 is not None and ehs_release_x64 is not None: if 'false' in ehs_release_x86.text and 'false' in ehs_release_x64.text: send('No ExceptionHandling option for release.', '') else: self.win_rel_flags += ' /EHsc' send('ExceptionHandling for release.', 'ok')
def set_generate_debug_information(self): """ Set GenerateDebugInformation flag: /Zi """ zi_debug_x86 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['debug']['x86'], namespaces=self.ns ) zi_debug_x64 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['debug']['x64'], namespaces=self.ns ) if zi_debug_x86 is not None and zi_debug_x64 is not None: if 'true' in zi_debug_x86.text and 'true' in zi_debug_x64.text: self.win_deb_flags += ' /Zi' send('GenerateDebugInformation for debug.', 'ok') else: send('No GenerateDebugInformation for debug.', '') zi_release_x86 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['release']['x86'], namespaces=self.ns ) zi_release_x64 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if zi_release_x86 is not None and zi_release_x64 is not None: if 'true' in zi_release_x86.text and 'true' in zi_release_x64.text: self.win_rel_flags += ' /Zi' send('GenerateDebugInformation for release.', 'ok') else: send('No GenerateDebugInformation for release.', '')
def set_runtime_type_info(self): """ Set RuntimeTypeInfo flag: /GR """ # RuntimeTypeInfo gr_debug_x86 = self.tree.find('%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['debug']['x86'], namespaces=self.ns) gr_debug_x64 = self.tree.find('%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['debug']['x64'], namespaces=self.ns) if gr_debug_x64 is not None and gr_debug_x86 is not None: if 'true' in gr_debug_x64.text and 'true' in gr_debug_x86.text: self.win_deb_flags += ' /GR' send('RuntimeTypeInfo for Debug', 'ok') else: send('No RuntimeTypeInfo for Debug', '') gr_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['release']['x86'], namespaces=self.ns) gr_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['release']['x64'], namespaces=self.ns) if gr_release_x86 is not None and gr_release_x64 is not None: if 'true' in gr_release_x64.text and 'true' in gr_release_x86.text: self.win_rel_flags += ' /GR' send('RuntimeTypeInfo for Release', 'ok') else: send('No RuntimeTypeInfo for Release', '')
def set_runtime_type_info(self): """ Set RuntimeTypeInfo flag: /GR """ # RuntimeTypeInfo gr_debug_x86 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['debug']['x86'], namespaces=self.ns ) gr_debug_x64 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['debug']['x64'], namespaces=self.ns ) if gr_debug_x64 is not None and gr_debug_x86 is not None: if 'true' in gr_debug_x64.text and 'true' in gr_debug_x86.text: self.win_deb_flags += ' /GR' send('RuntimeTypeInfo for Debug', 'ok') else: send('No RuntimeTypeInfo for Debug', '') gr_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['release']['x86'], namespaces=self.ns ) gr_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeTypeInfo' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if gr_release_x86 is not None and gr_release_x64 is not None: if 'true' in gr_release_x64.text and 'true' in gr_release_x86.text: self.win_rel_flags += ' /GR' send('RuntimeTypeInfo for Release', 'ok') else: send('No RuntimeTypeInfo for Release', '')
def set_intrinsic_functions(self): """ Set Intrinsic Functions flag: /Oi """ oi_debug_x86 = self.tree.find( '%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['debug']['x86'], namespaces=self.ns ) oi_debug_x64 = self.tree.find( '%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['debug']['x64'], namespaces=self.ns ) if oi_debug_x86 is not None and oi_debug_x64 is not None: if 'true' in oi_debug_x86.text and 'true' in oi_debug_x64.text: self.win_deb_flags += ' /Oi' send('IntrinsicFunctions for Debug', 'ok') else: send('No IntrinsicFunctions for Debug', '') oi_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['release']['x86'], namespaces=self.ns ) oi_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:IntrinsicFunctions' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if oi_release_x86 is not None and oi_release_x64 is not None: if 'true' in oi_release_x86.text and 'true' in oi_release_x64.text: self.win_rel_flags += ' /Oi' send('IntrinsicFunctions for Release', 'ok') else: send('No IntrinsicFunctions for Release', '')
def set_optimization(self): """ Set Optimization flag: /Od """ opt_debug_x86 = self.tree.find('%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['debug']['x86'], namespaces=self.ns) opt_debug_x64 = self.tree.find('%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['debug']['x64'], namespaces=self.ns) if opt_debug_x86 is not None and opt_debug_x64 is not None: if 'Disabled' in opt_debug_x64.text and 'Disabled' in opt_debug_x86.text: self.win_deb_flags += ' /Od' send('Optimization for Debug', 'ok') else: send('No Optimization for Debug', '') opt_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['release']['x86'], namespaces=self.ns) opt_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['release']['x64'], namespaces=self.ns) if opt_release_x86 is not None and opt_release_x64 is not None: if 'MaxSpeed' in opt_release_x64.text and 'MaxSpeed' in opt_release_x86.text: self.win_rel_flags += ' /Od' send('Optimization for Release', 'ok') else: send('No Optimization for Release', '')
def set_generate_debug_information(self): """ Set GenerateDebugInformation flag: /Zi """ zi_debug_x86 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['debug']['x86'], namespaces=self.ns) zi_debug_x64 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['debug']['x64'], namespaces=self.ns) if zi_debug_x86 is not None and zi_debug_x64 is not None: if 'true' in zi_debug_x86.text and 'true' in zi_debug_x64.text: self.win_deb_flags += ' /Zi' send('GenerateDebugInformation for debug.', 'ok') else: send('No GenerateDebugInformation for debug.', '') zi_release_x86 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['release']['x86'], namespaces=self.ns) zi_release_x64 = self.tree.find( '%s/ns:Link/ns:GenerateDebugInformation' % self.definitiongroups['release']['x64'], namespaces=self.ns) if zi_release_x86 is not None and zi_release_x64 is not None: if 'true' in zi_release_x86.text and 'true' in zi_release_x64.text: self.win_rel_flags += ' /Zi' send('GenerateDebugInformation for release.', 'ok') else: send('No GenerateDebugInformation for release.', '')
def set_use_debug_libraries(self): """ Set Use Debug Libraries flag: /MD """ md_debug_x86 = self.tree.xpath( '%s/ns:UseDebugLibraries' % self.propertygroup['debug']['x86'], namespaces=self.ns ) md_debug_x64 = self.tree.xpath( '%s/ns:UseDebugLibraries' % self.propertygroup['debug']['x64'], namespaces=self.ns ) if md_debug_x64 and md_debug_x86: if 'true' in md_debug_x86[0].text and 'true' in md_debug_x64[0].text: self.win_deb_flags += ' /MD' send('UseDebugLibrairies for Debug', 'ok') else: send('No UseDebugLibrairies for Debug', '') md_release_x86 = self.tree.xpath( '%s/ns:UseDebugLibraries' % self.propertygroup['release']['x86'], namespaces=self.ns ) md_release_x64 = self.tree.xpath( '%s/ns:UseDebugLibraries' % self.propertygroup['release']['x64'], namespaces=self.ns ) if md_release_x86 and md_release_x64: if 'true' in md_release_x86[0].text and 'true' in md_release_x64[0].text: self.win_rel_flags += ' /MD' send('UseDebugLibrairies for Release', 'ok') else: send('No UseDebugLibrairies for Release', '')
def write_dependencies(self): """ Dependencies : Add subdirectories or link directories for external libraries. """ references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns) if references: self.cmake.write( '################### Dependencies ##################\n' '# Add Dependencies to project. #\n' '###################################################\n\n') self.cmake.write('option(BUILD_DEPENDS \n' + ' "Build other CMake project." \n' + ' ON \n' + ')\n\n') self.cmake.write( '# Dependencies : disable BUILD_DEPENDS to link with lib already build.\n' ) if self.dependencies is None: self.cmake.write('if(BUILD_DEPENDS)\n') for ref in references: reference = str(ref.get('Include')) path_to_reference = os.path.splitext( ntpath.basename(reference))[0] self.cmake.write( ' add_subdirectory(platform/cmake/%s ${CMAKE_BINARY_DIR}/%s)\n' % (path_to_reference, path_to_reference)) else: self.cmake.write('if(BUILD_DEPENDS)\n') d = 1 for ref in self.dependencies: self.cmake.write( ' add_subdirectory(%s ${CMAKE_BINARY_DIR}/lib%s)\n' % (ref, str(d))) send( 'Add manually dependencies : %s. Will be build in "lib%s/" !' % (ref, str(d)), 'warn') d += 1 self.cmake.write('else()\n') for ref in references: reference = str(ref.get('Include')) path_to_reference = os.path.splitext( ntpath.basename(reference))[0] self.cmake.write( ' link_directories(dependencies/%s/build/)\n' % path_to_reference) self.cmake.write('endif()\n\n') else: # pragma: no cover send('No link needed.', '')
def define_windows_flags(self): """ Define the Flags for Win32 platforms """ # Define FLAGS for Windows self.set_warning_level() self.set_whole_program_optimization() self.set_use_debug_libraries() self.set_runtime_library() self.set_optimization() self.set_intrinsic_functions() self.set_runtime_type_info() self.set_function_level_linking() self.set_generate_debug_information() self.set_exception_handling() # Write FLAGS for Windows self.cmake.write('if(MSVC)\n') if self.win_deb_flags != '': send('Debug FLAGS found = ' + self.win_deb_flags, 'ok') self.cmake.write( ' set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}%s")\n' % self.win_deb_flags) else: # pragma: no cover send('No Debug FLAGS found', '') if self.win_rel_flags != '': send('Release FLAGS found = ' + self.win_rel_flags, 'ok') self.cmake.write( ' set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}%s")\n' % self.win_rel_flags) else: # pragma: no cover send('No Release FLAGS found', '') self.cmake.write('endif(MSVC)\n')
def set_optimization(self): """ Set Optimization flag: /Od """ opt_debug_x86 = self.tree.find( '%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['debug']['x86'], namespaces=self.ns ) opt_debug_x64 = self.tree.find( '%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['debug']['x64'], namespaces=self.ns ) if opt_debug_x86 is not None and opt_debug_x64 is not None: if 'Disabled' in opt_debug_x64.text and 'Disabled' in opt_debug_x86.text: self.win_deb_flags += ' /Od' send('Optimization for Debug', 'ok') else: send('No Optimization for Debug', '') opt_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['release']['x86'], namespaces=self.ns ) opt_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:Optimization' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if opt_release_x86 is not None and opt_release_x64 is not None: if 'MaxSpeed' in opt_release_x64.text and 'MaxSpeed' in opt_release_x86.text: self.win_rel_flags += ' /Od' send('Optimization for Release', 'ok') else: send('No Optimization for Release', '')
def set_use_debug_libraries(self): """ Set Use Debug Libraries flag: /MD """ md_debug_x86 = self.tree.xpath('%s/ns:UseDebugLibraries' % self.propertygroup['debug']['x86'], namespaces=self.ns) md_debug_x64 = self.tree.xpath('%s/ns:UseDebugLibraries' % self.propertygroup['debug']['x64'], namespaces=self.ns) if md_debug_x64 and md_debug_x86: if 'true' in md_debug_x86[0].text and 'true' in md_debug_x64[ 0].text: self.win_deb_flags += ' /MD' send('UseDebugLibrairies for Debug', 'ok') else: send('No UseDebugLibrairies for Debug', '') md_release_x86 = self.tree.xpath('%s/ns:UseDebugLibraries' % self.propertygroup['release']['x86'], namespaces=self.ns) md_release_x64 = self.tree.xpath('%s/ns:UseDebugLibraries' % self.propertygroup['release']['x64'], namespaces=self.ns) if md_release_x86 and md_release_x64: if 'true' in md_release_x86[0].text and 'true' in md_release_x64[ 0].text: self.win_rel_flags += ' /MD' send('UseDebugLibrairies for Release', 'ok') else: send('No UseDebugLibrairies for Release', '')
def set_exception_handling(self): """ Set ExceptionHandling flag: /EHsc """ ehs_debug_x86 = self.tree.find('%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['debug']['x86'], namespaces=self.ns) ehs_debug_x64 = self.tree.find('%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['debug']['x64'], namespaces=self.ns) if ehs_debug_x86 is not None and ehs_debug_x64 is not None: if 'false' in ehs_debug_x86.text and 'false' in ehs_debug_x64.text: send('No ExceptionHandling for debug.', '') else: self.win_deb_flags += ' /EHsc' send('ExceptionHandling for debug.', 'ok') ehs_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['release']['x86'], namespaces=self.ns) ehs_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:ExceptionHandling' % self.definitiongroups['release']['x64'], namespaces=self.ns) if ehs_release_x86 is not None and ehs_release_x64 is not None: if 'false' in ehs_release_x86.text and 'false' in ehs_release_x64.text: send('No ExceptionHandling option for release.', '') else: self.win_rel_flags += ' /EHsc' send('ExceptionHandling for release.', 'ok')
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()
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()
def set_warning_level(self): """ Set Warning level for Windows: /W """ try: warning = self.tree.xpath('//ns:WarningLevel', namespaces=self.ns)[0] except IndexError: return if warning.text != '': lvl = ' /W' + warning.text[-1:] self.win_deb_flags += lvl self.win_rel_flags += lvl send('Warning : ' + warning.text, 'ok') else: # pragma: no cover send('No Warning level.', '')
def set_function_level_linking(self): """ Set FunctionLevelLinking flag: /Gy """ gy_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:FunctionLevelLinking' % self.definitiongroups['release']['x86'], namespaces=self.ns ) gy_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:FunctionLevelLinking' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if gy_release_x86 is not None and gy_release_x64 is not None: if 'true' in gy_release_x86.text and 'true' in gy_release_x64.text: self.win_rel_flags += ' /Gy' send('FunctionLevelLinking for release.', 'ok') else: send('No FunctionLevelLinking for release.', '')
def set_function_level_linking(self): """ Set FunctionLevelLinking flag: /Gy """ gy_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:FunctionLevelLinking' % self.definitiongroups['release']['x86'], namespaces=self.ns) gy_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:FunctionLevelLinking' % self.definitiongroups['release']['x64'], namespaces=self.ns) if gy_release_x86 is not None and gy_release_x64 is not None: if 'true' in gy_release_x86.text and 'true' in gy_release_x64.text: self.win_rel_flags += ' /Gy' send('FunctionLevelLinking for release.', 'ok') else: send('No FunctionLevelLinking for release.', '')
def get_cmake_lists(cmake_path=None): """ Create CMakeLists.txt file in wanted path :param cmake_path: path where CMakeLists.txt should be write :type cmake_path: str :return: cmake file wrapper opened :rtype: _io.TextIOWrapper """ if not cmake_path: send('CMakeLists will be build in current directory.', '') cmake = open('CMakeLists.txt', 'w') else: send('CmakeLists.txt will be build in : ' + str(cmake_path), 'warn') if cmake_path[-1:] == '/' or cmake_path[-1:] == '\\': cmake = open(str(cmake_path) + 'CMakeLists.txt', 'w') else: cmake = open(str(cmake_path) + '/CMakeLists.txt', 'w') return cmake
def get_cmake_lists(cmake_path=None): """ Create CMakeLists.txt file in wanted "cmake_path" :param cmake_path: path where CMakeLists.txt should be write :type cmake_path: str :return: cmake file wrapper opened :rtype: _io.TextIOWrapper """ if not cmake_path: send('CMakeLists will be build in current directory.', '') cmake = open('CMakeLists.txt', 'w') else: send('CmakeLists.txt will be build in : ' + str(cmake_path), 'warn') if cmake_path[-1:] == '/' or cmake_path[-1:] == '\\': cmake = open(str(cmake_path) + 'CMakeLists.txt', 'w') else: cmake = open(str(cmake_path) + '/CMakeLists.txt', 'w') return cmake
def write_files_variables(self): """ Write the project variables in CMakeLists.txt file """ # Cpp Dir known_cpp = [] ProjectFiles.c_folder_nb = 1 self.cmake.write('# Folders files\n') for cpp in self.cppfiles: if cpp.get('Include') is not None: cxx = str(cpp.get('Include')) if not cxx.rpartition('.')[-1] in self.language: self.language.append(cxx.rpartition('.')[-1]) current_cpp = '/'.join(cxx.split('\\')[0:-1]) if current_cpp not in known_cpp: if not current_cpp: # Case files are beside the VS Project current_cpp = './' known_cpp.append(current_cpp) self.cmake.write( 'set(CPP_DIR_%s %s)\n' % (str(ProjectFiles.c_folder_nb), current_cpp)) ProjectFiles.c_folder_nb += 1 # Headers Dir known_headers = [] ProjectFiles.h_folder_nb = 1 for header in self.headerfiles: h = str(header.get('Include')) current_header = '/'.join(h.split('\\')[0:-1]) if current_header not in known_headers: known_headers.append(current_header) self.cmake.write( 'set(HEADER_DIR_%s %s)\n' % (str(ProjectFiles.h_folder_nb), current_header)) ProjectFiles.h_folder_nb += 1 send("C++ Extensions found: %s" % self.language, 'INFO')
def add_additional_code(self, file_to_add): """ Add additional file with CMake code inside :param file_to_add: the file who contains CMake code :type file_to_add: str """ if file_to_add != '': try: fc = open(file_to_add, 'r') self.cmake.write('############# Additional Code #############\n') self.cmake.write('# Provides from external file. #\n') self.cmake.write('###########################################\n\n') for line in fc: self.cmake.write(line) fc.close() self.cmake.write('\n') send('File of Code is added = ' + file_to_add, 'warn') except OSError as e: send(str(e), 'error') send( 'Wrong data file ! Code was not added, please verify file name or path !', 'error' )
def get_vcxproj_data(vs_project): """ Return xml data from "vcxproj" file :param vs_project: the vcxproj file :type vs_project: str :return: dict with VS Project data :rtype: dict """ vcxproj = {} try: tree = etree.parse(vs_project) namespace = str(tree.getroot().nsmap) ns = {'ns': namespace.partition('\'')[-1].rpartition('\'')[0]} vcxproj['tree'] = tree vcxproj['ns'] = ns assert 'http://schemas.microsoft.com' in ns['ns'] except AssertionError: # pragma: no cover send( '.vcxproj file cannot be import, because this file does not seem to comply with' ' Microsoft xml data !', 'error') exit(1) except (OSError, IOError): # pragma: no cover send( '.vcxproj file cannot be import. ' 'Please, verify you have rights to this directory or file exists !', 'error') exit(1) except etree.XMLSyntaxError: # pragma: no cover send('This file is not a ".vcxproj" file or XML is broken !', 'error') exit(1) return vcxproj
def init_files(self, vs_project, cmake_lists): """ Initialize opening of CMake and VS Project files :param vs_project: Visual Studio project file path :type vs_project: str :param cmake_lists: CMakeLists.txt file path :type cmake_lists: str """ # VS Project (.vcxproj) if vs_project: temp_path = os.path.splitext(vs_project) if temp_path[1] == '.vcxproj': send('Project to convert = ' + vs_project, '') self.data['vcxproj'] = get_vcxproj_data(vs_project) else: # pragma: no cover send( 'This file is not a ".vcxproj". Be sure you give the right file', 'error') exit(1) # CMakeLists if cmake_lists: if os.path.exists(cmake_lists): self.data['cmake'] = get_cmake_lists(cmake_lists) if not self.data['cmake']: send( 'CMakeLists.txt path is not set. ' 'He will be generated in current directory.', 'warn') self.data['cmake'] = get_cmake_lists()
def add_artefact_target_outputs(self): """ Add outputs for each artefacts CMake target """ if ProjectVariables.out_deb or ProjectVariables.out_rel: self.cmake.write( '############## Artefacts Output #################\n') self.cmake.write( '# Defines outputs , depending Debug or Release. #\n') self.cmake.write( '#################################################\n\n') if ProjectVariables.out_deb: self.cmake.write('if(CMAKE_BUILD_TYPE STREQUAL "Debug")\n') self.cmake.write( ' set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")\n' ) self.cmake.write( ' set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")\n' ) self.cmake.write( ' set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")' '\n') if ProjectVariables.out_rel: self.cmake.write('else()\n') self.cmake.write( ' set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")\n' ) self.cmake.write( ' set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")\n' ) self.cmake.write( ' set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")\n' ) self.cmake.write('endif()\n\n') else: # pragma: no cover send( 'No Output found or define. CMake will use current directory as output !', 'warn')
def init_files(self, vs_project, cmake_lists): """ Initialize opening of CMakeLists.txt and VS Project files :param vs_project: Visual Studio project file path :type vs_project: str :param cmake_lists: CMakeLists.txt file path :type cmake_lists: str """ # VS Project (.vcxproj) if vs_project: temp_path = os.path.splitext(vs_project) if temp_path[1] == '.vcxproj': send('Project to convert = ' + vs_project, '') self.data['vcxproj'] = get_vcxproj_data(vs_project) else: # pragma: no cover send('This file is not a ".vcxproj". Be sure you give the right file', 'error') exit(1) # Cmake Porject (CMakeLists.txt) if cmake_lists: if os.path.exists(cmake_lists): self.data['cmake'] = get_cmake_lists(cmake_lists) if not self.data['cmake']: send( 'CMakeLists.txt path is not set. ' 'He will be generated in current directory.', 'warn' ) self.data['cmake'] = get_cmake_lists()
def write_files_variables(self): """ Write the project variables in CMakeLists.txt file """ # Cpp Dir known_cpp = [] ProjectFiles.c_folder_nb = 1 self.cmake.write('# Folders files\n') for cpp in self.cppfiles: if cpp.get('Include') is not None: cxx = str(cpp.get('Include')) if not cxx.rpartition('.')[-1] in self.language: self.language.append(cxx.rpartition('.')[-1]) current_cpp = '/'.join(cxx.split('\\')[0:-1]) if current_cpp not in known_cpp: if not current_cpp: # Case files are beside the VS Project current_cpp = './' known_cpp.append(current_cpp) self.cmake.write( 'set(CPP_DIR_%s %s)\n' % (str(ProjectFiles.c_folder_nb), current_cpp) ) ProjectFiles.c_folder_nb += 1 # Headers Dir known_headers = [] ProjectFiles.h_folder_nb = 1 for header in self.headerfiles: h = str(header.get('Include')) current_header = '/'.join(h.split('\\')[0:-1]) if current_header not in known_headers: known_headers.append(current_header) self.cmake.write( 'set(HEADER_DIR_%s %s)\n' % (str(ProjectFiles.h_folder_nb), current_header) ) ProjectFiles.h_folder_nb += 1 send("C++ Extensions found: %s" % self.language, 'INFO')
def set_runtime_library(self): """ Set RuntimeLibrary flag: /MDd """ # RuntimeLibrary mdd_debug_x86 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeLibrary' % self.definitiongroups['debug']['x86'], namespaces=self.ns ) mdd_debug_x64 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeLibrary' % self.definitiongroups['debug']['x64'], namespaces=self.ns ) if mdd_debug_x64 is not None and mdd_debug_x86 is not None: if 'MultiThreadedDebugDLL' in mdd_debug_x86.text and \ 'MultiThreadedDebugDLL' in mdd_debug_x64.text: self.win_deb_flags += ' /MDd' send('RuntimeLibrary for Debug', 'ok') else: send('No RuntimeLibrary for Debug', '') mdd_release_x86 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeLibrary' % self.definitiongroups['release']['x86'], namespaces=self.ns ) mdd_release_x64 = self.tree.find( '%s/ns:ClCompile/ns:RuntimeLibrary' % self.definitiongroups['release']['x64'], namespaces=self.ns ) if mdd_release_x86 is not None and mdd_release_x64 is not None: if 'MultiThreadedDebugDLL' in mdd_release_x86.text and \ 'MultiThreadedDebugDLL' in mdd_release_x64.text: self.win_rel_flags += ' /MDd' send('RuntimeLibrary for Release', 'ok') else: send('No RuntimeLibrary for Release', '')
def set_whole_program_optimization(self): """ Set Whole Program Optimization flag: /GL """ # WholeProgramOptimization gl_debug_x86 = self.tree.xpath( '%s/ns:WholeProgramOptimization' % self.propertygroup['debug']['x86'], namespaces=self.ns ) gl_debug_x64 = self.tree.xpath( '%s/ns:WholeProgramOptimization' % self.propertygroup['debug']['x64'], namespaces=self.ns ) if gl_debug_x86 and gl_debug_x64: if 'true' in gl_debug_x86[0].text and 'true' in gl_debug_x64[0].text: self.win_deb_flags += ' /GL' send('WholeProgramOptimization for Debug', 'ok') else: send('No WholeProgramOptimization for Debug', '') gl_release_x86 = self.tree.xpath( '%s/ns:WholeProgramOptimization' % self.propertygroup['release']['x86'], namespaces=self.ns ) gl_release_x64 = self.tree.xpath( '%s/ns:WholeProgramOptimization' % self.propertygroup['release']['x64'], namespaces=self.ns ) if gl_release_x86 and gl_release_x64: if 'true' in gl_release_x86[0].text and 'true' in gl_release_x64[0].text: self.win_rel_flags += ' /GL' send('WholeProgramOptimization for Release', 'ok') else: send('No WholeProgramOptimization for Release', '')
def link_dependencies(self): """ Link : Add command to link dependencies to project. """ # External libraries references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns) if references: self.cmake.write('# Link with other dependencies.\n') self.cmake.write('target_link_libraries(${PROJECT_NAME} ') for ref in references: reference = str(ref.get('Include')) path_to_reference = os.path.splitext( ntpath.basename(reference))[0] lib = os.path.splitext(ntpath.basename(reference))[0] if lib == 'g3log': lib += 'ger' # To get "g3logger" self.cmake.write(lib + ' ') message = 'External library found : %s' % path_to_reference send(message, '') self.cmake.write(')\n') # Additional Dependencies dependencies = self.tree.xpath('//ns:AdditionalDependencies', namespaces=self.ns) if dependencies: listdepends = dependencies[0].text.replace( '%(AdditionalDependencies)', '') if listdepends != '': send('Additional Dependencies = %s' % listdepends, 'ok') windepends = [] for d in listdepends.split(';'): if d != '%(AdditionalDependencies)': if os.path.splitext(d)[1] == '.lib': windepends.append(d) if windepends: self.cmake.write('if(MSVC)\n') self.cmake.write( ' target_link_libraries(${PROJECT_NAME} ') for dep in windepends: self.cmake.write(dep + ' ') self.cmake.write(')\n') self.cmake.write('endif(MSVC)\n') else: # pragma: no cover send('No dependencies.', '')
def define_windows_flags(self): """ Define the Flags for Win32 platforms """ # Define FLAGS for Windows self.set_warning_level() self.set_whole_program_optimization() self.set_use_debug_libraries() self.set_runtime_library() self.set_optimization() self.set_intrinsic_functions() self.set_runtime_type_info() self.set_function_level_linking() self.set_generate_debug_information() self.set_exception_handling() # Write FLAGS for Windows self.cmake.write('if(MSVC)\n') if self.win_deb_flags != '': send('Debug FLAGS found = ' + self.win_deb_flags, 'ok') self.cmake.write( ' set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}%s")\n' % self.win_deb_flags ) else: # pragma: no cover send('No Debug FLAGS found', '') if self.win_rel_flags != '': send('Release FLAGS found = ' + self.win_rel_flags, 'ok') self.cmake.write( ' set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}%s")\n' % self.win_rel_flags ) else: # pragma: no cover send('No Release FLAGS found', '') self.cmake.write('endif(MSVC)\n')
def define_linux_flags(self): """ Define the Flags for Linux platforms """ if self.std: if self.std in self.available_std: send('Cmake will use C++ std %s.' % self.std, 'info') linux_flags = '-std=%s' % self.std else: send( 'C++ std %s version does not exist. CMake will use "c++11" instead' % self.std, 'warn') linux_flags = '-std=c++11' else: send( 'No C++ std version specified. CMake will use "c++11" by default.', 'info') linux_flags = '-std=c++11' references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns) if references: for ref in references: reference = str(ref.get('Include')) if '\\' in reference: reference = reference.replace('\\', '/') lib = os.path.splitext(path.basename(reference))[0] if (lib == 'lemon' or lib == 'zlib') and '-fPIC' not in linux_flags: linux_flags += ' -fPIC' self.cmake.write('if(NOT MSVC)\n') self.cmake.write(' set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} %s")\n' % linux_flags) self.cmake.write( ' if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")\n') self.cmake.write( ' set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")\n' ) self.cmake.write(' endif()\n') self.cmake.write('endif(NOT MSVC)\n\n')
def link_dependencies(self): """ Write link dependencies of project. """ # External libraries references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns) if references: self.cmake.write('# Link with other dependencies.\n') self.cmake.write('target_link_libraries(${PROJECT_NAME} ') for ref in references: reference = str(ref.get('Include')) path_to_reference = os.path.splitext(ntpath.basename(reference))[0] lib = os.path.splitext(ntpath.basename(reference))[0] if lib == 'g3log': lib += 'ger' # To get "g3logger" self.cmake.write(lib + ' ') message = 'External library found : %s' % path_to_reference send(message, '') self.cmake.write(')\n') # Additional Dependencies dependencies = self.tree.xpath('//ns:AdditionalDependencies', namespaces=self.ns) if dependencies: listdepends = dependencies[0].text.replace('%(AdditionalDependencies)', '') if listdepends != '': send('Additional Dependencies = %s' % listdepends, 'ok') windepends = [] for d in listdepends.split(';'): if d != '%(AdditionalDependencies)': if os.path.splitext(d)[1] == '.lib': windepends.append(d) if windepends: self.cmake.write('if(MSVC)\n') self.cmake.write(' target_link_libraries(${PROJECT_NAME} ') for dep in windepends: self.cmake.write(dep + ' ') self.cmake.write(')\n') self.cmake.write('endif(MSVC)\n') else: # pragma: no cover send('No dependencies.', '')
def add_target_artefact(self): """ Add Library or Executable target """ configurationtype = self.tree.find('//ns:ConfigurationType', namespaces=self.ns) if configurationtype.text == 'DynamicLibrary': self.cmake.write('# Add library to build.\n') self.cmake.write('add_library(${PROJECT_NAME} SHARED\n') send('CMake will build a SHARED Library.', '') elif configurationtype.text == 'StaticLibrary': # pragma: no cover self.cmake.write('# Add library to build.\n') self.cmake.write('add_library(${PROJECT_NAME} STATIC\n') send('CMake will build a STATIC Library.', '') else: # pragma: no cover self.cmake.write('# Add executable to build.\n') self.cmake.write('add_executable(${PROJECT_NAME} \n') send('CMake will build an EXECUTABLE.', '') self.cmake.write(' ${SRC_FILES}\n') self.cmake.write(')\n\n')
def get_vcxproj_data(vs_project): """ Return xml data from "vcxproj" file :param vs_project: the vcxproj file :type vs_project: str :return: dict with VS Project data :rtype: dict """ vcxproj = {} try: tree = etree.parse(vs_project) namespace = str(tree.getroot().nsmap) ns = {'ns': namespace.partition('\'')[-1].rpartition('\'')[0]} vcxproj['tree'] = tree vcxproj['ns'] = ns assert 'http://schemas.microsoft.com' in ns['ns'] except AssertionError: # pragma: no cover send( '.vcxproj file cannot be import, because this file does not seem to comply with' ' Microsoft xml data !', 'error' ) exit(1) except (OSError, IOError): # pragma: no cover send( '.vcxproj file cannot be import. ' 'Please, verify you have rights to this directory or file exists !', 'error' ) exit(1) except etree.XMLSyntaxError: # pragma: no cover send('This file is not a ".vcxproj" file or XML is broken !', 'error') exit(1) return vcxproj
def define_linux_flags(self): """ Define the Flags for Linux platforms """ if self.std: if self.std in self.available_std: send('Cmake will use C++ std %s.' % self.std, 'info') linux_flags = '-std=%s' % self.std else: send( 'C++ std %s version does not exist. CMake will use "c++11" instead' % self.std, 'warn' ) linux_flags = '-std=c++11' else: send('No C++ std version specified. CMake will use "c++11" by default.', 'info') linux_flags = '-std=c++11' references = self.tree.xpath('//ns:ProjectReference', namespaces=self.ns) if references: for ref in references: reference = str(ref.get('Include')) if '\\' in reference: reference = reference.replace('\\', '/') lib = os.path.splitext(path.basename(reference))[0] if (lib == 'lemon' or lib == 'zlib') and '-fPIC' not in linux_flags: linux_flags += ' -fPIC' self.cmake.write('if(NOT MSVC)\n') self.cmake.write(' set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} %s")\n' % linux_flags) self.cmake.write(' if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")\n') self.cmake.write(' set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")\n') self.cmake.write(' endif()\n') self.cmake.write('endif(NOT MSVC)\n\n')
def add_project_variables(self): """ Add main CMake project variables """ # CMake Minimum required. self.cmake.write( 'cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)\n\n') # Project Name self.cmake.write( '################### Variables. ####################\n' '# Change if you want modify path or other values. #\n' '###################################################\n\n') root_projectname = self.tree.xpath('//ns:RootNamespace', namespaces=self.ns) project = False if root_projectname: projectname = root_projectname[0] if projectname.text: self.cmake.write('set(PROJECT_NAME ' + projectname.text + ')\n') project = True if not project: # pragma: no cover self.cmake.write( 'set(PROJECT_NAME <PLEASE SET YOUR PROJECT NAME !!>)\n') send( 'No PROJECT NAME found or define. ' 'Please set [PROJECT_NAME] variable in CMakeLists.txt.', 'error') # PropertyGroup prop_deb_x86 = get_propertygroup('debug', 'x86') prop_deb_x64 = get_propertygroup('debug', 'x64') prop_rel_x86 = get_propertygroup('release', 'x86') prop_rel_x64 = get_propertygroup('release', 'x64') if not self.vs_outputs['debug']['x86']: self.vs_outputs['debug']['x86'] = self.tree.find( '%s//ns:OutDir' % prop_deb_x86, namespaces=self.ns) if self.vs_outputs['debug']['x86'] is None: vs_output_debug_x86 = self.tree.xpath( '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir', namespaces=self.ns) if vs_output_debug_x86: self.vs_outputs['debug']['x86'] = vs_output_debug_x86[0] if not self.vs_outputs['debug']['x64']: self.vs_outputs['debug']['x64'] = self.tree.find( '%s/ns:OutDir' % prop_deb_x64, namespaces=self.ns) if self.vs_outputs['debug']['x64'] is None: vs_output_debug_x64 = self.tree.xpath( '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir', namespaces=self.ns) if vs_output_debug_x64: self.vs_outputs['debug']['x64'] = vs_output_debug_x64[0] if not self.vs_outputs['release']['x86']: self.vs_outputs['release']['x86'] = self.tree.find( '%s//ns:OutDir' % prop_rel_x86, namespaces=self.ns) if self.vs_outputs['release']['x86'] is None: vs_output_release_x86 = self.tree.xpath( '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir', namespaces=self.ns) if vs_output_release_x86: self.vs_outputs['release']['x86'] = vs_output_release_x86[ 0] if not self.vs_outputs['release']['x64']: self.vs_outputs['release']['x64'] = self.tree.find( '%s//ns:OutDir' % prop_rel_x64, namespaces=self.ns) if self.vs_outputs['release']['x64'] is None: vs_output_release_x64 = self.tree.xpath( '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir', namespaces=self.ns) if vs_output_release_x64: self.vs_outputs['release']['x64'] = vs_output_release_x64[ 0]
def add_outputs_variables(self): """ Add Outputs Variables """ output_deb_x86 = '' output_deb_x64 = '' output_rel_x86 = '' output_rel_x64 = '' if not self.output: if self.vs_outputs['debug']['x86'] is not None: output_deb_x86 = self.cleaning_output( self.vs_outputs['debug']['x86'].text) if self.vs_outputs['debug']['x64'] is not None: output_deb_x64 = self.cleaning_output( self.vs_outputs['debug']['x64'].text) if self.vs_outputs['release']['x86'] is not None: output_rel_x86 = self.cleaning_output( self.vs_outputs['release']['x86'].text) if self.vs_outputs['release']['x64'] is not None: output_rel_x64 = self.cleaning_output( self.vs_outputs['release']['x64'].text) else: if self.output[-1:] == '/' or self.output[-1:] == '\\': build_type = '${CMAKE_BUILD_TYPE}' else: build_type = '/${CMAKE_BUILD_TYPE}' output_deb_x86 = self.output + build_type output_deb_x64 = self.output + build_type output_rel_x86 = self.output + build_type output_rel_x64 = self.output + build_type output_deb_x86 = output_deb_x86.strip().replace('\n', '') output_deb_x64 = output_deb_x64.strip().replace('\n', '') output_rel_x86 = output_rel_x86.strip().replace('\n', '') output_rel_x64 = output_rel_x64.strip().replace('\n', '') self.cmake.write('# Output Variables\n') if output_deb_x64 or output_deb_x86: debug_output = output_deb_x64 if output_deb_x64 else output_deb_x86 send('Output Debug = %s' % debug_output, 'ok') self.cmake.write('set(OUTPUT_DEBUG ' + debug_output + ')\n') ProjectVariables.out_deb = True else: # pragma: no cover send('No Output Debug define. Use [Debug/bin] by default !', 'warn') self.cmake.write('set(OUTPUT_DEBUG Debug/bin)\n') ProjectVariables.out_deb = True if output_rel_x64 or output_rel_x86: release_output = output_rel_x64 if output_rel_x64 else output_rel_x86 send('Output Release = ' + release_output, 'ok') self.cmake.write('set(OUTPUT_REL ' + release_output + ')\n') ProjectVariables.out_rel = True else: # pragma: no cover send('No Output Release define. Use [Release/bin] by default !', 'warn') self.cmake.write('set(OUTPUT_RELEASE Release/bin)\n') ProjectVariables.out_rel = True