CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Project-level configuration.
  2. cmake_minimum_required(VERSION 3.14)
  3. project(rustdesk LANGUAGES CXX)
  4. # The name of the executable created for the application. Change this to change
  5. # the on-disk name of your application.
  6. set(BINARY_NAME "rustdesk")
  7. # Explicitly opt into modern CMake behaviors to avoid warnings with recent
  8. # versions of CMake.
  9. cmake_policy(SET CMP0063 NEW)
  10. # Define build configuration option.
  11. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  12. if(IS_MULTICONFIG)
  13. set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
  14. CACHE STRING "" FORCE)
  15. else()
  16. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  17. set(CMAKE_BUILD_TYPE "Debug" CACHE
  18. STRING "Flutter build mode" FORCE)
  19. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  20. "Debug" "Profile" "Release")
  21. endif()
  22. endif()
  23. # Define settings for the Profile build mode.
  24. set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
  25. set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
  26. set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
  27. set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
  28. # Replace /MD flags to /MT to use static vcruntine
  29. set(CompilerFlags
  30. CMAKE_CXX_FLAGS
  31. CMAKE_CXX_FLAGS_DEBUG
  32. CMAKE_CXX_FLAGS_RELEASE
  33. CMAKE_C_FLAGS
  34. CMAKE_C_FLAGS_DEBUG
  35. CMAKE_C_FLAGS_RELEASE
  36. )
  37. foreach(CompilerFlag ${CompilerFlags})
  38. string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
  39. endforeach()
  40. # Use Unicode for all projects.
  41. add_definitions(-DUNICODE -D_UNICODE)
  42. # Compilation settings that should be applied to most targets.
  43. #
  44. # Be cautious about adding new options here, as plugins use this function by
  45. # default. In most cases, you should add new options to specific targets instead
  46. # of modifying this function.
  47. function(APPLY_STANDARD_SETTINGS TARGET)
  48. target_compile_features(${TARGET} PUBLIC cxx_std_17)
  49. target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
  50. target_compile_options(${TARGET} PRIVATE /EHsc)
  51. # Disable VC140_1
  52. target_compile_options(${TARGET} PRIVATE /d2FH4-)
  53. target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
  54. target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
  55. endfunction()
  56. # Flutter library and tool build rules.
  57. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
  58. add_subdirectory(${FLUTTER_MANAGED_DIR})
  59. # Application build; see runner/CMakeLists.txt.
  60. add_subdirectory("runner")
  61. # Generated plugin build rules, which manage building the plugins and adding
  62. # them to the application.
  63. include(flutter/generated_plugins.cmake)
  64. # === Installation ===
  65. # Support files are copied into place next to the executable, so that it can
  66. # run in place. This is done instead of making a separate bundle (as on Linux)
  67. # so that building and running from within Visual Studio will work.
  68. set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
  69. # Make the "install" step default, as it's required to run.
  70. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
  71. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  72. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  73. endif()
  74. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  75. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
  76. install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  77. COMPONENT Runtime)
  78. install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  79. COMPONENT Runtime)
  80. install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  81. COMPONENT Runtime)
  82. if(PLUGIN_BUNDLED_LIBRARIES)
  83. install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
  84. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  85. COMPONENT Runtime)
  86. endif()
  87. # flutter_rust_bridge
  88. set(RUSTDESK_LIB_BUILD_TYPE $<IF:$<CONFIG:Debug>,debug,release>)
  89. message(STATUS "rustdesk lib build type: ${RUSTDESK_LIB_BUILD_TYPE}")
  90. set(RUSTDESK_LIB "../../target/${RUSTDESK_LIB_BUILD_TYPE}/librustdesk.dll")
  91. install(FILES "${RUSTDESK_LIB}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  92. COMPONENT Runtime RENAME librustdesk.dll)
  93. # Fully re-copy the assets directory on each build to avoid having stale files
  94. # from a previous install.
  95. set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
  96. install(CODE "
  97. file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  98. " COMPONENT Runtime)
  99. install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
  100. DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
  101. # Install the AOT library on non-Debug builds only.
  102. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  103. CONFIGURATIONS Profile;Release
  104. COMPONENT Runtime)