You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.0 KiB

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