[opengl] build failure - Windows SDK path hardcoded
Host Environment
- OS: Microsoft Windows 10 1903 (build: 18362.356)
- Compiler: Microsoft Visual Studio 2019
To Reproduce
Steps to reproduce the behavior:
./vcpkg install opengl
Failure logs
Building package opengl[core]:x64-windows...
CMake Error at ports/opengl/portfile.cmake:20 (message):
Cannot find Windows 10.0.17763.0 SDK. File does not exist: C:\Program
Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64\OpenGL32.Lib
Call Stack (most recent call first):
scripts/ports.cmake:91 (include)
Error: Building package opengl:x64-windows failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `.\vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
Package: opengl:x64-windows
Vcpkg version: 2019.09.12-nohash
Additional context The portfiles for OpenGL hardcode the Windows 8 and 10 SDK paths:
vcpkg_get_program_files_32_bit(PROGRAM_FILES_32_BIT)
vcpkg_get_windows_sdk(WINDOWS_SDK)
if (WINDOWS_SDK MATCHES "10.")
set(LIBGLFILEPATH "${PROGRAM_FILES_32_BIT}\\Windows Kits\\10\\Lib\\${WINDOWS_SDK}\\um\\${TRIPLET_SYSTEM_ARCH}\\OpenGL32.Lib")
set(LIBGLUFILEPATH "${PROGRAM_FILES_32_BIT}\\Windows Kits\\10\\Lib\\${WINDOWS_SDK}\\um\\${TRIPLET_SYSTEM_ARCH}\\GlU32.Lib")
set(HEADERSPATH "${PROGRAM_FILES_32_BIT}\\Windows Kits\\10\\Include\\${WINDOWS_SDK}\\um")
elseif(WINDOWS_SDK MATCHES "8.")
set(LIBGLFILEPATH "${PROGRAM_FILES_32_BIT}\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\${TRIPLET_SYSTEM_ARCH}\\OpenGL32.Lib")
set(LIBGLUFILEPATH "${PROGRAM_FILES_32_BIT}\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\${TRIPLET_SYSTEM_ARCH}\\GlU32.Lib")
set(HEADERSPATH "${PROGRAM_FILES_32_BIT}\\Windows Kits\\8.1\\Include\\um")
else()
message(FATAL_ERROR "Portfile not yet configured for Windows SDK with version: ${WINDOWS_SDK}")
endif()
This assumes that the Windows SDK is always installed in the default path, which might not always be the case (on my machine, it was installed into D:\Program Files (x86)\Windows Kits\10, hence the error).
From a quick search, the issue seems to also affect the wincrypt and winsock2 ports.
A possible fix (at least for the Windows 10 SDK) would be to have CMake read the installation path from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots (value name: KitsRoot10) and to use it instead of the hardcoded one - I can draft a PR if needed.
@AlessandroMenti, thanks for reporting this issue, could you summit a PR for this?
Do you also know how to solve it in qmake's syntax/*.prl files (#7675)
cmake
get_filename_component(WINDOWS_KIT_10_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE CACHE)
C:\Program Files (x86)\Windows Kits\10\
get_filename_component(WINDOWS_KIT_81_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot81]" ABSOLUTE CACHE)
or
7.1
get_filename_component(WINDOWS_KIT_71_PATH "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v7.1;InstallationFolder]" ABSOLUTE CACHE)
8.0
get_filename_component(WINDOWS_KIT_80_PATH "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v8.0;InstallationFolder]" ABSOLUTE CACHE)
8.1
get_filename_component(WINDOWS_KIT_81_PATH "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v8.1;InstallationFolder]" ABSOLUTE CACHE)
10.0
get_filename_component(WINDOWS_KIT_10_PATH "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0;InstallationFolder]" ABSOLUTE CACHE)
C:\Program Files (x86)\Windows Kits\10\
to locate system libraries) CMAKE_STANDARD_LIBRARIES
it is enough to include them in the build system, in the CMAKE parameters
list(APPEND CMAKE_STANDARD_LIBRARIES ... ?
or
set(CMAKE_STANDARD_LIBRARIES ${CMAKE_STANDARD_LIBRARIES} OpenGL32.Lib GlU32.Lib) ?
or
SET (CMAKE_STANDARD_LIBRARIES "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib OpenGL32.Lib GlU32.Lib" CACHE STRING "Libraries linked by defalut with all applications.")
MARK_AS_ADVANCED(CMAKE_STANDARD_LIBRARIES)
?
))
https://cmake.org/cmake/help/latest/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.html
set a CMAKE_WINDOWS_KITS_10_DIR environment variable
look for Windows 10 SDKs in a custom location
?
set(CMAKE_SYSTEM_VERSION 10.0.17763)
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 10.0.17763.0)
hmm...
~~CMAKE_SYSTEM_VERSION = CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION~~
set(CMAKE_WINDOWS_KITS_10_DIR "D:/Program Files (x86)/Windows Kits/10")
or
get_filename_component(WINDOWS_KIT_10_PATH "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0;InstallationFolder]" ABSOLUTE CACHE)
set(CMAKE_WINDOWS_KITS_10_DIR ${WINDOWS_KIT_10_PATH})
good example https://github.com/tt4g/winldap-example/blob/master/cmake/FindWldap32.cmake
or https://github.com/Microsoft/DirectXShaderCompiler/blob/master/cmake/modules/FindD3D12.cmake
Find the win10 SDK path. if ("$ENV{WIN10_SDK_PATH}$ENV{WIN10_SDK_VERSION}" STREQUAL "" ) get_filename_component(WIN10_SDK_PATH "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0;InstallationFolder]" ABSOLUTE CACHE) get_filename_component(TEMP_WIN10_SDK_VERSION "[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0;ProductVersion]" ABSOLUTE CACHE) get_filename_component(WIN10_SDK_VERSION ${TEMP_WIN10_SDK_VERSION} NAME) elseif(TRUE) set (WIN10_SDK_PATH $ENV{WIN10_SDK_PATH}) set (WIN10_SDK_VERSION $ENV{WIN10_SDK_VERSION}) endif ("$ENV{WIN10_SDK_PATH}$ENV{WIN10_SDK_VERSION}" STREQUAL "" )
WIN10_SDK_PATH will be something like C:\Program Files (x86)\Windows Kits\10 WIN10_SDK_VERSION will be something like 10.0.14393 or 10.0.14393.0; we need the one that matches the directory name.
if (IS_DIRECTORY "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}.0") set(WIN10_SDK_VERSION "${WIN10_SDK_VERSION}.0") endif (IS_DIRECTORY "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}.0")
@PhoebeHui: of course! @Neumann-A: I'll have to check that issue first. @Voskrese: thanks for the inputs!
I've started working on a PR for this, see #8329 - I'll improve it in the next days.
https://github.com/microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_get_windows_sdk.cmake
# Returns Windows SDK number via out variable "ret"
function(vcpkg_get_windows_sdk ret)
set(WINDOWS_SDK $ENV{WindowsSDKVersion})
string(REPLACE "\\" "" WINDOWS_SDK "${WINDOWS_SDK}")
set(${ret} ${WINDOWS_SDK} PARENT_SCOPE)
endfunction()
$ENV{WindowsSDKVersion}
open C:\Program Files (x86)\Microsoft Visual ...\...\...\Common7\Tools\vsdevcmd\core\winsdk.bat
set WindowsSdkDir=
set WindowsLibPath=
set WindowsSDKVersion=
set WindowsSDKLibVersion=
set WindowsSdkBinPath=
set UCRTVersion=
set UniversalCRTSdkDir=
set WindowsSDKVerBinPath=
version - vcpkg_get_windows_sdk_version(WINDOWS_SDK)
function(vcpkg_get_windows_sdk_version ret)
set(WINDOWS_SDK $ENV{WindowsSDKVersion})
string(REPLACE "\\" "" WINDOWS_SDK "${WINDOWS_SDK}")
set(${ret} ${WINDOWS_SDK} PARENT_SCOPE)
endfunction()
echo %WindowsSDKVersion% 10.0.17763.0\
$ENV{WindowsSDKDir}
dir - vcpkg_get_windows_sdk_dir(WINDOWS_SDK)
function(vcpkg_get_windows_sdk_dir ret)
set(WINDOWS_SDK $ENV{WindowsSDKDir})
string(REPLACE "\\" "" WINDOWS_SDK "${WINDOWS_SDK}")
set(${ret} ${WINDOWS_SDK} PARENT_SCOPE)
endfunction()
echo %WindowsSDKDir% C:\Program Files (x86)\Windows Kits\10\
I think the best approach here would be to run a CMake build that simply performs something like
project(opengl NONE)
find_library(OGL opengl32)
install(FILES ${OGL} DESTINATION lib)
This should correctly find opengl from whichever windows sdk we're using to configure cmake projcets.
This should correctly find opengl from whichever windows sdk we're using to configure cmake projcets.
Probably needs an opengl selector somehow since opengl32 from the windows sdk is not the only possibility if mesa is installed