CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. cmake_minimum_required(VERSION 3.10)
  2. project(runner LANGUAGES CXX)
  3. set(BINARY_NAME "flutter_green")
  4. set(APPLICATION_ID "me.yoqi.flutter.flutter_green")
  5. cmake_policy(SET CMP0063 NEW)
  6. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
  7. # Configure build options.
  8. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  9. set(CMAKE_BUILD_TYPE "Debug" CACHE
  10. STRING "Flutter build mode" FORCE)
  11. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  12. "Debug" "Profile" "Release")
  13. endif()
  14. # Compilation settings that should be applied to most targets.
  15. function(APPLY_STANDARD_SETTINGS TARGET)
  16. target_compile_features(${TARGET} PUBLIC cxx_std_14)
  17. target_compile_options(${TARGET} PRIVATE -Wall -Werror)
  18. target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
  19. target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
  20. endfunction()
  21. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
  22. # Flutter library and tool build rules.
  23. add_subdirectory(${FLUTTER_MANAGED_DIR})
  24. # System-level dependencies.
  25. find_package(PkgConfig REQUIRED)
  26. pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
  27. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
  28. # Application build
  29. add_executable(${BINARY_NAME}
  30. "main.cc"
  31. "my_application.cc"
  32. "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
  33. )
  34. apply_standard_settings(${BINARY_NAME})
  35. target_link_libraries(${BINARY_NAME} PRIVATE flutter)
  36. target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
  37. add_dependencies(${BINARY_NAME} flutter_assemble)
  38. # Only the install-generated bundle's copy of the executable will launch
  39. # correctly, since the resources must in the right relative locations. To avoid
  40. # people trying to run the unbundled copy, put it in a subdirectory instead of
  41. # the default top-level location.
  42. set_target_properties(${BINARY_NAME}
  43. PROPERTIES
  44. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
  45. )
  46. # Generated plugin build rules, which manage building the plugins and adding
  47. # them to the application.
  48. include(flutter/generated_plugins.cmake)
  49. # === Installation ===
  50. # By default, "installing" just makes a relocatable bundle in the build
  51. # directory.
  52. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
  53. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  54. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  55. endif()
  56. # Start with a clean build bundle directory every time.
  57. install(CODE "
  58. file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
  59. " COMPONENT Runtime)
  60. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  61. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
  62. install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  63. COMPONENT Runtime)
  64. install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  65. COMPONENT Runtime)
  66. install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  67. COMPONENT Runtime)
  68. if(PLUGIN_BUNDLED_LIBRARIES)
  69. install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
  70. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  71. COMPONENT Runtime)
  72. endif()
  73. # Fully re-copy the assets directory on each build to avoid having stale files
  74. # from a previous install.
  75. set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
  76. install(CODE "
  77. file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  78. " COMPONENT Runtime)
  79. install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
  80. DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
  81. # Install the AOT library on non-Debug builds only.
  82. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
  83. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  84. COMPONENT Runtime)
  85. endif()