RuntimeUtilities.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #[[
  2. Utility functions used to set the output of runtime executables and dependencies.
  3. ]]
  4. #[[
  5. Change the output directories of binaries and libraries of all targets declared in this scope. This is particularly
  6. helpful on Windows when building the project as a shared library, so that all DLLs are located together with any
  7. built executables. More generally, placing these files in the top-level binary directory makes them easier to
  8. locate. The set() call is guarded against pre-definitions in order to respect consumer choice.
  9. ]]
  10. function(setup_binary_output_directories)
  11. if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  12. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" PARENT_SCOPE)
  13. endif()
  14. if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  15. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" PARENT_SCOPE)
  16. endif()
  17. if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  18. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" PARENT_SCOPE)
  19. endif()
  20. endfunction()
  21. # RMLUI_CMAKE_MINIMUM_VERSION_RAISE_NOTICE:
  22. # From CMake 3.21 there is no need for the following function, as we can set the RUNTIME_DEPENDENCY_SET on
  23. # install(TARGETS) directly.
  24. #[[
  25. Output variable to conditionally set up runtime dependency arguments when installing targets.
  26. This feature is only available from CMake 3.21, on older version this feature will be disabled.
  27. Output variable:
  28. - RMLUI_RUNTIME_DEPENDENCY_SET_ARG: Argument to use for the install(TARGETS) command.
  29. ]]
  30. function(setup_runtime_dependency_set_arg)
  31. set(RMLUI_RUNTIME_DEPENDENCY_SET_ARG "" PARENT_SCOPE)
  32. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
  33. set(RMLUI_RUNTIME_DEPENDENCY_SET_ARG RUNTIME_DEPENDENCY_SET rmlui_runtime_dependencies PARENT_SCOPE)
  34. endif()
  35. endfunction()
  36. #[[
  37. Install runtime dependencies on supported platforms, when enabled by the user.
  38. ]]
  39. function(install_runtime_dependencies)
  40. if(WIN32 AND RMLUI_RUNTIME_DEPENDENCY_SET_ARG)
  41. option(RMLUI_INSTALL_RUNTIME_DEPENDENCIES "Include runtime dependencies when installing RmlUi." ON)
  42. mark_as_advanced(RMLUI_INSTALL_RUNTIME_DEPENDENCIES)
  43. if(RMLUI_INSTALL_RUNTIME_DEPENDENCIES)
  44. install(RUNTIME_DEPENDENCY_SET rmlui_runtime_dependencies
  45. PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
  46. POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
  47. )
  48. endif()
  49. endif()
  50. endfunction()