Last active
December 13, 2015 23:29
-
-
Save chenzx/4992140 to your computer and use it in GitHub Desktop.
A simple ruby script to convert vcproj to SConstruct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pathname' | |
require 'rexml/document' | |
include REXML | |
BUILD_CONFIG = 'Debug' # to switch between different config; | |
vcproj_filename = ARGV.shift | |
vcproj_filename = Pathname.new(vcproj_filename).cleanpath | |
vcproj_libname = vcproj_filename.sub(/\.vcproj/, '') | |
vcprojDoc = REXML::Document.new File.new(vcproj_filename) | |
sourceFiles = [] | |
REXML::XPath.each( vcprojDoc, "*/Files/Filter/descendant::File").each {|fileElement| | |
bExcludedFromBuild = false | |
if fileElement.elements["FileConfiguration[starts-with(@Name,'"+BUILD_CONFIG+"')][@ExcludedFromBuild='true']"] | |
bExcludedFromBuild = true | |
end | |
if not bExcludedFromBuild then | |
sourceFile = fileElement.attributes["RelativePath"] | |
if not sourceFile.end_with? '.h' then | |
sourceFiles.push sourceFile.gsub(/\\/,'/') | |
end | |
end | |
} | |
includePaths = [] | |
REXML::XPath.each( vcprojDoc, "*/Configurations/Configuration[starts-with(@Name,'"+BUILD_CONFIG+"')]/Tool[@Name='VCCLCompilerTool']").each {|toolElement| | |
strAdditionalIncludeDirectories = toolElement.attributes["AdditionalIncludeDirectories"] | |
strAdditionalIncludeDirectories.gsub(/\"/,"").split(";").each{ |includePath| | |
includePaths.push includePath.gsub(/\\/,'/') | |
} | |
} | |
preprocessorDefinitions = [] | |
REXML::XPath.each( vcprojDoc, "*/Configurations/Configuration[starts-with(@Name,'"+BUILD_CONFIG+"')]/Tool[@Name='VCCLCompilerTool']").each {|toolElement| | |
strPreprocessorDefinitions = toolElement.attributes["PreprocessorDefinitions"] | |
strPreprocessorDefinitions.split(";").each{ |preprocessorDefinition| | |
preprocessorDefinitions.push preprocessorDefinition | |
} | |
} | |
puts "env = Environment(MSVC_VERSION = '9.0', CPPPATH = ['.'" | |
includePaths.each{|path| puts " ,'#{path}'"} | |
puts " ])" | |
puts "env.Append(CPPDEFINES=[" | |
preprocessorDefinitions.each{|predef| puts " '#{predef}',"} | |
puts "])" | |
puts """ | |
import platform | |
if platform.system()=='Linux': | |
env.Append(CCFLAGS=[ | |
'-fshort-wchar', '-O2', '-fPIC', '-Wall', | |
'-Wno-error=c++0x-compat', '-pipe', '-Wextra', '-Wreturn-type', | |
'-fno-strict-aliasing', '-Wcast-align', '-Wchar-subscripts', '-Wformat-security', '-Wno-unused-parameter', | |
'-Wno-sign-compare', '-Wno-switch', '-Wno-switch-enum', '-Wundef', | |
'-Wmissing-noreturn', '-Winit-self', '-Werror', | |
'-ffunction-sections', '-fdata-sections', | |
# '-fvisibility=hidden', '-fvisibility-inlines-hidden', #Not enabled now; | |
]); | |
else: | |
env.Append(CCFLAGS=[ | |
'/wd4396', '/wd4917', '/wd4619', '/wd4548', '/wd4530', '/wd4365', '/wd4217', '/wd4946', '/wd4928', '/wd4706', | |
'/wd4700', '/wd4512', '/wd4505', '/wd4350', '/wd4347', '/wd4127', '/wd4626', '/wd4625', '/wd4623', '/wd4610', | |
'/wd4510', '/wd4390', '/wd4389', '/wd4266', '/wd4264', '/wd4263', '/wd4242', '/wd4189', '/wd4101', '/wd4067', | |
'/wd4996', '/wd4806', '/wd4800', '/wd4702', '/wd4701', '/wd4565', '/wd4355', '/wd4344', '/wd4309', '/wd4291', | |
'/wd4273', '/wd4244', '/wd4146', '/wd4099', '/wd4065', '/wd4018', '/wd4692', '/wd4826', '/wd4819', '/wd4820', | |
'/wd4738', '/wd4711', '/wd4710', '/wd4668', '/wd4640', '/wd4514', '/wd4324', '/wd4100', '/wd4062', '/wd4061' | |
]); | |
""" | |
puts "env.StaticLibrary(target='#{vcproj_libname}', source=[ #Note: Change to SharedLibrary here if is EAWebKit, or Program if is demo app;" | |
sourceFiles.each{|path| puts " '#{path}',"} | |
puts "], LIBS = [" | |
puts "], LIBPATH = [" | |
puts "])" | |
# support Configuration select now; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment