Configurations_windows.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. get_property(O3DE_SCRIPT_ONLY GLOBAL PROPERTY "O3DE_SCRIPT_ONLY")
  45. if(NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT O3DE_SCRIPT_ONLY)
  46. if(DEFINED ENV{CMAKE_WINDOWS_KITS_10_DIR})
  47. set(win10_root $ENV{CMAKE_WINDOWS_KITS_10_DIR})
  48. file(TO_CMAKE_PATH "${win10_root}" win10_root)
  49. list(APPEND win10_roots "${win10_root}")
  50. endif()
  51. # This logic is taken from cmGlobalVisualStudio14Generator.cxx, which
  52. # itself is taken from the vcvarsqueryregistry.bat file from VS2015.
  53. # Try HKLM and then HKCU.
  54. list(APPEND win10_roots "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]")
  55. list(APPEND win10_roots "[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]")
  56. foreach(win10_root IN LISTS win10_roots)
  57. get_filename_component(_win10_root "${win10_root}" ABSOLUTE CACHE)
  58. # Grab the paths of the different SDKs that are installed
  59. file(GLOB candidates "${_win10_root}/Include/*")
  60. foreach(sdk_dir IN LISTS candidates)
  61. # Skip SDKs that do not contain <um/windows.h> because that
  62. # indicates that only the UCRT MSIs were installed for them.
  63. if(EXISTS "${sdk_dir}/um/Windows.h")
  64. list(APPEND sdks "${sdk_dir}")
  65. endif()
  66. endforeach()
  67. if(sdks)
  68. break()
  69. endif()
  70. endforeach()
  71. if(NOT sdks)
  72. return()
  73. endif()
  74. list(GET sdks 0 max_sdk)
  75. foreach(sdk IN LISTS sdks)
  76. # Only use the filename, which will be the SDK version.
  77. get_filename_component(version "${sdk}" NAME)
  78. # Look for a SDK exactly matching the requested target version
  79. if(version VERSION_EQUAL CMAKE_SYSTEM_VERSION)
  80. set(max_sdk "${version}")
  81. set(sdk_root "${sdk}")
  82. break()
  83. elseif(version VERSION_GREATER max_sdk)
  84. # Use the latest Windows 10 SDK since the exact version is not
  85. # available
  86. set(max_sdk "${version}")
  87. set(sdk_root "${sdk}")
  88. endif()
  89. endforeach()
  90. if(NOT version VERSION_EQUAL CMAKE_SYSTEM_VERSION)
  91. message(STATUS "Using Windows SDK version ${version} to target Windows ${CMAKE_SYSTEM_VERSION}")
  92. endif()
  93. ly_set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "${version}")
  94. endif()
  95. if(NOT O3DE_SCRIPT_ONLY AND NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION MATCHES "10.0")
  96. message(FATAL_ERROR "Unsupported version of Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}, specify \"-DCMAKE_SYSTEM_VERSION=10.0\" when invoking cmake")
  97. endif()