CMakeLists.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # Project-level configuration.
  2. cmake_minimum_required(VERSION 3.10)
  3. project(runner 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. # The unique GTK application identifier for this application. See:
  8. # https://wiki.gnome.org/HowDoI/ChooseApplicationID
  9. set(APPLICATION_ID "com.carriez.flutter_hbb")
  10. # Explicitly opt into modern CMake behaviors to avoid warnings with recent
  11. # versions of CMake.
  12. cmake_policy(SET CMP0063 NEW)
  13. # Load bundled libraries from the lib/ directory relative to the binary.
  14. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
  15. # Root filesystem for cross-building.
  16. if(FLUTTER_TARGET_PLATFORM_SYSROOT)
  17. set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
  18. set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
  19. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  20. set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  21. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  22. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  23. endif()
  24. # Define build configuration options.
  25. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  26. set(CMAKE_BUILD_TYPE "Debug" CACHE
  27. STRING "Flutter build mode" FORCE)
  28. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  29. "Debug" "Profile" "Release")
  30. endif()
  31. # Compilation settings that should be applied to most targets.
  32. #
  33. # Be cautious about adding new options here, as plugins use this function by
  34. # default. In most cases, you should add new options to specific targets instead
  35. # of modifying this function.
  36. function(APPLY_STANDARD_SETTINGS TARGET)
  37. target_compile_features(${TARGET} PUBLIC cxx_std_14)
  38. target_compile_options(${TARGET} PRIVATE -Wall -Werror)
  39. target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
  40. target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
  41. endfunction()
  42. # Flutter library and tool build rules.
  43. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
  44. add_subdirectory(${FLUTTER_MANAGED_DIR})
  45. # System-level dependencies.
  46. find_package(PkgConfig REQUIRED)
  47. pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
  48. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
  49. # Define the application target. To change its name, change BINARY_NAME above,
  50. # not the value here, or `flutter run` will no longer work.
  51. #
  52. # Any new source files that you add to the application should be added here.
  53. add_executable(${BINARY_NAME}
  54. "main.cc"
  55. "my_application.cc"
  56. "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
  57. )
  58. # Apply the standard set of build settings. This can be removed for applications
  59. # that need different build settings.
  60. apply_standard_settings(${BINARY_NAME})
  61. # Add dependency libraries. Add any application-specific dependencies here.
  62. target_link_libraries(${BINARY_NAME} PRIVATE flutter)
  63. target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
  64. target_link_libraries(${BINARY_NAME} PRIVATE ${CMAKE_DL_LIBS})
  65. # target_link_libraries(${BINARY_NAME} PRIVATE librustdesk)
  66. # Run the Flutter tool portions of the build. This must not be removed.
  67. add_dependencies(${BINARY_NAME} flutter_assemble)
  68. # Only the install-generated bundle's copy of the executable will launch
  69. # correctly, since the resources must in the right relative locations. To avoid
  70. # people trying to run the unbundled copy, put it in a subdirectory instead of
  71. # the default top-level location.
  72. set_target_properties(${BINARY_NAME}
  73. PROPERTIES
  74. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
  75. )
  76. # Generated plugin build rules, which manage building the plugins and adding
  77. # them to the application.
  78. include(flutter/generated_plugins.cmake)
  79. # === Installation ===
  80. # By default, "installing" just makes a relocatable bundle in the build
  81. # directory.
  82. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
  83. #if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  84. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  85. #endif()
  86. # Start with a clean build bundle directory every time.
  87. install(CODE "
  88. file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
  89. " COMPONENT Runtime)
  90. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  91. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
  92. install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  93. COMPONENT Runtime)
  94. install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  95. COMPONENT Runtime)
  96. install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  97. COMPONENT Runtime)
  98. foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
  99. install(FILES "${bundled_library}"
  100. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  101. COMPONENT Runtime)
  102. endforeach(bundled_library)
  103. # flutter_rust_bridge
  104. set(RUSTDESK_LIB_BUILD_TYPE $<IF:$<CONFIG:Debug>,debug,release>)
  105. string(TOLOWER ${CMAKE_BUILD_TYPE} ${RUSTDESK_LIB_BUILD_TYPE})
  106. message(STATUS "rustdesk lib build type: ${RUSTDESK_LIB_BUILD_TYPE}")
  107. set(RUSTDESK_LIB "../../target/${RUSTDESK_LIB_BUILD_TYPE}/liblibrustdesk.so")
  108. install(FILES "${RUSTDESK_LIB}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  109. COMPONENT Runtime RENAME librustdesk.so)
  110. # Fully re-copy the assets directory on each build to avoid having stale files
  111. # from a previous install.
  112. set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
  113. install(CODE "
  114. file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  115. " COMPONENT Runtime)
  116. install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
  117. DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
  118. # Install the AOT library on non-Debug builds only.
  119. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
  120. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  121. COMPONENT Runtime)
  122. endif()