3 ## Copyright (c) 2013 The WebM project authors. All Rights Reserved.
5 ## Use of this source code is governed by a BSD-style license
6 ## that can be found in the LICENSE file in the root of the source
7 ## tree. An additional intellectual property rights grant can be found
8 ## in the file PATENTS. All contributing project authors may
9 ## be found in the AUTHORS file in the root of the source tree.
13 self_basename=${self##*/}
14 self_dirname=$(dirname "$0")
16 . "$self_dirname/msvs_common.sh"|| exit 127
20 Usage: ${self_basename} --name=projname [options] file1 [file2 ...]
22 This script generates a Visual Studio project file from a list of source
26 --help Print this message
27 --exe Generate a project for building an Application
28 --lib Generate a project for creating a static library
29 --dll Generate a project for creating a dll
30 --static-crt Use the static C runtime (/MT)
31 --enable-werror Treat warnings as errors (/WX)
32 --target=isa-os-cc Target specifier (required)
33 --out=filename Write output to a file [stdout]
34 --name=project_name Name of the project (required)
35 --proj-guid=GUID GUID to use for the project
36 --module-def=filename File containing export definitions (for DLLs)
37 --ver=version Version (10,11,12) of visual studio to generate for
38 --src-path-bare=dir Path to root of source tree
39 -Ipath/to/include Additional include directories
40 -DFLAG[=value] Preprocessor macros to define
41 -Lpath/to/lib Additional library search paths
42 -llibname Library to link against
53 echo "${indent}<${tag}"
56 echo "${indent}>${content}</${tag}>"
59 echo "${indent}<${tag}>${content}</${tag}>"
71 echo "generating filter '$name' from ${#file_list[@]} files" >&2
74 file_list_sz=${#file_list[@]}
75 for i in ${!file_list[@]}; do
77 for pat in ${pats//;/$IFS}; do
78 if [ "${f##*.}" == "$pat" ]; then
81 objf=$(echo ${f%.*}.obj \
82 | sed -e "s,$src_path_bare,," \
83 -e 's/^[\./]\+//g' -e 's,[:/ ],_,g')
85 if ([ "$pat" == "asm" ] || [ "$pat" == "s" ]) && $asm_use_custom_step; then
86 # Avoid object file name collisions, i.e. vpx_config.c and
87 # vpx_config.asm produce the same object file without
88 # this additional suffix.
89 objf=${objf%.obj}_asm.obj
90 open_tag CustomBuild \
92 for plat in "${platforms[@]}"; do
93 for cfg in Debug Release; do
94 tag_content Message "Assembling %(Filename)%(Extension)" \
95 Condition="'\$(Configuration)|\$(Platform)'=='$cfg|$plat'"
96 tag_content Command "$(eval echo \$asm_${cfg}_cmdline) -o \$(IntDir)$objf" \
97 Condition="'\$(Configuration)|\$(Platform)'=='$cfg|$plat'"
98 tag_content Outputs "\$(IntDir)$objf" \
99 Condition="'\$(Configuration)|\$(Platform)'=='$cfg|$plat'"
102 close_tag CustomBuild
103 elif [ "$pat" == "c" ] || \
104 [ "$pat" == "cc" ] || [ "$pat" == "cpp" ]; then
107 # Separate file names with Condition?
108 tag_content ObjectFileName "\$(IntDir)$objf"
109 # Check for AVX and turn it on to avoid warnings.
110 if [[ $f =~ avx.?\.c$ ]]; then
111 tag_content AdditionalOptions "/arch:AVX"
114 elif [ "$pat" == "h" ] ; then
117 elif [ "$pat" == "vcxproj" ] ; then
118 open_tag ProjectReference \
120 depguid=`grep ProjectGuid "$f" | sed 's,.*<.*>\(.*\)</.*>.*,\1,'`
121 tag_content Project "$depguid"
122 tag_content ReferenceOutputAssembly false
123 close_tag ProjectReference
137 # Process command line
144 --target=*) target="${optval}"
146 --out=*) outfile="$optval"
148 --name=*) name="${optval}"
150 --proj-guid=*) guid="${optval}"
152 --module-def=*) module_def="${optval}"
154 --exe) proj_kind="exe"
156 --dll) proj_kind="dll"
158 --lib) proj_kind="lib"
161 src_path_bare=$(fix_path "$optval")
162 src_path_bare=${src_path_bare%/}
164 --static-crt) use_static_runtime=true
166 --enable-werror) werror=true
173 *) die Unrecognized Visual Studio Version in $opt
179 opt=$(fix_path "$opt")
181 incs="${incs}${incs:+;}"${opt}""
182 yasmincs="${yasmincs} -I"${opt}""
184 -D*) defines="${defines}${defines:+;}${opt##-D}"
186 -L*) # fudge . to $(OutDir)
187 if [ "${opt##-L}" == "." ]; then
188 libdirs="${libdirs}${libdirs:+;}"\$(OutDir)""
190 # Also try directories for this platform/configuration
192 opt=$(fix_path "$opt")
193 libdirs="${libdirs}${libdirs:+;}"${opt}""
194 libdirs="${libdirs}${libdirs:+;}"${opt}/\$(PlatformName)/\$(Configuration)""
195 libdirs="${libdirs}${libdirs:+;}"${opt}/\$(PlatformName)""
198 -l*) libs="${libs}${libs:+ }${opt##-l}.lib"
203 # The paths in file_list are fixed outside of the loop.
204 file_list[${#file_list[@]}]="$opt"
206 *.asm|*.s) uses_asm=true
213 # Make one call to fix_path for file_list to improve performance.
216 outfile=${outfile:-/dev/stdout}
217 guid=${guid:-`generate_uuid`}
218 asm_use_custom_step=false
219 uses_asm=${uses_asm:-false}
220 case "${vs_ver:-11}" in
222 asm_use_custom_step=$uses_asm
226 [ -n "$name" ] || die "Project name (--name) must be specified!"
227 [ -n "$target" ] || die "Target (--target) must be specified!"
229 if ${use_static_runtime:-false}; then
230 release_runtime=MultiThreaded
231 debug_runtime=MultiThreadedDebug
234 release_runtime=MultiThreadedDLL
235 debug_runtime=MultiThreadedDebugDLL
239 # Calculate debug lib names: If a lib ends in ${lib_sfx}.lib, then rename
240 # it to ${lib_sfx}d.lib. This precludes linking to release libs from a
241 # debug exe, so this may need to be refactored later.
242 for lib in ${libs}; do
243 if [ "$lib" != "${lib%${lib_sfx}.lib}" ]; then
246 debug_libs="${debug_libs}${debug_libs:+ }${lib}"
248 debug_libs=${debug_libs// /;}
252 # List of all platforms supported for this target
256 asm_Debug_cmdline="yasm -Xvc -g cv8 -f win64 ${yasmincs} "%(FullPath)""
257 asm_Release_cmdline="yasm -Xvc -f win64 ${yasmincs} "%(FullPath)""
261 asm_Debug_cmdline="yasm -Xvc -g cv8 -f win32 ${yasmincs} "%(FullPath)""
262 asm_Release_cmdline="yasm -Xvc -f win32 ${yasmincs} "%(FullPath)""
265 asm_Debug_cmdline="armasm -nologo "%(FullPath)""
266 asm_Release_cmdline="armasm -nologo "%(FullPath)""
267 if [ "$name" = "obj_int_extract" ]; then
268 # We don't want to build this tool for the target architecture,
269 # but for an architecture we can run locally during the build.
275 *) die "Unsupported target $target!"
280 echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
282 DefaultTargets="Build" \
284 xmlns="http://schemas.microsoft.com/developer/msbuild/2003" \
287 Label="ProjectConfigurations"
288 for plat in "${platforms[@]}"; do
289 for config in Debug Release; do
290 open_tag ProjectConfiguration \
291 Include="$config|$plat"
292 tag_content Configuration $config
293 tag_content Platform $plat
294 close_tag ProjectConfiguration
299 open_tag PropertyGroup \
301 tag_content ProjectGuid "{${guid}}"
302 tag_content RootNamespace ${name}
303 tag_content Keyword ManagedCProj
304 if [ $vs_ver -ge 12 ] && [ "${platforms[0]}" = "ARM" ]; then
305 tag_content AppContainerApplication true
306 # The application type can be one of "Windows Store",
307 # "Windows Phone" or "Windows Phone Silverlight". The
308 # actual value doesn't matter from the libvpx point of view,
309 # since a static library built for one works on the others.
310 # The PlatformToolset field needs to be set in sync with this;
311 # for Windows Store and Windows Phone Silverlight it should be
312 # v120 while it should be v120_wp81 if the type is Windows Phone.
313 tag_content ApplicationType "Windows Store"
314 tag_content ApplicationTypeRevision 8.1
316 close_tag PropertyGroup
319 Project="\$(VCTargetsPath)\\Microsoft.Cpp.Default.props"
321 for plat in "${platforms[@]}"; do
322 for config in Release Debug; do
323 open_tag PropertyGroup \
324 Condition="'\$(Configuration)|\$(Platform)'=='$config|$plat'" \
325 Label="Configuration"
326 if [ "$proj_kind" = "exe" ]; then
327 tag_content ConfigurationType Application
328 elif [ "$proj_kind" = "dll" ]; then
329 tag_content ConfigurationType DynamicLibrary
331 tag_content ConfigurationType StaticLibrary
333 if [ "$vs_ver" = "11" ]; then
334 if [ "$plat" = "ARM" ]; then
335 # Setting the wp80 toolchain automatically sets the
336 # WINAPI_FAMILY define, which is required for building
337 # code for arm with the windows headers. Alternatively,
338 # one could add AppContainerApplication=true in the Globals
339 # section and add PrecompiledHeader=NotUsing and
340 # CompileAsWinRT=false in ClCompile and SubSystem=Console
342 tag_content PlatformToolset v110_wp80
344 tag_content PlatformToolset v110
347 if [ "$vs_ver" = "12" ]; then
348 # Setting a PlatformToolset indicating windows phone isn't
349 # enough to build code for arm with MSVC 2013, one strictly
350 # has to enable AppContainerApplication as well.
351 tag_content PlatformToolset v120
353 tag_content CharacterSet Unicode
354 if [ "$config" = "Release" ]; then
355 tag_content WholeProgramOptimization true
357 close_tag PropertyGroup
362 Project="\$(VCTargetsPath)\\Microsoft.Cpp.props"
364 open_tag ImportGroup \
365 Label="PropertySheets"
367 Project="\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props" \
368 Condition="exists('\$(UserRootDir)\\Microsoft.Cpp.\$(Platform).user.props')" \
369 Label="LocalAppDataPlatform"
370 close_tag ImportGroup
375 for plat in "${platforms[@]}"; do
376 plat_no_ws=`echo $plat | sed 's/[^A-Za-z0-9_]/_/g'`
377 for config in Debug Release; do
378 open_tag PropertyGroup \
379 Condition="'\$(Configuration)|\$(Platform)'=='$config|$plat'"
380 tag_content OutDir "\$(SolutionDir)$plat_no_ws\\\$(Configuration)\\"
381 tag_content IntDir "$plat_no_ws\\\$(Configuration)\\${name}\\"
382 if [ "$proj_kind" == "lib" ]; then
383 if [ "$config" == "Debug" ]; then
388 tag_content TargetName "${name}${lib_sfx}${config_suffix}"
390 close_tag PropertyGroup
394 for plat in "${platforms[@]}"; do
395 for config in Debug Release; do
396 open_tag ItemDefinitionGroup \
397 Condition="'\$(Configuration)|\$(Platform)'=='$config|$plat'"
398 if [ "$name" == "vpx" ]; then
400 if [ "$hostplat" == "ARM" ]; then
403 open_tag PreBuildEvent
404 tag_content Command "call obj_int_extract.bat "$src_path_bare" $hostplat\\\$(Configuration)"
405 close_tag PreBuildEvent
408 if [ "$config" = "Debug" ]; then
410 runtime=$debug_runtime
422 runtime=$release_runtime
424 tag_content FavorSizeOrSpeed Speed
429 extradefines=";_CONSOLE"
432 extradefines=";$defines"
435 tag_content Optimization $opt
436 tag_content AdditionalIncludeDirectories "$incs;%(AdditionalIncludeDirectories)"
437 tag_content PreprocessorDefinitions "WIN32;$debug;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE$extradefines;%(PreprocessorDefinitions)"
438 tag_content RuntimeLibrary $runtime
439 tag_content WarningLevel Level3
440 if ${werror:-false}; then
441 tag_content TreatWarningAsError true
443 if [ $vs_ver -ge 11 ]; then
444 # We need to override the defaults for these settings
445 # if AppContainerApplication is set.
446 tag_content CompileAsWinRT false
447 tag_content PrecompiledHeader NotUsing
448 tag_content SDLCheck false
454 if [ "$name" != "obj_int_extract" ]; then
455 tag_content AdditionalDependencies "$curlibs;%(AdditionalDependencies)"
456 tag_content AdditionalLibraryDirectories "$libdirs;%(AdditionalLibraryDirectories)"
458 tag_content GenerateDebugInformation true
459 # Console is the default normally, but if
460 # AppContainerApplication is set, we need to override it.
461 tag_content SubSystem Console
466 tag_content GenerateDebugInformation true
467 tag_content ModuleDefinitionFile $module_def
473 close_tag ItemDefinitionGroup
479 generate_filter "Source Files" "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx;s"
482 generate_filter "Header Files" "h;hm;inl;inc;xsd"
485 generate_filter "Build Files" "mk"
488 generate_filter "References" "vcxproj"
492 Project="\$(VCTargetsPath)\\Microsoft.Cpp.targets"
494 open_tag ImportGroup \
495 Label="ExtensionTargets"
496 close_tag ImportGroup
500 # This must be done from within the {} subshell
501 echo "Ignored files list (${#file_list[@]} items) is:" >&2
502 for f in "${file_list[@]}"; do
507 # This regexp doesn't catch most of the strings in the vcxproj format,
508 # since they're like <tag>path</tag> instead of <tag attr="path" />
509 # as previously. It still seems to work ok despite this.
511 sed -e '/"/s;\([^ "]\)/;\1\\;g' |
512 sed -e '/xmlns/s;\\;/;g' > ${outfile}