validate_d3d_compiler.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # This file is part of Desktop App Toolkit,
  2. # a set of libraries for developing nice desktop applications.
  3. #
  4. # For license and copyright information please follow this link:
  5. # https://github.com/desktop-app/legal/blob/master/LEGAL
  6. function(validate_d3d_error text)
  7. if (NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "")
  8. message(FATAL_ERROR ${text})
  9. else()
  10. message(WARNING ${text})
  11. endif()
  12. endfunction()
  13. function(validate_d3d_compiler target_name)
  14. if (build_win64)
  15. set(modules_subdir x64)
  16. else()
  17. set(modules_subdir x86)
  18. endif()
  19. set(modules_hash_loc ${CMAKE_BINARY_DIR}/modules/${modules_subdir})
  20. set(modules_debug_loc ${CMAKE_BINARY_DIR}/Debug/modules/${modules_subdir})
  21. set(modules_release_loc ${CMAKE_BINARY_DIR}/Release/modules/${modules_subdir})
  22. set(key_path ${modules_hash_loc}/d3d/d3dcompiler_47)
  23. set(module_debug_path ${modules_debug_loc}/d3d)
  24. set(module_release_path ${modules_release_loc}/d3d)
  25. set(key "")
  26. if (EXISTS ${key_path})
  27. file(READ ${key_path} key)
  28. endif()
  29. if (NOT "$ENV{WindowsSdkDir}" STREQUAL "")
  30. set(windows_sdk_loc $ENV{WindowsSdkDir} CACHE INTERNAL "Windows SDK Path" FORCE)
  31. endif()
  32. string(LENGTH "${key}" key_length)
  33. if (NOT "${key_length}" STREQUAL "32"
  34. OR NOT EXISTS ${module_debug_path}/d3dcompiler_47.dll
  35. OR NOT EXISTS ${module_release_path}/d3dcompiler_47.dll)
  36. if ("${windows_sdk_loc}" STREQUAL "")
  37. validate_d3d_error("Could not find Windows SDK.")
  38. return()
  39. endif()
  40. set(sdk_compiler ${windows_sdk_loc}/Redist/D3D/${modules_subdir}/d3dcompiler_47.dll)
  41. find_package(Python3 REQUIRED)
  42. execute_process(
  43. COMMAND
  44. ${Python3_EXECUTABLE}
  45. ${cmake_helpers_loc}/validate_d3d_compiler.py
  46. ${sdk_compiler}
  47. OUTPUT_VARIABLE key
  48. ERROR_VARIABLE error
  49. )
  50. if (NOT "${error}" STREQUAL "")
  51. validate_d3d_error(${error})
  52. return()
  53. endif()
  54. file(MAKE_DIRECTORY ${modules_debug_loc}/d3d)
  55. file(COPY ${sdk_compiler} DESTINATION ${module_debug_path})
  56. file(MAKE_DIRECTORY ${modules_release_loc}/d3d)
  57. file(COPY ${sdk_compiler} DESTINATION ${module_release_path})
  58. file(MAKE_DIRECTORY ${modules_hash_loc}/d3d)
  59. file(WRITE ${key_path} ${key})
  60. endif()
  61. target_compile_definitions(${target_name}
  62. PRIVATE
  63. DESKTOP_APP_D3DCOMPILER_HASH=${key}
  64. )
  65. target_link_libraries(${target_name}
  66. PRIVATE
  67. desktop-app::external_openssl
  68. )
  69. endfunction()