CMakeLists.txt 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. cmake_minimum_required(VERSION 3.15)
  2. project(flutter_green LANGUAGES CXX)
  3. set(BINARY_NAME "flutter_green")
  4. cmake_policy(SET CMP0063 NEW)
  5. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
  6. # Configure build options.
  7. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  8. if(IS_MULTICONFIG)
  9. set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
  10. CACHE STRING "" FORCE)
  11. else()
  12. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  13. set(CMAKE_BUILD_TYPE "Debug" CACHE
  14. STRING "Flutter build mode" FORCE)
  15. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  16. "Debug" "Profile" "Release")
  17. endif()
  18. endif()
  19. set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
  20. set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
  21. set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
  22. set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
  23. # Use Unicode for all projects.
  24. add_definitions(-DUNICODE -D_UNICODE)
  25. # Compilation settings that should be applied to most targets.
  26. function(APPLY_STANDARD_SETTINGS TARGET)
  27. target_compile_features(${TARGET} PUBLIC cxx_std_17)
  28. target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
  29. target_compile_options(${TARGET} PRIVATE /EHsc)
  30. target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
  31. target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
  32. endfunction()
  33. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
  34. # Flutter library and tool build rules.
  35. add_subdirectory(${FLUTTER_MANAGED_DIR})
  36. # Application build
  37. add_subdirectory("runner")
  38. # Generated plugin build rules, which manage building the plugins and adding
  39. # them to the application.
  40. include(flutter/generated_plugins.cmake)
  41. # === Installation ===
  42. # Support files are copied into place next to the executable, so that it can
  43. # run in place. This is done instead of making a separate bundle (as on Linux)
  44. # so that building and running from within Visual Studio will work.
  45. set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
  46. # Make the "install" step default, as it's required to run.
  47. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
  48. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  49. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  50. endif()
  51. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  52. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
  53. install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  54. COMPONENT Runtime)
  55. install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  56. COMPONENT Runtime)
  57. install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  58. COMPONENT Runtime)
  59. if(PLUGIN_BUNDLED_LIBRARIES)
  60. install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
  61. DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  62. COMPONENT Runtime)
  63. endif()
  64. # Fully re-copy the assets directory on each build to avoid having stale files
  65. # from a previous install.
  66. set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
  67. install(CODE "
  68. file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  69. " COMPONENT Runtime)
  70. install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
  71. DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
  72. # Install the AOT library on non-Debug builds only.
  73. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  74. CONFIGURATIONS Profile;Release
  75. COMPONENT Runtime)