CMakeLists.txt.tmpl 5.45 KB
Newer Older
1
# Project-level configuration.
2 3 4
cmake_minimum_required(VERSION 3.10)
project(runner LANGUAGES CXX)

5 6
# The name of the executable created for the application. Change this to change
# the on-disk name of your application.
7
set(BINARY_NAME "{{projectName}}")
8 9
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
10
set(APPLICATION_ID "{{linuxIdentifier}}")
11

12 13
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
14 15
cmake_policy(SET CMP0063 NEW)

16
# Load bundled libraries from the lib/ directory relative to the binary.
17
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
18

19 20 21 22 23 24 25 26 27 28
# Root filesystem for cross-building.
if(FLUTTER_TARGET_PLATFORM_SYSROOT)
  set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
  set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif()

29
# Define build configuration options.
30 31 32 33 34 35 36 37
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_BUILD_TYPE "Debug" CACHE
    STRING "Flutter build mode" FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
    "Debug" "Profile" "Release")
endif()

# Compilation settings that should be applied to most targets.
38 39 40 41
#
# Be cautious about adding new options here, as plugins use this function by
# default. In most cases, you should add new options to specific targets instead
# of modifying this function.
42 43 44 45 46 47 48 49
function(APPLY_STANDARD_SETTINGS TARGET)
  target_compile_features(${TARGET} PUBLIC cxx_std_14)
  target_compile_options(${TARGET} PRIVATE -Wall -Werror)
  target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
  target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
endfunction()

# Flutter library and tool build rules.
50
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
51 52
add_subdirectory(${FLUTTER_MANAGED_DIR})

53 54 55 56
# System-level dependencies.
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)

57 58
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")

59 60 61 62
# Define the application target. To change its name, change BINARY_NAME above,
# not the value here, or `flutter run` will no longer work.
#
# Any new source files that you add to the application should be added here.
63 64
add_executable(${BINARY_NAME}
  "main.cc"
65
  "my_application.cc"
66 67
  "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
)
68 69 70

# Apply the standard set of build settings. This can be removed for applications
# that need different build settings.
71
apply_standard_settings(${BINARY_NAME})
72 73

# Add dependency libraries. Add any application-specific dependencies here.
74 75
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
76 77

# Run the Flutter tool portions of the build. This must not be removed.
78
add_dependencies(${BINARY_NAME} flutter_assemble)
79

80 81 82 83 84 85 86 87
# Only the install-generated bundle's copy of the executable will launch
# correctly, since the resources must in the right relative locations. To avoid
# people trying to run the unbundled copy, put it in a subdirectory instead of
# the default top-level location.
set_target_properties(${BINARY_NAME}
  PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
)
88

89 90 91 92 93
{{#withPlatformChannelPluginHook}}
# Enable the test target.
set(include_{{pluginProjectName}}_tests TRUE)
{{/withPlatformChannelPluginHook}}

94 95 96 97 98 99 100 101
# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)


# === Installation ===
# By default, "installing" just makes a relocatable bundle in the build
# directory.
102
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
103
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
104
  set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
105 106
endif()

107 108
# Start with a clean build bundle directory every time.
install(CODE "
109 110 111
  file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
  " COMPONENT Runtime)

112 113 114 115 116 117
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")

install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
  COMPONENT Runtime)

118 119
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
  COMPONENT Runtime)
120

121 122
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  COMPONENT Runtime)
123

Daco Harkes's avatar
Daco Harkes committed
124 125
foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
  install(FILES "${bundled_library}"
126 127
    DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
    COMPONENT Runtime)
Daco Harkes's avatar
Daco Harkes committed
128
endforeach(bundled_library)
129

130 131 132 133 134 135
# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
   DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
   COMPONENT Runtime)

136 137 138
# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
139
install(CODE "
140 141
  file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
  " COMPONENT Runtime)
142
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
143
  DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
144

145
# Install the AOT library on non-Debug builds only.
146
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
147 148
  install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
    COMPONENT Runtime)
149
endif()