|
| 1 | +cmake_minimum_required(VERSION 3.15) |
| 2 | +project(example LANGUAGES CXX) |
| 3 | + |
| 4 | +set(BINARY_NAME "example") |
| 5 | + |
| 6 | +cmake_policy(SET CMP0063 NEW) |
| 7 | + |
| 8 | +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") |
| 9 | + |
| 10 | +# Configure build options. |
| 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 | + |
| 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 | + |
| 29 | +# Use Unicode for all projects. |
| 30 | +add_definitions(-DUNICODE -D_UNICODE) |
| 31 | + |
| 32 | +# Compilation settings that should be applied to most targets. |
| 33 | +function(APPLY_STANDARD_SETTINGS TARGET) |
| 34 | + target_compile_features(${TARGET} PUBLIC cxx_std_17) |
| 35 | + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") |
| 36 | + target_compile_options(${TARGET} PRIVATE /EHsc) |
| 37 | + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") |
| 38 | + target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>") |
| 39 | +endfunction() |
| 40 | + |
| 41 | +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") |
| 42 | + |
| 43 | +# Flutter library and tool build rules. |
| 44 | +add_subdirectory(${FLUTTER_MANAGED_DIR}) |
| 45 | + |
| 46 | +# Application build |
| 47 | +add_subdirectory("runner") |
| 48 | + |
| 49 | +# Generated plugin build rules, which manage building the plugins and adding |
| 50 | +# them to the application. |
| 51 | +include(flutter/generated_plugins.cmake) |
| 52 | + |
| 53 | + |
| 54 | +# === Installation === |
| 55 | +# Support files are copied into place next to the executable, so that it can |
| 56 | +# run in place. This is done instead of making a separate bundle (as on Linux) |
| 57 | +# so that building and running from within Visual Studio will work. |
| 58 | +set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>") |
| 59 | +# Make the "install" step default, as it's required to run. |
| 60 | +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) |
| 61 | +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 62 | + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) |
| 63 | +endif() |
| 64 | + |
| 65 | +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") |
| 66 | +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") |
| 67 | + |
| 68 | +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" |
| 69 | + COMPONENT Runtime) |
| 70 | + |
| 71 | +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" |
| 72 | + COMPONENT Runtime) |
| 73 | + |
| 74 | +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" |
| 75 | + COMPONENT Runtime) |
| 76 | + |
| 77 | +if(PLUGIN_BUNDLED_LIBRARIES) |
| 78 | + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" |
| 79 | + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" |
| 80 | + COMPONENT Runtime) |
| 81 | +endif() |
| 82 | + |
| 83 | +# Fully re-copy the assets directory on each build to avoid having stale files |
| 84 | +# from a previous install. |
| 85 | +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") |
| 86 | +install(CODE " |
| 87 | + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") |
| 88 | + " COMPONENT Runtime) |
| 89 | +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" |
| 90 | + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) |
| 91 | + |
| 92 | +# Install the AOT library on non-Debug builds only. |
| 93 | +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" |
| 94 | + CONFIGURATIONS Profile;Release |
| 95 | + COMPONENT Runtime) |
0 commit comments