CMakeLists.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Project-level configuration.
  2. cmake_minimum_required(VERSION 3.13)
  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 "photo_classify_example")
  7. # The unique GTK application identifier for this application. See:
  8. # https://wiki.gnome.org/HowDoI/ChooseApplicationID
  9. set(APPLICATION_ID "com.example.photo_classify")
  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. # Application build; see runner/CMakeLists.txt.
  49. add_subdirectory("runner")
  50. # Run the Flutter tool portions of the build. This must not be removed.
  51. add_dependencies(${BINARY_NAME} flutter_assemble)
  52. # Only the install-generated bundle's copy of the executable will launch
  53. # correctly, since the resources must in the right relative locations. To avoid
  54. # people trying to run the unbundled copy, put it in a subdirectory instead of
  55. # the default top-level location.
  56. set_target_properties(${BINARY_NAME}
  57. PROPERTIES
  58. RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
  59. )
  60. # Enable the test target.
  61. set(include_photo_classify_tests TRUE)
  62. # Generated plugin build rules, which manage building the plugins and adding
  63. # them to the application.
  64. include(flutter/generated_plugins.cmake)
  65. # === Installation ===
  66. # By default, "installing" just makes a relocatable bundle in the build
  67. # directory.
  68. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
  69. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  70. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  71. endif()
  72. # Start with a clean build bundle directory every time.
  73. install(CODE "
  74. file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
  75. " COMPONENT Runtime)
  76. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  77. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
  78. install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  79. COMPONENT Runtime)
  80. install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  81. COMPONENT Runtime)
  82. install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  83. COMPONENT Runtime)
  84. foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
  85. install(FILES "${bundled_library}"
  86. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  87. COMPONENT Runtime)
  88. endforeach(bundled_library)
  89. # Copy the native assets provided by the build.dart from all packages.
  90. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
  91. install(DIRECTORY "${NATIVE_ASSETS_DIR}"
  92. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  93. COMPONENT Runtime)
  94. # Fully re-copy the assets directory on each build to avoid having stale files
  95. # from a previous install.
  96. set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
  97. install(CODE "
  98. file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  99. " COMPONENT Runtime)
  100. install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
  101. DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
  102. # Install the AOT library on non-Debug builds only.
  103. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
  104. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  105. COMPONENT Runtime)
  106. endif()