|
| 1 | +cmake_minimum_required(VERSION 3.10) |
| 2 | +project(runner LANGUAGES CXX) |
| 3 | + |
| 4 | +set(BINARY_NAME "flutter_constraintlayout") |
| 5 | +set(APPLICATION_ID "cn.flutterfirst.constraintlayout") |
| 6 | + |
| 7 | +cmake_policy(SET CMP0063 NEW) |
| 8 | + |
| 9 | +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") |
| 10 | + |
| 11 | +# Root filesystem for cross-building. |
| 12 | +if(FLUTTER_TARGET_PLATFORM_SYSROOT) |
| 13 | + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) |
| 14 | + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) |
| 15 | + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 16 | + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) |
| 17 | + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 18 | + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 19 | +endif() |
| 20 | + |
| 21 | +# Configure build options. |
| 22 | +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 23 | + set(CMAKE_BUILD_TYPE "Debug" CACHE |
| 24 | + STRING "Flutter build mode" FORCE) |
| 25 | + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS |
| 26 | + "Debug" "Profile" "Release") |
| 27 | +endif() |
| 28 | + |
| 29 | +# Compilation settings that should be applied to most targets. |
| 30 | +function(APPLY_STANDARD_SETTINGS TARGET) |
| 31 | + target_compile_features(${TARGET} PUBLIC cxx_std_14) |
| 32 | + target_compile_options(${TARGET} PRIVATE -Wall -Werror) |
| 33 | + target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>") |
| 34 | + target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>") |
| 35 | +endfunction() |
| 36 | + |
| 37 | +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") |
| 38 | + |
| 39 | +# Flutter library and tool build rules. |
| 40 | +add_subdirectory(${FLUTTER_MANAGED_DIR}) |
| 41 | + |
| 42 | +# System-level dependencies. |
| 43 | +find_package(PkgConfig REQUIRED) |
| 44 | +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) |
| 45 | + |
| 46 | +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") |
| 47 | + |
| 48 | +# Application build |
| 49 | +add_executable(${BINARY_NAME} |
| 50 | + "main.cc" |
| 51 | + "my_application.cc" |
| 52 | + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" |
| 53 | +) |
| 54 | +apply_standard_settings(${BINARY_NAME}) |
| 55 | +target_link_libraries(${BINARY_NAME} PRIVATE flutter) |
| 56 | +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) |
| 57 | +add_dependencies(${BINARY_NAME} flutter_assemble) |
| 58 | +# Only the install-generated bundle's copy of the executable will launch |
| 59 | +# correctly, since the resources must in the right relative locations. To avoid |
| 60 | +# people trying to run the unbundled copy, put it in a subdirectory instead of |
| 61 | +# the default top-level location. |
| 62 | +set_target_properties(${BINARY_NAME} |
| 63 | + PROPERTIES |
| 64 | + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" |
| 65 | +) |
| 66 | + |
| 67 | +# Generated plugin build rules, which manage building the plugins and adding |
| 68 | +# them to the application. |
| 69 | +include(flutter/generated_plugins.cmake) |
| 70 | + |
| 71 | + |
| 72 | +# === Installation === |
| 73 | +# By default, "installing" just makes a relocatable bundle in the build |
| 74 | +# directory. |
| 75 | +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") |
| 76 | +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 77 | + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) |
| 78 | +endif() |
| 79 | + |
| 80 | +# Start with a clean build bundle directory every time. |
| 81 | +install(CODE " |
| 82 | + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") |
| 83 | + " COMPONENT Runtime) |
| 84 | + |
| 85 | +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") |
| 86 | +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") |
| 87 | + |
| 88 | +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" |
| 89 | + COMPONENT Runtime) |
| 90 | + |
| 91 | +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" |
| 92 | + COMPONENT Runtime) |
| 93 | + |
| 94 | +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" |
| 95 | + COMPONENT Runtime) |
| 96 | + |
| 97 | +if(PLUGIN_BUNDLED_LIBRARIES) |
| 98 | + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" |
| 99 | + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" |
| 100 | + COMPONENT Runtime) |
| 101 | +endif() |
| 102 | + |
| 103 | +# Fully re-copy the assets directory on each build to avoid having stale files |
| 104 | +# from a previous install. |
| 105 | +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") |
| 106 | +install(CODE " |
| 107 | + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") |
| 108 | + " COMPONENT Runtime) |
| 109 | +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" |
| 110 | + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) |
| 111 | + |
| 112 | +# Install the AOT library on non-Debug builds only. |
| 113 | +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") |
| 114 | + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" |
| 115 | + COMPONENT Runtime) |
| 116 | +endif() |
0 commit comments