(:declare default element namespace "http://schemas.microsoft.com/developer/msbuild/2003";:) declare variable $projectFile external; declare variable $outputPath external; declare variable $xmlversion := "1.0"; declare variable $xmlencoding := "utf-8"; declare variable $msbversion := "4.0"; declare variable $msbnamespace := "http://schemas.microsoft.com/developer/msbuild/2003"; declare variable $msbdefprops := '$(VCTargetsPath)\Microsoft.Cpp.Default.props'; declare variable $msbprops := '$(VCTargetsPath)\Microsoft.Cpp.props'; declare variable $msbtargets := "$(VCTargetsPath)\Microsoft.Cpp.targets"; declare variable $mobile := xs:boolean(doc($projectFile)/projects/variable[@name="mobile"]); declare variable $debugOptLevel := "Disabled"; declare variable $releaseOptLevel := "MaxSpeed"; declare variable $warnLevel := "Level3"; declare variable $debugInfo := "ProgramDatabase"; declare variable $sourcePath := doc($projectFile)/projects/variable[@name="sourcePath"]; declare variable $outputBase := doc($projectFile)/projects/variable[@name="outputBase.10.0"]; declare variable $dllType := "dll"; declare variable $appType := "Application"; declare variable $libprop := "library.props"; declare function local:genImportProperty($libprop) { local:indent(2), {local:indent(4)} local:indent(2) }; declare function local:indent($n) { concat(" ",string-join(for $i in (1 to $n) return " ", "")) }; declare function local:getPlatforms($version) { if ($version eq "7.10") then ("Win32") else ("Win32", "x64", "IA64") }; declare function local:getGuid($project) { concat("{",$project/@guid,"}") }; declare function local:generateProjectConfigurations($project, $vsversion) { local:indent(2), {for $config in local:getConfiguration($project) return for $platform in local:getPlatforms($vsversion) return (local:indent(4), {local:indent(6)}{$config} {local:indent(6)}{$platform} {local:indent(4)}) } {local:indent(2)} }; declare function local:generateGlobalProperty($project) { local:indent(2), {local:indent(2)}{local:getGuid($project)} {local:indent(2)} }; declare function local:configurationType($project, $config) { if ($project/type eq "library") then if (contains($config,"Static")) then "StaticLibrary" else "DynamicLibrary" else if ($project/type eq "app") then "Application" else error(QName("","xqilla"),"configurationType:unkown project type") }; declare function local:generateConfigurations($project, $vsversion) { for $platform in local:getPlatforms($vsversion) return for $config in local:getConfiguration($project) let $configType := local:configurationType($project,$config) return (local:indent(2), {local:indent(4)}{$configType} {local:indent(4)}false {local:indent(4)}MultiByte {local:indent(2)} ) }; declare function local:genExtensionSettings() { local:indent(2), {local:indent(2)} }; declare function local:genExtensionTargets() { local:indent(2), {local:indent(2)} }; declare variable $msbuserprops := "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"; declare variable $msbuserpropsexit := "exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"; declare function local:genPropertySheets($project, $vsversion) { for $platform in local:getPlatforms($vsversion) return for $config in local:getConfiguration($project) return (local:indent(2), {local:indent(4)} {local:indent(4)} ) }; declare function local:windowsPath($path) as xs:string { translate($path,"/","\\") }; declare function local:generateOutDir($config) { local:windowsPath(concat($outputBase, "$(Platform)", "/", $config, "/")) }; (:becaues zlib has different 32 and 64 bits platform libraries, so use another getLibName:) declare function local:getLibName($name, $config) { doc($projectFile)/projects/library[@name=$name]/libname[@config=$config and not(@platform eq "x64")]/text() }; declare function local:getLibNameWithPlatform($name, $config, $platform) { let $libnamePlatform := doc($projectFile)/projects/library[@name=$name]/libname[@config=$config and @platform=$platform]/text() let $libname := doc($projectFile)/projects/library[@name=$name]/libname[@config=$config and not(@platform)]/text() return if ($libnamePlatform) then ($libnamePlatform) else ($libname) }; declare function local:genMacros($project, $vsversion) { local:genDynamicMacros($project, $vsversion) }; declare function local:genTargetName($project,$config) { if ($project/type eq "library") then local:getLibName($project/@name, $config) else if (not(empty($project/@output))) then data($project/@output) else data($project/@name) }; declare function local:genTargetExt($project, $config) { if ($project/type eq "library") then if (contains($config, "Static")) then ".lib" else ".dll" else ".exe" }; (: no static variable usage now :) declare function local:genDynamicMacros($project, $vsversion) { local:indent(2), {local:indent(4)}<_ProjectFileVersion>10.0.30319.1 {for $platform in local:getPlatforms($vsversion) return for $config in local:getConfiguration($project) return (local:indent(4), {local:generateOutDir($config)}, local:indent(4), {concat("./$(OutDir)",$project/@name,"\")}, local:indent(4),false, local:indent(4),{local:genTargetName($project,$config)}, local:indent(4),{local:genTargetExt($project, $config)} ) } {local:indent(2)} }; declare function local:isDebug($config) as xs:boolean { contains($config,"Debug") }; declare function local:isRelease($config) as xs:boolean { contains($config,"Release") }; declare function local:optLevel($config) { if (local:isDebug($config)) then $debugOptLevel else $releaseOptLevel }; declare function local:addIncludeDirectories($project,$config) { let $incref := for $inc in $project/include[@type="ref"] return doc($projectFile)/projects/include[@name=$inc] let $increl := $project/include[@type="rel"] return translate(concat(string-join($incref,";"), if (not(empty($increl)) and not(empty($incref))) then ";" else "", string-join($increl,";"),";","%(AdditionalIncludeDirectories)"),",",";") }; declare function local:getProjectType($project, $config) { if ($project/type eq "library") then if (contains($config,"Static")) then "static_lib" else "dll" else if ($project/type eq "app") then if (contains($config,"Static")) then "static_app" else "app" else error(QName("","dbxml"),"getProjectType:unkown project type") }; declare function local:generateCompilerPreprocessorDefs($project,$config) { let $ptype := local:getProjectType($project, $config) let $generic := doc($projectFile)/projects/preprocessor[@config="all" or contains($config,@config)] let $type := doc($projectFile)/projects/preprocessor[@config=$ptype] let $proj := $project/preprocessor[@config="all" or @config=$config] let $projType := $project/preprocessor[@config=$ptype] return concat(string-join(($generic,$type,$proj,$projType),";"),";","%(PreprocessorDefinitions)") }; declare function local:runtimeLibrary($config) { if (local:isDebug($config)) then if (contains($config,"Static")) then "MultiThreadedDebug" else "MultiThreadedDebugDLL" else if (contains($config,"Static")) then "MultiThreaded" else "MultiThreadedDLL" }; declare function local:makeObjectFile($project,$config) { concat("$(OutDir)", if (not(empty($project/@output))) then $project/@output else $project/@name,"/") }; declare function local:addDebugInformation($config) { local:indent(6),{$debugInfo}, if (local:isDebug($config)) then (local:indent(6),EnableFastChecks) else () }; declare function local:addLinkOptions($project, $platform, $config) { let $machine := if (contains($platform,"Win32")) then "/machine:x86" else concat("/machine:",$platform) let $opt := string-join(($machine,$project/options/link[contains(@config,$config)])," ") return if (not($opt eq " ")) then (local:indent(6),{string-join(($opt,"%(AdditionalOptions)")," ")} ) else () }; declare function local:addLibraryDependencies($project,$config,$platform) { string-join(for $dep in $project/depends return concat(local:getLibNameWithPlatform($dep,$config,$platform),".lib"), ";") }; declare function local:addProjectDependencies($project) { for $mydep in $project/references let $mytemp := ( if ($mydep eq "XercesLib") then '{152CE948-F659-4206-A50A-1D2B9658EF96}' else if ($mydep eq "xqilla") then '{63E85107-41E0-4FC7-8083-40E85861B426}' else lower-case(concat("{",doc($projectFile)/projects/project[@name=$mydep]/@guid,"}")) ) return (local:indent(4), {local:indent(6)}{$mytemp} {local:indent(6)}false {local:indent(4)}) }; declare function local:makeLibraryDirectory($lib,$platform,$config, $vsversion) { for $dir in $lib/platform[contains(@name,$platform)]/config[$config=./@type]/libdir return if (not(empty($lib/libbase[@vsver=$vsversion]))) then concat($lib/libbase[@vsver=$vsversion],"/",$dir) else $dir }; declare function local:addLibraryDirectories($project, $platform, $config, $vsversion) { string-join((for $dep in $project/depends return local:makeLibraryDirectory(doc($projectFile)/projects/library[@name=$dep],$platform,$config, $vsversion),"../lib"),";") }; declare function local:makeOutputPDBFile($project,$config) { if ($project/type eq "library") then concat("$(OutDir)",local:getLibName($project/@name,$config),".pdb") else concat("$(OutDir)",if (not(empty($project/@output))) then $project/@output else $project/@name,".pdb") }; declare function local:makeImportLibrary($project,$config) { if ($project/type eq "library" and not(contains($config,"Static"))) then (local:indent(6),{concat("$(OutDir)",local:getLibName($project/@name,$config),".lib")}) else () }; declare function local:makeModuleDefinition($project,$config) { if (not(empty($project/moddef))) then let $temp := concat($sourcePath,$project/moddef/@file) return (local:indent(6),{local:windowsPath($temp)}) else () }; declare function local:generateCustomBuildTool($project,$config) { if (not(empty($project/event[@name="custom"]))) then let $commandtext := $project/event[@name="custom"]/command[contains(@config,$config)]/text() let $outputs := concat($project/event[@name="custom"]/output,";%(Outputs)") return ( local:indent(4), {local:indent(6)}{$commandtext} {local:indent(6)}{$outputs} {local:indent(4)}) else if (not(empty($project/event[@name="postbuild"]))) then let $commandtext := $project/event[@name="postbuild"]/command[contains(@config,$config)]/text() let $message := $project/event[@name="postbuild"]/description return ( local:indent(4), {local:indent(6)}{$commandtext} {local:indent(6)}{$message} {local:indent(4)}) else () }; declare function local:genDefinition($project,$vsversion) { local:genDynamicDefinition($project,$vsversion) }; declare function local:generateConfigCompiler($project,$platform,$config) { local:indent(4), {local:indent(6)}{local:optLevel($config)} {local:indent(6)}true {if (local:isRelease($config)) then (local:indent(6),OnlyExplicitInline) else ()} {local:indent(6)}{local:addIncludeDirectories($project,$config)} {local:indent(6)}{local:generateCompilerPreprocessorDefs($project,$config)} {local:indent(6)}true {local:indent(6)}{local:runtimeLibrary($config)} {if (local:isRelease($config)) then (local:indent(6),true) else ()} {local:indent(6)} {local:indent(6)} {local:indent(6)}{concat("./$(OutDir)", $project/@name, ".pch")} {local:indent(6)}{local:makeObjectFile($project,$config)} {local:indent(6)}{local:makeObjectFile($project,$config)} {local:indent(6)}{$warnLevel} {local:indent(6)}true {local:addDebugInformation($config)} {local:indent(6)}Default {local:indent(4)} }; declare function local:generateDynamicLink($project, $platform, $config, $vsversion) { local:indent(4), {local:addLinkOptions($project,$platform,$config)} {local:indent(6)}{local:addLibraryDependencies($project,$config,$platform)};%(AdditionalDependencies) {local:indent(6)}{local:addLibraryDirectories($project,$platform,$config,$vsversion)};%(AdditionalLibraryDirectories) {local:indent(6)}$(OutDir)$(TargetName)$(TargetExt) {local:indent(6)}{local:makeOutputPDBFile($project,$config)} {local:indent(6)}true {local:indent(6)}true {local:makeImportLibrary($project,$config)} {local:indent(6)}true {local:makeModuleDefinition($project,$config)} {local:indent(6)}{if (contains($platform,"(ARMV4)")) then "MachineARM" else "NotSet"} {local:indent(4)} }; declare function local:generateConfigLibrarian($project,$platform,$config) { local:indent(4), {local:indent(6)}$(OutDir)$(TargetName)$(TargetExt) {local:addLinkOptions($project,$platform,$config)} {local:indent(4)} }; declare function local:generateStaticLink($project,$platform,$config,$vsversion) { if (contains($project/type,"lib")) then local:generateConfigLibrarian($project,$platform,$config) else local:generateDynamicLink($project,$platform,$config, $vsversion) }; declare function local:genDynamicDefinition($project,$vsversion) { for $platform in local:getPlatforms($vsversion) return for $config in local:getConfiguration($project) let $static := contains($config, "Static") return ( local:indent(2), {local:generateConfigCompiler($project,$platform,$config)} {if ($static) then local:generateStaticLink($project,$platform,$config, $vsversion) else local:generateDynamicLink($project,$platform,$config,$vsversion)} {local:generateCustomBuildTool($project,$config)} {local:indent(2)} ) }; declare function local:genStaticDefinition($project, $vsversion) { for $platform in local:getPlatforms($vsversion) return for $config in local:getConfiguration($project) return ( local:indent(2), {local:generateConfigCompiler($project,$platform,$config)} {local:generateStaticLink($project,$platform,$config,$vsversion)} {local:generateCustomBuildTool($project,$config)} {local:indent(2)} ) }; declare function local:generateIncFilesNoFilter($project) { for $file in $project/files//file return if (ends-with($file/@name,".h") or ends-with($file/@name,".hpp")) then (local:indent(4),) else () }; declare function local:generateSrcFilesNoFilter($project) { for $file in $project/files//file return if (ends-with($file/@name,".rc") or ends-with($file/@name,".def") or ends-with($file/@name,".h") or ends-with($file/@name,".hpp")) then () else (local:indent(4),) }; declare function local:generateRcFilesNoFilter($project, $vsversion) { for $file in $project/files//file return if (ends-with($file/@name,".rc")) then (local:indent(2), {local:indent(4)} {for $platform in local:getPlatforms($vsversion) return for $config in local:getConfiguration($project) return( local:indent(6), {concat(if ($config="Debug") then "_DEBUG" else "NDEBUG",";","$(NoInherit))",";%(PreprocessorDefinitions)")}) } {local:indent(4)} {local:indent(2)} ) else () }; declare function local:generateDefFilesNoFilter($project) { for $file in $project/files//file return if (ends-with($file/@name,".def")) then ( local:indent(2), {local:indent(4)} {local:indent(2)} ) else () }; declare function local:generateFilesWithFilter($project,$filter) { }; declare function local:genFiles($project,$vsversion) { local:indent(2), {local:generateIncFilesNoFilter($project)} {local:indent(2)}, local:indent(2), {local:generateSrcFilesNoFilter($project)} {local:indent(2)}, local:generateDefFilesNoFilter($project), local:generateRcFilesNoFilter($project,$vsversion) }; declare function local:getConfiguration($project) { for $compType in ("Debug", "Release") return for $config in $project/configuration return concat($config, $compType) }; declare function local:getOutputName($project, $vsversion) { let $vsname := if($vsversion = "7.10") then "VC7.1" else if($vsversion = "8.00") then "VC8" else "VC10" let $postfix := if($vsversion = "10.0") then ".vcxproj" else ".vcproj" return concat($outputPath, "/", $vsname, "/", $project/@name, $postfix) }; declare function local:getVsversion() { (: Only be suitable when version >= 10.0 :) distinct-values(doc($projectFile)//visualstudioversion[fn:number(.) >= 10.0]) }; declare function local:getProjects() { doc($projectFile)/projects/project }; for $vsversion in local:getVsversion() for $project in local:getProjects() return put( {local:generateProjectConfigurations($project, $vsversion)} {local:generateGlobalProperty($project)} {local:indent(2)} {local:generateConfigurations($project, $vsversion)} {local:indent(2)} {local:genExtensionSettings()} {local:genPropertySheets($project, $vsversion)} {local:indent(2)} {local:genMacros($project, $vsversion)} {local:genDefinition($project,$vsversion)} {local:genFiles($project,$vsversion)} {local:indent(2)} {local:genExtensionTargets()} {local:indent(2)} {local:addProjectDependencies($project)} {local:indent(2)} {local:indent(0)}, local:getOutputName($project, $vsversion))