Main coves client
1# Project-level configuration.
2cmake_minimum_required(VERSION 3.14)
3project(coves_flutter LANGUAGES CXX)
4
5# The name of the executable created for the application. Change this to change
6# the on-disk name of your application.
7set(BINARY_NAME "coves_flutter")
8
9# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10# versions of CMake.
11cmake_policy(VERSION 3.14...3.25)
12
13# Define build configuration option.
14get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
15if(IS_MULTICONFIG)
16 set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
17 CACHE STRING "" FORCE)
18else()
19 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
20 set(CMAKE_BUILD_TYPE "Debug" CACHE
21 STRING "Flutter build mode" FORCE)
22 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
23 "Debug" "Profile" "Release")
24 endif()
25endif()
26# Define settings for the Profile build mode.
27set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
28set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
29set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
30set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
31
32# Use Unicode for all projects.
33add_definitions(-DUNICODE -D_UNICODE)
34
35# Compilation settings that should be applied to most targets.
36#
37# Be cautious about adding new options here, as plugins use this function by
38# default. In most cases, you should add new options to specific targets instead
39# of modifying this function.
40function(APPLY_STANDARD_SETTINGS TARGET)
41 target_compile_features(${TARGET} PUBLIC cxx_std_17)
42 target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
43 target_compile_options(${TARGET} PRIVATE /EHsc)
44 target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
45 target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
46endfunction()
47
48# Flutter library and tool build rules.
49set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
50add_subdirectory(${FLUTTER_MANAGED_DIR})
51
52# Application build; see runner/CMakeLists.txt.
53add_subdirectory("runner")
54
55
56# Generated plugin build rules, which manage building the plugins and adding
57# them to the application.
58include(flutter/generated_plugins.cmake)
59
60
61# === Installation ===
62# Support files are copied into place next to the executable, so that it can
63# run in place. This is done instead of making a separate bundle (as on Linux)
64# so that building and running from within Visual Studio will work.
65set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
66# Make the "install" step default, as it's required to run.
67set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
68if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
69 set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
70endif()
71
72set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
73set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
74
75install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
76 COMPONENT Runtime)
77
78install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
79 COMPONENT Runtime)
80
81install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
82 COMPONENT Runtime)
83
84if(PLUGIN_BUNDLED_LIBRARIES)
85 install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
86 DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
87 COMPONENT Runtime)
88endif()
89
90# Copy the native assets provided by the build.dart from all packages.
91set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
92install(DIRECTORY "${NATIVE_ASSETS_DIR}"
93 DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
94 COMPONENT Runtime)
95
96# Fully re-copy the assets directory on each build to avoid having stale files
97# from a previous install.
98set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
99install(CODE "
100 file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
101 " COMPONENT Runtime)
102install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
103 DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
104
105# Install the AOT library on non-Debug builds only.
106install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
107 CONFIGURATIONS Profile;Release
108 COMPONENT Runtime)