at main 4.8 kB view raw
1# Project-level configuration. 2cmake_minimum_required(VERSION 3.13) 3project(runner 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# The unique GTK application identifier for this application. See: 9# https://wiki.gnome.org/HowDoI/ChooseApplicationID 10set(APPLICATION_ID "com.coves.coves_flutter") 11 12# Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13# versions of CMake. 14cmake_policy(SET CMP0063 NEW) 15 16# Load bundled libraries from the lib/ directory relative to the binary. 17set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 19# Root filesystem for cross-building. 20if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27endif() 28 29# Define build configuration options. 30if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 set(CMAKE_BUILD_TYPE "Debug" CACHE 32 STRING "Flutter build mode" FORCE) 33 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 "Debug" "Profile" "Release") 35endif() 36 37# Compilation settings that should be applied to most targets. 38# 39# Be cautious about adding new options here, as plugins use this function by 40# default. In most cases, you should add new options to specific targets instead 41# of modifying this function. 42function(APPLY_STANDARD_SETTINGS TARGET) 43 target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>") 46 target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>") 47endfunction() 48 49# Flutter library and tool build rules. 50set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 53# System-level dependencies. 54find_package(PkgConfig REQUIRED) 55pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 57# Application build; see runner/CMakeLists.txt. 58add_subdirectory("runner") 59 60# Run the Flutter tool portions of the build. This must not be removed. 61add_dependencies(${BINARY_NAME} flutter_assemble) 62 63# Only the install-generated bundle's copy of the executable will launch 64# correctly, since the resources must in the right relative locations. To avoid 65# people trying to run the unbundled copy, put it in a subdirectory instead of 66# the default top-level location. 67set_target_properties(${BINARY_NAME} 68 PROPERTIES 69 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 70) 71 72 73# Generated plugin build rules, which manage building the plugins and adding 74# them to the application. 75include(flutter/generated_plugins.cmake) 76 77 78# === Installation === 79# By default, "installing" just makes a relocatable bundle in the build 80# directory. 81set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 82if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 83 set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 84endif() 85 86# Start with a clean build bundle directory every time. 87install(CODE " 88 file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 89 " COMPONENT Runtime) 90 91set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 92set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 93 94install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 95 COMPONENT Runtime) 96 97install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 98 COMPONENT Runtime) 99 100install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 101 COMPONENT Runtime) 102 103foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 104 install(FILES "${bundled_library}" 105 DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 106 COMPONENT Runtime) 107endforeach(bundled_library) 108 109# Copy the native assets provided by the build.dart from all packages. 110set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") 111install(DIRECTORY "${NATIVE_ASSETS_DIR}" 112 DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 113 COMPONENT Runtime) 114 115# Fully re-copy the assets directory on each build to avoid having stale files 116# from a previous install. 117set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 118install(CODE " 119 file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 120 " COMPONENT Runtime) 121install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 122 DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 123 124# Install the AOT library on non-Debug builds only. 125if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 126 install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 127 COMPONENT Runtime) 128endif()