Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opengl] build failure - Windows SDK path hardcoded #8288

Closed
AlessandroMenti opened this issue Sep 22, 2019 · 9 comments · Fixed by #12232
Closed

[opengl] build failure - Windows SDK path hardcoded #8288

AlessandroMenti opened this issue Sep 22, 2019 · 9 comments · Fixed by #12232
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@AlessandroMenti
Copy link

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 AlessandroMenti added the category:port-bug The issue is with a library, which is something the port should already support label Sep 22, 2019
@PhoebeHui
Copy link
Contributor

@AlessandroMenti, thanks for reporting this issue, could you summit a PR for this?

@PhoebeHui PhoebeHui self-assigned this Sep 23, 2019
@Neumann-A
Copy link
Contributor

Do you also know how to solve it in qmake's syntax/*.prl files (#7675)

@MVoz
Copy link
Contributor

MVoz commented Sep 24, 2019

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\

@MVoz
Copy link
Contributor

MVoz commented Sep 24, 2019

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) 

?

))

@MVoz
Copy link
Contributor

MVoz commented Sep 24, 2019

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")

@AlessandroMenti
Copy link
Author

@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.

@MVoz
Copy link
Contributor

MVoz commented Sep 26, 2019

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\

@ras0219
Copy link
Contributor

ras0219 commented May 15, 2020

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.

@Neumann-A
Copy link
Contributor

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

BillyONeal added a commit to BillyONeal/vcpkg that referenced this issue Jul 2, 2020
…ding Windows SDK paths.

Also delete vcpkg_get_program_files_32_bit because it was used in only one place.

Resolves microsoft#8288
Obsoletes microsoft#11421, microsoft#11261, microsoft#8329
ras0219-msft pushed a commit that referenced this issue Jul 6, 2020
…ding Windows SDK paths. (#12232)

Also delete vcpkg_get_program_files_32_bit because it was used in only one place.

Resolves #8288
Obsoletes #11421, #11261, #8329
strega-nil pushed a commit to strega-nil/vcpkg that referenced this issue May 5, 2021
…ding Windows SDK paths. (microsoft#12232)

Also delete vcpkg_get_program_files_32_bit because it was used in only one place.

Resolves microsoft#8288
Obsoletes microsoft#11421, microsoft#11261, microsoft#8329
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
7 participants