aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bootstrap.ps131
-rw-r--r--scripts/buildsystems/msbuild/applocal.ps127
-rw-r--r--scripts/buildsystems/msbuild/vcpkg.targets58
-rw-r--r--scripts/buildsystems/vcpkg.cmake52
-rw-r--r--scripts/cmake/vcpkg_apply_patches.cmake19
-rw-r--r--scripts/cmake/vcpkg_build_cmake.cmake17
-rw-r--r--scripts/cmake/vcpkg_build_msbuild.cmake32
-rw-r--r--scripts/cmake/vcpkg_common_functions.cmake10
-rw-r--r--scripts/cmake/vcpkg_configure_cmake.cmake54
-rw-r--r--scripts/cmake/vcpkg_copy_pdbs.cmake38
-rw-r--r--scripts/cmake/vcpkg_download_distfile.cmake20
-rw-r--r--scripts/cmake/vcpkg_execute_required_process.cmake21
-rw-r--r--scripts/cmake/vcpkg_extract_source_archive.cmake14
-rw-r--r--scripts/cmake/vcpkg_find_acquire_program.cmake51
-rw-r--r--scripts/cmake/vcpkg_install_cmake.cmake17
-rw-r--r--scripts/doVcpkgRelease.ps184
-rw-r--r--scripts/fetchDependency.ps1212
-rw-r--r--scripts/ports.cmake85
-rw-r--r--scripts/templates/portfile.in.cmake21
19 files changed, 863 insertions, 0 deletions
diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1
new file mode 100644
index 000000000..568f56995
--- /dev/null
+++ b/scripts/bootstrap.ps1
@@ -0,0 +1,31 @@
+[CmdletBinding()]
+param(
+ [ValidateNotNullOrEmpty()]
+ [string]$disableMetrics = "0"
+)
+
+$vcpkgRoot = (get-item $PSScriptRoot).parent.FullName
+
+$gitHash = git rev-parse HEAD
+Write-Verbose("Git hash is " + $gitHash)
+$gitStartOfHash = $gitHash.substring(0,6)
+$vcpkgSourcesPath = "$vcpkgRoot\toolsrc"
+Write-Verbose("vcpkg Path " + $vcpkgSourcesPath)
+
+if (!(Test-Path $vcpkgSourcesPath))
+{
+ New-Item -ItemType directory -Path $vcpkgSourcesPath -force | Out-Null
+}
+
+try{
+ pushd $vcpkgSourcesPath
+ cmd /c "$env:VS140COMNTOOLS..\..\VC\vcvarsall.bat" x86 "&" msbuild "/p:VCPKG_VERSION=-$gitHash" "/p:DISABLE_METRICS=$disableMetrics" /p:Configuration=Release /p:Platform=x86 /m
+
+ Write-Verbose("Placing vcpkg.exe in the correct location")
+
+ Copy-Item $vcpkgSourcesPath\Release\vcpkg.exe $vcpkgRoot\vcpkg.exe | Out-Null
+ Copy-Item $vcpkgSourcesPath\Release\vcpkgmetricsuploader.exe $vcpkgRoot\scripts\vcpkgmetricsuploader.exe | Out-Null
+}
+finally{
+ popd
+}
diff --git a/scripts/buildsystems/msbuild/applocal.ps1 b/scripts/buildsystems/msbuild/applocal.ps1
new file mode 100644
index 000000000..70528e078
--- /dev/null
+++ b/scripts/buildsystems/msbuild/applocal.ps1
@@ -0,0 +1,27 @@
+[cmdletbinding()]
+param([string]$targetBinary, [string]$installedDir, [string]$tlogFile)
+
+function resolve($targetBinary) {
+ $targetBinaryPath = Resolve-Path $targetBinary
+ $targetBinaryDir = Split-Path $targetBinaryPath -parent
+
+ $a = $(link /dump /imports $targetBinary | ? { $_ -match "^ [^ ].*\.dll" } | % { $_ -replace "^ ","" })
+ $a | % {
+ if (Test-Path "$installedDir\$_") {
+ if (Test-Path "$targetBinaryDir\$_") {
+ Write-Verbose "$_ is already present"
+ }
+ else {
+ Copy-Item $installedDir\$_ $targetBinaryDir
+ Write-Verbose "Copying $installedDir\$_ -> $_"
+ }
+ "$targetBinaryDir\$_"
+ if ($tlogFile) { Add-Content $tlogFile "$targetBinaryDir\$_" }
+ resolve("$targetBinaryDir\$_")
+ } else {
+ Write-Verbose "$installedDir\$_ not found"
+ }
+ }
+}
+
+resolve($targetBinary) \ No newline at end of file
diff --git a/scripts/buildsystems/msbuild/vcpkg.targets b/scripts/buildsystems/msbuild/vcpkg.targets
new file mode 100644
index 000000000..3a74099f0
--- /dev/null
+++ b/scripts/buildsystems/msbuild/vcpkg.targets
@@ -0,0 +1,58 @@
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition="'$(Platform)|$(ApplicationType)|$(ApplicationTypeRevision)' == 'Win32||'">
+ <VCPkgEnabled Condition="'$(VCPkgEnabled)' == ''">true</VCPkgEnabled>
+ <VCPkgTriplet Condition="'$(VCPkgTriplet)' == ''">x86-windows</VCPkgTriplet>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Platform)|$(ApplicationType)|$(ApplicationTypeRevision)' == 'Win32|Windows Store|10.0'">
+ <VCPkgEnabled Condition="'$(VCPkgEnabled)' == ''">true</VCPkgEnabled>
+ <VCPkgTriplet Condition="'$(VCPkgTriplet)' == ''">x86-uwp</VCPkgTriplet>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Platform)|$(ApplicationType)|$(ApplicationTypeRevision)' == 'x64||'">
+ <VCPkgEnabled Condition="'$(VCPkgEnabled)' == ''">true</VCPkgEnabled>
+ <VCPkgTriplet Condition="'$(VCPkgTriplet)' == ''">x64-windows</VCPkgTriplet>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Platform)|$(ApplicationType)|$(ApplicationTypeRevision)' == 'x64|Windows Store|10.0'">
+ <VCPkgEnabled Condition="'$(VCPkgEnabled)' == ''">true</VCPkgEnabled>
+ <VCPkgTriplet Condition="'$(VCPkgTriplet)' == ''">x64-uwp</VCPkgTriplet>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Platform)|$(ApplicationType)|$(ApplicationTypeRevision)' == 'arm|Windows Store|10.0'">
+ <VCPkgEnabled Condition="'$(VCPkgEnabled)' == ''">true</VCPkgEnabled>
+ <VCPkgTriplet Condition="'$(VCPkgTriplet)' == ''">arm-uwp</VCPkgTriplet>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(VCPkgEnabled)' == 'true'">
+ <VCPkgConfiguration Condition="'$(VCPkgConfiguration)' == ''">$(Configuration)</VCPkgConfiguration>
+ <!-- Expected to ..\..\..\ over scripts\buildsystems\msbuild -->
+ <VCPkgRoot Condition="'$(VCPkgRoot)' == ''">$(MSBuildThisFileDirectory)..\..\..\installed\$(VCPkgTriplet)\</VCPkgRoot>
+ </PropertyGroup>
+
+ <ItemDefinitionGroup Condition="'$(VCPkgEnabled)' == 'true'">
+ <Link>
+ <AdditionalDependencies Condition="'$(VCPkgConfiguration)' == 'Debug'">$(VCPkgRoot)debug\lib\*.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies Condition="'$(VCPkgConfiguration)' == 'Release'">$(VCPkgRoot)lib\*.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ </Link>
+ <ClCompile>
+ <AdditionalIncludeDirectories>$(VCPkgRoot)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ </ClCompile>
+ </ItemDefinitionGroup>
+
+ <Target Name="AppLocalFromInstalled" AfterTargets="CopyFilesToOutputDirectory" BeforeTargets="CopyLocalFilesOutputGroup" Condition="'$(VCPkgEnabled)' == 'true' and '$(OutputType)' == 'exe'">
+ <WriteLinesToFile
+ File="$(TLogLocation)$(ProjectName).write.1u.tlog"
+ Lines="^$(OutputPath)$(TargetName).$(OutputType);" Encoding="Unicode"/>
+ <Exec Condition="'$(VCPkgConfiguration)' == 'Debug'"
+ Command="powershell.exe -ExecutionPolicy Unrestricted -noprofile -File %22$(MSBuildThisFileDirectory)applocal.ps1%22 %22$(OutputPath)$(TargetName).$(OutputType)%22 %22$(VCPkgRoot)debug\bin%22 %22$(TLogLocation)$(ProjectName).write.1u.tlog%22"
+ ConsoleToMSBuild="true">
+ <Output TaskParameter="ConsoleOutput" ItemName="ReferenceCopyLocalPaths" />
+ </Exec>
+ <Exec Condition="'$(VCPkgConfiguration)' == 'Release'"
+ Command="powershell.exe -ExecutionPolicy Unrestricted -noprofile -File %22$(MSBuildThisFileDirectory)applocal.ps1%22 %22$(OutputPath)$(TargetName).$(OutputType)%22 %22$(VCPkgRoot)bin%22 %22$(TLogLocation)$(ProjectName).write.1u.tlog%22"
+ ConsoleToMSBuild="true">
+ <Output TaskParameter="ConsoleOutput" ItemName="ReferenceCopyLocalPaths" />
+ </Exec>
+ </Target>
+</Project>
diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake
new file mode 100644
index 000000000..26cc8a57b
--- /dev/null
+++ b/scripts/buildsystems/vcpkg.cmake
@@ -0,0 +1,52 @@
+if(NOT VCPKG_TOOLCHAIN)
+ if(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$")
+ set(_VCPKG_TARGET_TRIPLET_ARCH x86)
+ elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$")
+ set(_VCPKG_TARGET_TRIPLET_ARCH x64)
+ elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$")
+ set(_VCPKG_TARGET_TRIPLET_ARCH arm)
+ else()
+ if(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015 Win64$")
+ set(_VCPKG_TARGET_TRIPLET_ARCH x64)
+ elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015 ARM$")
+ set(_VCPKG_TARGET_TRIPLET_ARCH arm)
+ else()
+ set(_VCPKG_TARGET_TRIPLET_ARCH x86)
+ endif()
+ endif()
+
+ if(WINDOWS_STORE OR WINDOWS_PHONE)
+ set(_VCPKG_TARGET_TRIPLET_PLAT uwp)
+ else()
+ set(_VCPKG_TARGET_TRIPLET_PLAT windows)
+ endif()
+
+ set(_VCPKG_TARGET_TRIPLET ${_VCPKG_TARGET_TRIPLET_ARCH}-${_VCPKG_TARGET_TRIPLET_PLAT})
+
+ set(_VCPKG_TOOLCHAIN_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+ if(CMAKE_BUILD_TYPE MATCHES "^Debug$" OR NOT DEFINED CMAKE_BUILD_TYPE)
+ list(APPEND CMAKE_PREFIX_PATH
+ ${CMAKE_CURRENT_LIST_DIR}/../installed/${_VCPKG_TARGET_TRIPLET}/debug
+ )
+ endif()
+ list(APPEND CMAKE_PREFIX_PATH
+ ${CMAKE_CURRENT_LIST_DIR}/../installed/${_VCPKG_TARGET_TRIPLET}
+ )
+
+ include_directories(${CMAKE_CURRENT_LIST_DIR}/../installed/${_VCPKG_TARGET_TRIPLET}/include)
+
+ option(OVERRIDE_ADD_EXECUTABLE "Automatically copy dependencies into the output directory for executables." ON)
+ if(OVERRIDE_ADD_EXECUTABLE)
+ function(add_executable name)
+ _add_executable(${ARGV})
+ add_custom_command(TARGET ${name} POST_BUILD
+ COMMAND powershell -executionpolicy remotesigned -file ${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1
+ -targetBinary $<TARGET_FILE:${name}>
+ -installedDir "${_VCPKG_TOOLCHAIN_DIR}/../installed/${_VCPKG_TARGET_TRIPLET}$<$<CONFIG:Debug>:/debug>/bin"
+ -OutVariable out
+ )
+ endfunction()
+ endif()
+ set(VCPKG_TOOLCHAIN ON)
+endif()
diff --git a/scripts/cmake/vcpkg_apply_patches.cmake b/scripts/cmake/vcpkg_apply_patches.cmake
new file mode 100644
index 000000000..939edbd14
--- /dev/null
+++ b/scripts/cmake/vcpkg_apply_patches.cmake
@@ -0,0 +1,19 @@
+function(vcpkg_apply_patches)
+ cmake_parse_arguments(_ap "" "SOURCE_PATH" "PATCHES" ${ARGN})
+
+ find_program(GIT git)
+ set(PATCHNUM 0)
+ foreach(PATCH ${_ap_PATCHES})
+ message(STATUS "Applying patch ${PATCH}")
+ set(LOGNAME patch-${TARGET_TRIPLET}-${PATCHNUM})
+ execute_process(
+ COMMAND ${GIT} --work-tree=. apply "${PATCH}" --ignore-whitespace --whitespace=nowarn --verbose
+ OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-out.log
+ ERROR_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-err.log
+ WORKING_DIRECTORY ${_ap_SOURCE_PATH}
+ RESULT_VARIABLE error_code
+ )
+ message(STATUS "Applying patch ${PATCH} done")
+ math(EXPR PATCHNUM "${PATCHNUM}+1")
+ endforeach()
+endfunction()
diff --git a/scripts/cmake/vcpkg_build_cmake.cmake b/scripts/cmake/vcpkg_build_cmake.cmake
new file mode 100644
index 000000000..33990d9b0
--- /dev/null
+++ b/scripts/cmake/vcpkg_build_cmake.cmake
@@ -0,0 +1,17 @@
+function(vcpkg_build_cmake)
+ message(STATUS "Build ${TARGET_TRIPLET}-rel")
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} --build . --config Release -- /p:VCPkgLocalAppDataDisabled=true
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
+ LOGNAME build-${TARGET_TRIPLET}-rel
+ )
+ message(STATUS "Build ${TARGET_TRIPLET}-rel done")
+
+ message(STATUS "Build ${TARGET_TRIPLET}-dbg")
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} --build . --config Debug -- /p:VCPkgLocalAppDataDisabled=true
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
+ LOGNAME build-${TARGET_TRIPLET}-dbg
+ )
+ message(STATUS "Build ${TARGET_TRIPLET}-dbg done")
+endfunction()
diff --git a/scripts/cmake/vcpkg_build_msbuild.cmake b/scripts/cmake/vcpkg_build_msbuild.cmake
new file mode 100644
index 000000000..bf7c1b546
--- /dev/null
+++ b/scripts/cmake/vcpkg_build_msbuild.cmake
@@ -0,0 +1,32 @@
+function(vcpkg_build_msbuild)
+ cmake_parse_arguments(_csc "" "PROJECT_PATH;RELEASE_CONFIGURATION;DEBUG_CONFIGURATION" "OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE" ${ARGN})
+
+ if(NOT DEFINED _csc_RELEASE_CONFIGURATION)
+ set(_csc_RELEASE_CONFIGURATION Release)
+ endif()
+ if(NOT DEFINED _csc_DEBUG_CONFIGURATION)
+ set(_csc_DEBUG_CONFIGURATION Debug)
+ endif()
+
+ message(STATUS "Building ${_csc_PROJECT_PATH} for Release")
+ file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
+ vcpkg_execute_required_process(
+ COMMAND msbuild ${_csc_PROJECT_PATH} ${_csc_OPTIONS} ${_csc_OPTIONS_RELEASE}
+ /p:Configuration=${_csc_RELEASE_CONFIGURATION}
+ /p:Platform=${TRIPLET_SYSTEM_ARCH}
+ /p:VCPkgLocalAppDataDisabled=true
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
+ LOGNAME build-${TARGET_TRIPLET}-rel
+ )
+
+ message(STATUS "Building ${_csc_PROJECT_PATH} for Debug")
+ file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
+ vcpkg_execute_required_process(
+ COMMAND msbuild ${_csc_PROJECT_PATH} ${_csc_OPTIONS} ${_csc_OPTIONS_DEBUG}
+ /p:Configuration=${_csc_DEBUG_CONFIGURATION}
+ /p:Platform=${TRIPLET_SYSTEM_ARCH}
+ /p:VCPkgLocalAppDataDisabled=true
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
+ LOGNAME build-${TARGET_TRIPLET}-dbg
+ )
+endfunction() \ No newline at end of file
diff --git a/scripts/cmake/vcpkg_common_functions.cmake b/scripts/cmake/vcpkg_common_functions.cmake
new file mode 100644
index 000000000..59824eb17
--- /dev/null
+++ b/scripts/cmake/vcpkg_common_functions.cmake
@@ -0,0 +1,10 @@
+include(vcpkg_download_distfile)
+include(vcpkg_extract_source_archive)
+include(vcpkg_execute_required_process)
+include(vcpkg_find_acquire_program)
+include(vcpkg_build_cmake)
+include(vcpkg_build_msbuild)
+include(vcpkg_install_cmake)
+include(vcpkg_configure_cmake)
+include(vcpkg_apply_patches)
+include(vcpkg_copy_pdbs) \ No newline at end of file
diff --git a/scripts/cmake/vcpkg_configure_cmake.cmake b/scripts/cmake/vcpkg_configure_cmake.cmake
new file mode 100644
index 000000000..aa85c8ff4
--- /dev/null
+++ b/scripts/cmake/vcpkg_configure_cmake.cmake
@@ -0,0 +1,54 @@
+find_program(vcpkg_configure_cmake_NINJA ninja)
+function(vcpkg_configure_cmake)
+ cmake_parse_arguments(_csc "" "SOURCE_PATH;GENERATOR" "OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE" ${ARGN})
+
+ if(_csc_GENERATOR)
+ set(GENERATOR ${_csc_GENERATOR})
+ elseif(TRIPLET_SYSTEM_NAME MATCHES "uwp" AND TRIPLET_SYSTEM_ARCH MATCHES "x86")
+ set(GENERATOR "Visual Studio 14 2015")
+ elseif(TRIPLET_SYSTEM_NAME MATCHES "uwp" AND TRIPLET_SYSTEM_ARCH MATCHES "x64")
+ set(GENERATOR "Visual Studio 14 2015 Win64")
+ elseif(TRIPLET_SYSTEM_NAME MATCHES "uwp" AND TRIPLET_SYSTEM_ARCH MATCHES "arm")
+ set(GENERATOR "Visual Studio 14 2015 ARM")
+ # elseif(NOT vcpkg_configure_cmake_NINJA MATCHES "NOTFOUND")
+ # set(GENERATOR "Ninja")
+ elseif(TRIPLET_SYSTEM_ARCH MATCHES "x86")
+ set(GENERATOR "Visual Studio 14 2015")
+ elseif(TRIPLET_SYSTEM_ARCH MATCHES "x64")
+ set(GENERATOR "Visual Studio 14 2015 Win64")
+ elseif(TRIPLET_SYSTEM_ARCH MATCHES "arm")
+ set(GENERATOR "Visual Studio 14 2015 ARM")
+ endif()
+
+ file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
+
+ message(STATUS "Configuring ${TARGET_TRIPLET}-rel")
+ file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel)
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} ${_csc_SOURCE_PATH} ${_csc_OPTIONS} ${_csc_OPTIONS_RELEASE}
+ -G ${GENERATOR}
+ -DCMAKE_VERBOSE_MAKEFILE=ON
+ -DCMAKE_BUILD_TYPE=Release
+ -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
+ -DCMAKE_PREFIX_PATH=${CURRENT_INSTALLED_DIR}
+ -DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
+ LOGNAME config-${TARGET_TRIPLET}-rel
+ )
+ message(STATUS "Configuring ${TARGET_TRIPLET}-rel done")
+
+ message(STATUS "Configuring ${TARGET_TRIPLET}-dbg")
+ file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg)
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} ${_csc_SOURCE_PATH} ${_csc_OPTIONS} ${_csc_OPTIONS_DEBUG}
+ -G ${GENERATOR}
+ -DCMAKE_VERBOSE_MAKEFILE=ON
+ -DCMAKE_BUILD_TYPE=Debug
+ -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
+ -DCMAKE_PREFIX_PATH=${CURRENT_INSTALLED_DIR}/debug\\\\\\\;${CURRENT_INSTALLED_DIR}
+ -DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
+ LOGNAME config-${TARGET_TRIPLET}-dbg
+ )
+ message(STATUS "Configuring ${TARGET_TRIPLET}-dbg done")
+endfunction() \ No newline at end of file
diff --git a/scripts/cmake/vcpkg_copy_pdbs.cmake b/scripts/cmake/vcpkg_copy_pdbs.cmake
new file mode 100644
index 000000000..b99649d59
--- /dev/null
+++ b/scripts/cmake/vcpkg_copy_pdbs.cmake
@@ -0,0 +1,38 @@
+function(vcpkg_copy_pdbs)
+ function(merge_filelist OUTVAR INVAR)
+ set(MSG "")
+ foreach(VAR ${${INVAR}})
+ set(MSG "${MSG} ${VAR}\n")
+ endforeach()
+ set(${OUTVAR} ${MSG} PARENT_SCOPE)
+ endfunction()
+
+ file(GLOB_RECURSE DLLS ${CURRENT_PACKAGES_DIR}/bin/*.dll ${CURRENT_PACKAGES_DIR}/debug/bin/*.dll)
+
+ set(DLLS_WITHOUT_MATCHING_PDBS)
+
+ foreach(DLL ${DLLS})
+ execute_process(COMMAND dumpbin /PDBPATH ${DLL}
+ COMMAND findstr PDB
+ OUTPUT_VARIABLE PDB_LINE
+ ERROR_QUIET
+ RESULT_VARIABLE error_code
+ )
+
+ if(NOT error_code AND PDB_LINE MATCHES "PDB file found at")
+ string(REGEX MATCH '.*' PDB_PATH ${PDB_LINE}) # Extract the path which is in single quotes
+ string(REPLACE ' "" PDB_PATH ${PDB_PATH}) # Remove single quotes
+ get_filename_component(DLL_DIR ${DLL} DIRECTORY)
+ file(COPY ${PDB_PATH} DESTINATION ${DLL_DIR})
+ else()
+ list(APPEND DLLS_WITHOUT_MATCHING_PDBS ${DLL})
+ endif()
+ endforeach()
+
+ list(LENGTH DLLS_WITHOUT_MATCHING_PDBS UNMATCHED_DLLS_LENGTH)
+ if(UNMATCHED_DLLS_LENGTH GREATER 0)
+ merge_filelist(MSG DLLS_WITHOUT_MATCHING_PDBS)
+ message(STATUS "Warning: Could not find a matching pdb file for:\n${MSG}")
+ endif()
+
+endfunction() \ No newline at end of file
diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake
new file mode 100644
index 000000000..7c36f5d97
--- /dev/null
+++ b/scripts/cmake/vcpkg_download_distfile.cmake
@@ -0,0 +1,20 @@
+# Usage: vcpkg_download_distfile(<VAR> URL <http://...> FILENAME <output.zip> MD5 <5981de...>)
+function(vcpkg_download_distfile VAR)
+ set(oneValueArgs URL FILENAME MD5)
+ cmake_parse_arguments(vcpkg_download_distfile "" "${oneValueArgs}" "" ${ARGN})
+
+ if(EXISTS ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME})
+ message(STATUS "Using cached ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}")
+ file(MD5 ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} FILE_HASH)
+ if(NOT FILE_HASH MATCHES ${vcpkg_download_distfile_MD5})
+ message(FATAL_ERROR
+ "File does not have expected hash: ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}\n"
+ " ${FILE_HASH} <> ${vcpkg_download_distfile_MD5}\n"
+ "Please delete the file and try again if this file should be downloaded again.")
+ endif()
+ else()
+ message(STATUS "Downloading ${vcpkg_download_distfile_URL}")
+ file(DOWNLOAD ${vcpkg_download_distfile_URL} ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} EXPECTED_HASH MD5=${vcpkg_download_distfile_MD5})
+ endif()
+ set(${VAR} ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} PARENT_SCOPE)
+endfunction()
diff --git a/scripts/cmake/vcpkg_execute_required_process.cmake b/scripts/cmake/vcpkg_execute_required_process.cmake
new file mode 100644
index 000000000..bd6e56f7b
--- /dev/null
+++ b/scripts/cmake/vcpkg_execute_required_process.cmake
@@ -0,0 +1,21 @@
+# Usage: vcpkg_execute_required_process(COMMAND <cmd> [<args>...] WORKING_DIRECTORY </path/to/dir> LOGNAME <my_log_name>)
+function(vcpkg_execute_required_process)
+ cmake_parse_arguments(vcpkg_execute_required_process "" "WORKING_DIRECTORY;LOGNAME" "COMMAND" ${ARGN})
+ #debug_message("vcpkg_execute_required_process(${vcpkg_execute_required_process_COMMAND})")
+ execute_process(
+ COMMAND ${vcpkg_execute_required_process_COMMAND}
+ OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-out.log
+ ERROR_FILE ${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-err.log
+ RESULT_VARIABLE error_code
+ WORKING_DIRECTORY ${vcpkg_execute_required_process_WORKING_DIRECTORY})
+ #debug_message("error_code=${error_code}")
+ file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}" NATIVE_BUILDTREES_DIR)
+ if(error_code)
+ message(FATAL_ERROR
+ "Command failed: ${vcpkg_execute_required_process_COMMAND}\n"
+ "Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n"
+ "See logs for more information:\n"
+ " ${NATIVE_BUILDTREES_DIR}\\${vcpkg_execute_required_process_LOGNAME}-out.log\n"
+ " ${NATIVE_BUILDTREES_DIR}\\${vcpkg_execute_required_process_LOGNAME}-err.log\n")
+ endif()
+endfunction()
diff --git a/scripts/cmake/vcpkg_extract_source_archive.cmake b/scripts/cmake/vcpkg_extract_source_archive.cmake
new file mode 100644
index 000000000..d970bb8b2
--- /dev/null
+++ b/scripts/cmake/vcpkg_extract_source_archive.cmake
@@ -0,0 +1,14 @@
+include(vcpkg_execute_required_process)
+
+function(vcpkg_extract_source_archive ARCHIVE)
+ if(NOT EXISTS ${CURRENT_BUILDTREES_DIR}/src)
+ message(STATUS "Extracting source ${ARCHIVE}")
+ file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src)
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} -E tar xjf ${ARCHIVE}
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src
+ LOGNAME extract
+ )
+ endif()
+ message(STATUS "Extracting done")
+endfunction()
diff --git a/scripts/cmake/vcpkg_find_acquire_program.cmake b/scripts/cmake/vcpkg_find_acquire_program.cmake
new file mode 100644
index 000000000..ce2cdaa26
--- /dev/null
+++ b/scripts/cmake/vcpkg_find_acquire_program.cmake
@@ -0,0 +1,51 @@
+function(vcpkg_find_acquire_program VAR)
+ if(${VAR} AND NOT ${VAR} MATCHES "-NOTFOUND")
+ return()
+ endif()
+
+ unset(NOEXTRACT)
+
+ if(VAR MATCHES "PERL")
+ set(PROGNAME perl)
+ set(PATHS ${DOWNLOADS}/tools/perl/perl/bin)
+ set(URL "http://strawberryperl.com/download/5.20.2.1/strawberry-perl-5.20.2.1-64bit-portable.zip")
+ set(ARCHIVE "strawberry-perl-5.20.2.1-64bit-portable.zip")
+ set(HASH 5fca4b3cfa7c9cc95e0c4fd8652eba80)
+ elseif(VAR MATCHES "NASM")
+ set(PROGNAME nasm)
+ set(PATHS ${DOWNLOADS}/tools/nasm/nasm-2.11.08)
+ set(URL "http://www.nasm.us/pub/nasm/releasebuilds/2.11.08/win32/nasm-2.11.08-win32.zip")
+ set(ARCHIVE "nasm-2.11.08-win32.zip")
+ set(HASH 46a31e22be69637f7a9ccba12874133f)
+ elseif(VAR MATCHES "YASM")
+ set(PROGNAME yasm)
+ set(PATHS ${DOWNLOADS}/tools/yasm)
+ set(URL "http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win32.exe")
+ set(ARCHIVE "yasm.exe")
+ set(NOEXTRACT ON)
+ set(HASH 51e967dceddd1f84e67bff255df977b3)
+ else()
+ message(FATAL "unknown tool ${VAR} -- unable to acquire.")
+ endif()
+
+ find_program(${VAR} ${PROGNAME} PATHS ${PATHS})
+ if(${VAR} MATCHES "-NOTFOUND")
+ file(DOWNLOAD ${URL} ${DOWNLOADS}/${ARCHIVE}
+ EXPECTED_MD5 ${HASH}
+ SHOW_PROGRESS
+ )
+ file(MAKE_DIRECTORY ${DOWNLOADS}/tools/${PROGNAME})
+ if(DEFINED NOEXTRACT)
+ file(COPY ${DOWNLOADS}/${ARCHIVE} DESTINATION ${DOWNLOADS}/tools/${PROGNAME})
+ else()
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E tar xzf ${DOWNLOADS}/${ARCHIVE}
+ WORKING_DIRECTORY ${DOWNLOADS}/tools/${PROGNAME}
+ )
+ endif()
+
+ find_program(${VAR} ${PROGNAME} PATHS ${PATHS})
+ endif()
+
+ set(${VAR} ${${VAR}} PARENT_SCOPE)
+endfunction()
diff --git a/scripts/cmake/vcpkg_install_cmake.cmake b/scripts/cmake/vcpkg_install_cmake.cmake
new file mode 100644
index 000000000..14f1bc94d
--- /dev/null
+++ b/scripts/cmake/vcpkg_install_cmake.cmake
@@ -0,0 +1,17 @@
+function(vcpkg_install_cmake)
+ message(STATUS "Package ${TARGET_TRIPLET}-rel")
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} --build . --config Release --target install
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel
+ LOGNAME package-${TARGET_TRIPLET}-rel
+ )
+ message(STATUS "Package ${TARGET_TRIPLET}-rel done")
+
+ message(STATUS "Package ${TARGET_TRIPLET}-dbg")
+ vcpkg_execute_required_process(
+ COMMAND ${CMAKE_COMMAND} --build . --config Debug --target install
+ WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg
+ LOGNAME package-${TARGET_TRIPLET}-dbg
+ )
+ message(STATUS "Package ${TARGET_TRIPLET}-dbg done")
+endfunction()
diff --git a/scripts/doVcpkgRelease.ps1 b/scripts/doVcpkgRelease.ps1
new file mode 100644
index 000000000..935eea031
--- /dev/null
+++ b/scripts/doVcpkgRelease.ps1
@@ -0,0 +1,84 @@
+[CmdletBinding()]
+param(
+
+)
+
+$version = git show HEAD:toolsrc/VERSION.txt
+#Remove the quotes from the string
+$version = $version.Substring(1, $version.length - 2)
+$versionRegex = '^\d+\.\d+\.\d+$'
+if (!($version -match $versionRegex))
+{
+ throw [System.ArgumentException] ("Expected version in the form d.d.d but was " + $version)
+}
+
+Write-Verbose("New version is " + $version)
+$gitTagString = "v$version"
+
+# Intentionally doesn't have ^ (=starts with) to match remote tags as well
+$matchingTags = git tag | Where-Object {$_ -match "$gitTagString$"}
+if ($matchingTags.Length -gt 0)
+{
+ throw [System.ArgumentException] ("Git tag matches existing tags: " + $matchingTags)
+}
+
+$gitHash = git rev-parse HEAD
+Write-Verbose("Git hash is " + $gitHash)
+
+$vcpkgPath = (get-item $PSScriptRoot).parent.FullName
+$gitStartOfHash = $gitHash.substring(0,6)
+$versionWithStartOfHash = "$version-$gitStartOfHash"
+$buildPath = "$vcpkgPath\build-$versionWithStartOfHash"
+$releasePath = "$vcpkgPath\release-$versionWithStartOfHash"
+Write-Verbose("Build Path " + $buildPath)
+Write-Verbose("Release Path " + $releasePath)
+
+# 0 is metrics disabled, 1 is metrics enabled
+for ($disableMetrics = 0; $disableMetrics -le 1; $disableMetrics++)
+{
+
+ if (!(Test-Path $buildPath))
+ {
+ New-Item -ItemType directory -Path $buildPath -force | Out-Null
+ }
+
+ if (!(Test-Path $releasePath))
+ {
+ New-Item -ItemType directory -Path $releasePath -force | Out-Null
+ }
+
+ # Partial checkout for building vcpkg
+ $dotGitDir = "$vcpkgPath\.git"
+ $workTreeForBuildOnly = "$buildPath"
+ $checkoutThisDirForBuildOnly1 = ".\scripts" # Must be relative to the root of the repository
+ $checkoutThisDirForBuildOnly2 = ".\toolsrc" # Must be relative to the root of the repository
+ Write-Verbose("Creating partial temporary checkout: $buildPath")
+ git --git-dir="$dotGitDir" --work-tree="$workTreeForBuildOnly" checkout $gitHash -f -q -- $checkoutThisDirForBuildOnly1
+ git --git-dir="$dotGitDir" --work-tree="$workTreeForBuildOnly" checkout $gitHash -f -q -- $checkoutThisDirForBuildOnly2
+
+ & "$buildPath\scripts\bootstrap.ps1" -disableMetrics $disableMetrics
+
+ # Full checkout which will be a zip along with the executables from the previous step
+ $workTree = "$releasePath"
+ $checkoutThisDir = ".\" # Must be relative to the root of the repository
+ Write-Verbose("Creating temporary checkout: $releasePath")
+ git --git-dir=$dotGitDir --work-tree=$workTree checkout $gitHash -f -q -- $checkoutThisDir
+
+ Copy-Item $buildPath\vcpkg.exe $releasePath\vcpkg.exe | Out-Null
+ Copy-Item $buildPath\scripts\vcpkgmetricsuploader.exe $releasePath\scripts\vcpkgmetricsuploader.exe | Out-Null
+
+ Write-Verbose("Archiving")
+ $outputArchive = "$vcpkgPath\vcpkg-$versionWithStartOfHash.zip"
+ if ($disableMetrics -ne 0)
+ {
+ $outputArchive = "$vcpkgPath\vcpkg-$versionWithStartOfHash-external.zip"
+ }
+ Compress-Archive -Path "$releasePath\*" -CompressionLevel Optimal -DestinationPath $outputArchive -Force | Out-Null
+
+ Write-Verbose("Removing temporary checkouts: $releasePath")
+ Remove-Item -recurse $buildPath | Out-Null
+ Remove-Item -recurse $releasePath | Out-Null
+
+ Write-Verbose("Redistributable archive is: $outputArchive")
+}
+git tag $gitTagString \ No newline at end of file
diff --git a/scripts/fetchDependency.ps1 b/scripts/fetchDependency.ps1
new file mode 100644
index 000000000..5873fd727
--- /dev/null
+++ b/scripts/fetchDependency.ps1
@@ -0,0 +1,212 @@
+[CmdletBinding()]
+param(
+ [string]$Dependency
+)
+
+Import-Module BitsTransfer
+
+$scriptsdir = split-path -parent $MyInvocation.MyCommand.Definition
+$vcpkgroot = Split-path $scriptsdir -Parent
+$downloadsdir = "$vcpkgroot\downloads"
+
+function SelectProgram([Parameter(Mandatory=$true)][string]$Dependency)
+{
+ function hasGreaterOrEqualVersion([Parameter(Mandatory=$true)]$requiredVersion, [Parameter(Mandatory=$true)]$availableVersion)
+ {
+ if ($availableVersion[0] -gt $requiredVersion[0]) {return $true}
+ if ($availableVersion[0] -lt $requiredVersion[0]) {return $false}
+
+ if ($availableVersion[1] -gt $requiredVersion[1]) {return $true}
+ if ($availableVersion[1] -lt $requiredVersion[1]) {return $false}
+
+ return ($availableVersion[2] -ge $requiredVersion[2])
+ }
+
+ function promptForDownload([string]$title, [string]$message, [string]$yesDescription, [string]$noDescription)
+ {
+ if ((Test-Path "$downloadsdir\AlwaysAllowEverything") -Or (Test-Path "$downloadsdir\AlwaysAllowDownloads"))
+ {
+ return $true
+ }
+
+ $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", $yesDescription
+ $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", $noDescription
+ $AlwaysAllowDownloads = New-Object System.Management.Automation.Host.ChoiceDescription "&Always Allow Downloads", ($yesDescription + "(Future download prompts will not be displayed)")
+
+ $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no, $AlwaysAllowDownloads)
+ $result = $host.ui.PromptForChoice($title, $message, $options, 0)
+
+ switch ($result)
+ {
+ 0 {return $true}
+ 1 {return $false}
+ 2 {
+ New-Item "$downloadsdir\AlwaysAllowDownloads" -type file -force | Out-Null
+ return $true
+ }
+ }
+
+ throw "Unexpected result"
+ }
+
+
+ function performDownload( [Parameter(Mandatory=$true)][string]$Dependency,
+ [Parameter(Mandatory=$true)][string]$url,
+ [Parameter(Mandatory=$true)][string]$downloaddir,
+ [Parameter(Mandatory=$true)][string]$downloadPath,
+ [Parameter(Mandatory=$true)][string]$downloadVersion,
+ [Parameter(Mandatory=$true)][string]$requiredVersion)
+ {
+ if (Test-Path $downloadPath)
+ {
+ return
+ }
+
+ $title = "Download " + $Dependency
+ $message = ("No suitable version of " + $Dependency + " was found (requires $requiredVersion or higher). Download portable version?")
+ $yesDescription = "Downloads " + $Dependency + " v" + $downloadVersion +" app-locally."
+ $noDescription = "Does not download " + $Dependency + "."
+
+ $userAllowedDownload = promptForDownload $title $message $yesDescription $noDescription
+ if (!$userAllowedDownload)
+ {
+ throw [System.IO.FileNotFoundException] ("Could not detect suitable version of " + $Dependency + " and download not allowed")
+ }
+
+ if (!(Test-Path $downloaddir))
+ {
+ New-Item -ItemType directory -Path $downloaddir | Out-Null
+ }
+
+ if ($Dependency -ne "git") # git fails with BITS
+ {
+ Start-BitsTransfer -Source $url -Destination $downloadPath -ErrorAction SilentlyContinue
+ }
+ else
+ {
+ if (!(Test-Path $downloadPath))
+ {
+ Write-Host("Downloading $Dependency...")
+ (New-Object System.Net.WebClient).DownloadFile($url, $downloadPath)
+ }
+ }
+ }
+
+ # Enums (without resorting to C#) are only available on powershell 5+.
+ $ExtractionType_NO_EXTRACTION_REQUIRED = 0
+ $ExtractionType_ZIP = 1
+ $ExtractionType_SELF_EXTRACTING_7Z = 2
+
+
+ # Using this to wait for the execution to finish
+ function Invoke-Command()
+ {
+ param ( [string]$program = $(throw "Please specify a program" ),
+ [string]$argumentString = "",
+ [switch]$waitForExit )
+
+ $psi = new-object "Diagnostics.ProcessStartInfo"
+ $psi.FileName = $program
+ $psi.Arguments = $argumentString
+ $proc = [Diagnostics.Process]::Start($psi)
+ if ( $waitForExit )
+ {
+ $proc.WaitForExit();
+ }
+ }
+
+ function Expand-ZIPFile($file, $destination)
+ {
+ Write-Host($file)
+ Write-Host($destination)
+ $shell = new-object -com shell.application
+ $zip = $shell.NameSpace($file)
+ foreach($item in $zip.items())
+ {
+ # Piping to Out-Null is used to block until finished
+ $shell.Namespace($destination).copyhere($item) | Out-Null
+ }
+ }
+
+ if($Dependency -eq "cmake")
+ {
+ $requiredVersion = "3.5.0"
+ $downloadVersion = "3.5.2"
+ $url = "https://cmake.org/files/v3.5/cmake-3.5.2-win32-x86.zip"
+ $downloadName = "cmake-3.5.2-win32-x86.zip"
+ $expectedDownloadedFileHash = "671073aee66b3480a564d0736792e40570a11e861bb34819bb7ae7858bbdfb80"
+ $executableFromDownload = "$downloadsdir\cmake-3.5.2-win32-x86\bin\cmake.exe"
+ $extractionType = $ExtractionType_ZIP
+ }
+ elseif($Dependency -eq "nuget")
+ {
+ $requiredVersion = "1.0.0"
+ $downloadVersion = "3.4.3"
+ $url = "https://dist.nuget.org/win-x86-commandline/v3.4.3/nuget.exe"
+ $downloadName = "nuget.exe"
+ $expectedDownloadedFileHash = "3B1EA72943968D7AF6BACDB4F2F3A048A25AFD14564EF1D8B1C041FDB09EBB0A"
+ $executableFromDownload = "$downloadsdir\nuget.exe"
+ $extractionType = $ExtractionType_NO_EXTRACTION_REQUIRED
+ }
+ elseif($Dependency -eq "git")
+ {
+ $requiredVersion = "2.0.0"
+ $downloadVersion = "2.8.3"
+ $url = "https://github.com/git-for-windows/git/releases/download/v2.8.3.windows.1/PortableGit-2.8.3-32-bit.7z.exe" # We choose the 32-bit version
+ $downloadName = "PortableGit-2.8.3-32-bit.7z.exe"
+ $expectedDownloadedFileHash = "DE52D070219E9C4EC1DB179F2ADBF4B760686C3180608F0382A1F8C7031E72AD"
+ # There is another copy of git.exe in PortableGit\bin. However, an installed version of git add the cmd dir to the PATH.
+ # Therefore, choosing the cmd dir here as well.
+ $executableFromDownload = "$downloadsdir\PortableGit\cmd\git.exe"
+ $extractionType = $ExtractionType_SELF_EXTRACTING_7Z
+ }
+ else
+ {
+ throw "Unknown program requested"
+ }
+
+ $downloadPath = "$downloadsdir\$downloadName"
+ performDownload $Dependency $url $downloadsdir $downloadPath $downloadVersion $requiredVersion
+
+ #calculating the hash
+ $hashAlgorithm = [Security.Cryptography.HashAlgorithm]::Create("SHA256")
+ $fileAsByteArray = [io.File]::ReadAllBytes($downloadPath)
+ $hashByteArray = $hashAlgorithm.ComputeHash($fileAsByteArray)
+ $downloadedFileHash = -Join ($hashByteArray | ForEach {"{0:x2}" -f $_})
+
+ if ($expectedDownloadedFileHash -ne $downloadedFileHash)
+ {
+ throw [System.IO.FileNotFoundException] ("Mismatching hash of the downloaded " + $Dependency)
+ }
+
+ if ($extractionType -eq $ExtractionType_NO_EXTRACTION_REQUIRED)
+ {
+ # do nothing
+ }
+ elseif($extractionType -eq $ExtractionType_ZIP)
+ {
+ if (-not (Test-Path $executableFromDownload)) # consider renaming the extraction folder to make sure the extraction finished
+ {
+ # Expand-Archive $downloadPath -dest "$downloadsdir" -Force # Requires powershell 5+
+ Expand-ZIPFile -File $downloadPath -Destination $downloadsdir
+ }
+ }
+ elseif($extractionType -eq $ExtractionType_SELF_EXTRACTING_7Z)
+ {
+ if (-not (Test-Path $executableFromDownload))
+ {
+ Invoke-Command $downloadPath "-y" -waitForExit:$true
+ }
+ }
+ else
+ {
+ throw "Invalid extraction type"
+ }
+
+ if (-not (Test-Path $executableFromDownload))
+ {
+ throw [System.IO.FileNotFoundException] ("Could not detect or download " + $Dependency)
+ }
+}
+
+SelectProgram $Dependency \ No newline at end of file
diff --git a/scripts/ports.cmake b/scripts/ports.cmake
new file mode 100644
index 000000000..51afc8d61
--- /dev/null
+++ b/scripts/ports.cmake
@@ -0,0 +1,85 @@
+cmake_minimum_required(VERSION 3.5)
+get_filename_component(VCPKG_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
+
+string(REGEX REPLACE "([^-]*)-([^-]*)" "\\1" TRIPLET_SYSTEM_ARCH ${TARGET_TRIPLET})
+string(REGEX REPLACE "([^-]*)-([^-]*)" "\\2" TRIPLET_SYSTEM_NAME ${TARGET_TRIPLET})
+
+if(NOT EXISTS ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake)
+ message(FATAL_ERROR "Unsupported target triplet. Toolchain file does not exist: ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake")
+endif()
+
+set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake)
+list(APPEND CMAKE_MODULE_PATH ${VCPKG_ROOT_DIR}/scripts/cmake)
+set(CURRENT_INSTALLED_DIR ${VCPKG_ROOT_DIR}/installed/${TARGET_TRIPLET} CACHE PATH "Location to install final packages")
+set(DOWNLOADS ${VCPKG_ROOT_DIR}/downloads CACHE PATH "Location to download sources and tools")
+set(PACKAGES_DIR ${VCPKG_ROOT_DIR}/packages CACHE PATH "Location to store package images")
+set(BUILDTREES_DIR ${VCPKG_ROOT_DIR}/buildtrees CACHE PATH "Location to perform actual extract+config+build")
+
+if(PORT)
+ set(CURRENT_BUILDTREES_DIR ${BUILDTREES_DIR}/${PORT})
+ set(CURRENT_PACKAGES_DIR ${PACKAGES_DIR}/${PORT}_${TARGET_TRIPLET})
+endif()
+
+macro(debug_message)
+ if(DEFINED PORT_DEBUG AND PORT_DEBUG)
+ message(STATUS "[DEBUG] ${ARGN}")
+ endif()
+endmacro()
+
+if(CMD MATCHES "^SCAFFOLD$")
+ if(EXISTS ports/${PORT}/portfile.cmake)
+ message(FATAL_ERROR "Portfile already exists: '${VCPKG_ROOT_DIR}/ports/${PORT}/portfile.cmake'")
+ endif()
+ if(NOT FILENAME)
+ get_filename_component(FILENAME "${URL}" NAME)
+ endif()
+ string(REGEX REPLACE "(\\.(zip|gz|tar|tgz|bz2))+\$" "" ROOT_NAME ${FILENAME})
+ if(EXISTS ${DOWNLOADS}/${FILENAME})
+ message(STATUS "Using pre-downloaded: ${DOWNLOADS}/${FILENAME}")
+ message(STATUS "If this is not desired, delete the file and ${VCPKG_ROOT_DIR}/ports/${PORT}/portfile.cmake")
+ else()
+ include(vcpkg_download_distfile)
+ file(DOWNLOAD ${URL} ${DOWNLOADS}/${FILENAME} STATUS error_code)
+ if(NOT error_code MATCHES "0;")
+ message(FATAL_ERROR "Error downloading file: ${error_code}")
+ endif()
+ endif()
+ file(MD5 ${DOWNLOADS}/${FILENAME} MD5)
+
+ file(MAKE_DIRECTORY ports/${PORT})
+ configure_file(scripts/templates/portfile.in.cmake ports/${PORT}/portfile.cmake @ONLY)
+
+ message(STATUS "Generated portfile: ${VCPKG_ROOT_DIR}/ports/${PORT}/portfile.cmake")
+elseif(CMD MATCHES "^BUILD$")
+ if(NOT DEFINED CURRENT_PORT_DIR)
+ message(FATAL_ERROR "CURRENT_PORT_DIR was not defined")
+ endif()
+ set(TO_CMAKE_PATH "${CURRENT_PORT_DIR}" CURRENT_PORT_DIR)
+ if(NOT EXISTS ${CURRENT_PORT_DIR})
+ message(FATAL_ERROR "Cannot find port: ${PORT}\n Directory does not exist: ${CURRENT_PORT_DIR}")
+ endif()
+ if(NOT EXISTS ${CURRENT_PORT_DIR}/portfile.cmake)
+ message(FATAL_ERROR "Port is missing portfile: ${CURRENT_PORT_DIR}/portfile.cmake")
+ endif()
+ if(NOT EXISTS ${CURRENT_PORT_DIR}/CONTROL)
+ message(FATAL_ERROR "Port is missing control file: ${CURRENT_PORT_DIR}/CONTROL")
+ endif()
+
+ message(STATUS "CURRENT_INSTALLED_DIR=${CURRENT_INSTALLED_DIR}")
+ message(STATUS "DOWNLOADS=${DOWNLOADS}")
+
+ message(STATUS "CURRENT_PACKAGES_DIR=${CURRENT_PACKAGES_DIR}")
+ message(STATUS "CURRENT_BUILDTREES_DIR=${CURRENT_BUILDTREES_DIR}")
+ message(STATUS "CURRENT_PORT_DIR=${CURRENT_PORT_DIR}")
+
+ unset(PACKAGES_DIR)
+ unset(BUILDTREES_DIR)
+
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR})
+ if(EXISTS ${CURRENT_PACKAGES_DIR})
+ message(FATAL_ERROR "Unable to remove directory: ${CURRENT_PACKAGES_DIR}\n Files are likely in use.")
+ endif()
+ file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR} ${CURRENT_PACKAGES_DIR})
+
+ include(${CURRENT_PORT_DIR}/portfile.cmake)
+endif()
diff --git a/scripts/templates/portfile.in.cmake b/scripts/templates/portfile.in.cmake
new file mode 100644
index 000000000..b29e2b682
--- /dev/null
+++ b/scripts/templates/portfile.in.cmake
@@ -0,0 +1,21 @@
+include(vcpkg_common_functions)
+vcpkg_download_distfile(ARCHIVE
+ URL "@URL@"
+ FILENAME "@FILENAME@"
+ MD5 @MD5@
+)
+vcpkg_extract_source_archive(${ARCHIVE})
+
+vcpkg_configure_cmake(
+ SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/@ROOT_NAME@
+ # OPTIONS -DUSE_THIS_IN_ALL_BUILDS=1 -DUSE_THIS_TOO=2
+ # OPTIONS_RELEASE -DOPTIMIZE=1
+ # OPTIONS_DEBUG -DDEBUGGABLE=1
+)
+
+vcpkg_build_cmake()
+vcpkg_install_cmake()
+
+# Handle copyright
+#file(COPY ${CURRENT_BUILDTREES_DIR}/src/@ROOT_NAME@/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/@PORT@)
+#file(RENAME ${CURRENT_PACKAGES_DIR}/share/@PORT@/LICENSE ${CURRENT_PACKAGES_DIR}/share/@PORT@/copyright) \ No newline at end of file