CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Project-level configuration.
  2. cmake_minimum_required(VERSION 3.14)
  3. project(rice 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. # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
  8. # versions of CMake.
  9. cmake_policy(VERSION 3.14...3.25)
  10. # Define build configuration option.
  11. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  12. if(IS_MULTICONFIG)
  13. set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
  14. CACHE STRING "" FORCE)
  15. else()
  16. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  17. set(CMAKE_BUILD_TYPE "Debug" CACHE
  18. STRING "Flutter build mode" FORCE)
  19. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
  20. "Debug" "Profile" "Release")
  21. endif()
  22. endif()
  23. # Define settings for the Profile build mode.
  24. set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
  25. set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
  26. set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
  27. set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
  28. # Use Unicode for all projects.
  29. add_definitions(-DUNICODE -D_UNICODE)
  30. # Compilation settings that should be applied to most targets.
  31. #
  32. # Be cautious about adding new options here, as plugins use this function by
  33. # default. In most cases, you should add new options to specific targets instead
  34. # of modifying this function.
  35. function(APPLY_STANDARD_SETTINGS TARGET)
  36. target_compile_features(${TARGET} PUBLIC cxx_std_17)
  37. target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
  38. target_compile_options(${TARGET} PRIVATE /EHsc)
  39. target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
  40. target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
  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. # Application build; see runner/CMakeLists.txt.
  46. add_subdirectory("runner")
  47. # Generated plugin build rules, which manage building the plugins and adding
  48. # them to the application.
  49. include(flutter/generated_plugins.cmake)
  50. # === Installation ===
  51. # Support files are copied into place next to the executable, so that it can
  52. # run in place. This is done instead of making a separate bundle (as on Linux)
  53. # so that building and running from within Visual Studio will work.
  54. set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
  55. # Make the "install" step default, as it's required to run.
  56. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
  57. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  58. set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
  59. endif()
  60. set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
  61. set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
  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. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  83. CONFIGURATIONS Profile;Release
  84. COMPONENT Runtime)