CMakeLists.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "rice")
  7. # The unique GTK application identifier for this application. See:
  8. # https://wiki.gnome.org/HowDoI/ChooseApplicationID
  9. set(APPLICATION_ID "com.pany.rice.rice")
  10. # Explicitly opt in to 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. # Run the Flutter tool portions of the build. This must not be removed.
  65. add_dependencies(${BINARY_NAME} flutter_assemble)
  66. # Only the install-generated bundle's copy of the executable will launch
  67. # correctly, since the resources must in the right relative locations. To avoid
  68. # people trying to run the unbundled copy, put it in a subdirectory instead of
  69. # the default top-level location.
  70. set_target_properties(${BINARY_NAME}
  71. PROPERTIES
  72. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
  73. )
  74. # Generated plugin build rules, which manage building the plugins and adding
  75. # them to the application.
  76. include(flutter/generated_plugins.cmake)
  77. # === Installation ===
  78. # By default, "installing" just makes a relocatable bundle in the build
  79. # directory.
  80. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
  81. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  82. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  83. endif()
  84. # Start with a clean build bundle directory every time.
  85. install(CODE "
  86. file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
  87. " COMPONENT Runtime)
  88. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  89. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
  90. install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  91. COMPONENT Runtime)
  92. install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  93. COMPONENT Runtime)
  94. install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  95. COMPONENT Runtime)
  96. foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
  97. install(FILES "${bundled_library}"
  98. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  99. COMPONENT Runtime)
  100. endforeach(bundled_library)
  101. # Fully re-copy the assets directory on each build to avoid having stale files
  102. # from a previous install.
  103. set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
  104. install(CODE "
  105. file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  106. " COMPONENT Runtime)
  107. install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
  108. DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
  109. # Install the AOT library on non-Debug builds only.
  110. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
  111. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  112. COMPONENT Runtime)
  113. endif()