Configurations_windows.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  9. ly_set(CMAKE_RC_FLAGS /nologo)
  10. include(cmake/Platform/Common/MSVC/Configurations_msvc.cmake)
  11. ly_append_configurations_options(
  12. DEFINES
  13. _WIN32
  14. WIN32
  15. _WIN64
  16. WIN64
  17. NOMINMAX
  18. LINK
  19. /MACHINE:X64
  20. )
  21. elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  22. if(MSVC)
  23. include(cmake/Platform/Common/MSVC/Configurations_clang.cmake)
  24. else()
  25. include(cmake/Platform/Common/Clang/Configurations_clang.cmake)
  26. endif()
  27. ly_append_configurations_options(
  28. DEFINES
  29. _ENABLE_EXTENDED_ALIGNED_STORAGE #Enables support for extended alignment for the MSVC std::aligned_storage class
  30. _WIN32
  31. WIN32
  32. _WIN64
  33. WIN64
  34. NOMINMAX
  35. COMPILATION
  36. -msse3
  37. -mf16c
  38. -Wno-deprecated-declarations
  39. )
  40. ly_set(CMAKE_CXX_EXTENSIONS OFF)
  41. else()
  42. message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} not supported in ${PAL_PLATFORM_NAME}")
  43. endif()
  44. if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  45. if(DEFINED ENV{CMAKE_WINDOWS_KITS_10_DIR})
  46. set(win10_root $ENV{CMAKE_WINDOWS_KITS_10_DIR})
  47. file(TO_CMAKE_PATH "${win10_root}" win10_root)
  48. list(APPEND win10_roots "${win10_root}")
  49. endif()
  50. # This logic is taken from cmGlobalVisualStudio14Generator.cxx, which
  51. # itself is taken from the vcvarsqueryregistry.bat file from VS2015.
  52. # Try HKLM and then HKCU.
  53. list(APPEND win10_roots "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]")
  54. list(APPEND win10_roots "[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]")
  55. foreach(win10_root IN LISTS win10_roots)
  56. get_filename_component(_win10_root "${win10_root}" ABSOLUTE CACHE)
  57. # Grab the paths of the different SDKs that are installed
  58. file(GLOB candidates "${_win10_root}/Include/*")
  59. foreach(sdk_dir IN LISTS candidates)
  60. # Skip SDKs that do not contain <um/windows.h> because that
  61. # indicates that only the UCRT MSIs were installed for them.
  62. if(EXISTS "${sdk_dir}/um/Windows.h")
  63. list(APPEND sdks "${sdk_dir}")
  64. endif()
  65. endforeach()
  66. if(sdks)
  67. break()
  68. endif()
  69. endforeach()
  70. if(NOT sdks)
  71. return()
  72. endif()
  73. list(GET sdks 0 max_sdk)
  74. foreach(sdk IN LISTS sdks)
  75. # Only use the filename, which will be the SDK version.
  76. get_filename_component(version "${sdk}" NAME)
  77. # Look for a SDK exactly matching the requested target version
  78. if(version VERSION_EQUAL CMAKE_SYSTEM_VERSION)
  79. set(max_sdk "${version}")
  80. set(sdk_root "${sdk}")
  81. break()
  82. elseif(version VERSION_GREATER max_sdk)
  83. # Use the latest Windows 10 SDK since the exact version is not
  84. # available
  85. set(max_sdk "${version}")
  86. set(sdk_root "${sdk}")
  87. endif()
  88. endforeach()
  89. if(NOT version VERSION_EQUAL CMAKE_SYSTEM_VERSION)
  90. message(STATUS "Using Windows SDK version ${version} to target Windows ${CMAKE_SYSTEM_VERSION}")
  91. endif()
  92. ly_set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "${version}")
  93. endif()
  94. if(NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION MATCHES "10.0")
  95. message(FATAL_ERROR "Unsupported version of Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}, specify \"-DCMAKE_SYSTEM_VERSION=10.0\" when invoking cmake")
  96. endif()