### Install Application Executable Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Installs the application executable to the root of the installation prefix. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Define Installation Directories Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Sets variables for the installation directories within the bundle for data and libraries. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Installation Bundle Directory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Determines the directory where support files will be installed, adjacent to the executable. ```cmake set(BUILD_BUNDLE_DIR "$") ``` -------------------------------- ### Installation Directory Variables Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Defines variables for the installation paths of data and library files within the bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Flutter Library Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Installs the main Flutter library file to the library directory within the bundle. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Installs native assets provided by build.dart from all packages into the library directory. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Installs any bundled plugin libraries to the library directory within the bundle, if they exist. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Installs all bundled libraries provided by plugins to the library directory within the bundle. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Set Install Prefix to Bundle Directory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Forces the installation prefix to be the bundle directory when it's initialized to its default value, ensuring files are installed next to the executable. ```cmake if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install AOT Library Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compilation library, but only for Profile and Release build configurations. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix for Bundle Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Initializes the CMAKE_INSTALL_PREFIX to a bundle directory within the project's binary directory if it hasn't been set. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install ICU Data File Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Installs the ICU data file to the data directory within the bundle. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Copies native assets provided by build.dart from all packages to the library directory within the bundle. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Clean Build Bundle Directory on Install Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Removes the build bundle directory before installation to ensure a clean state. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library for Non-Debug Builds Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the library directory within the bundle, but only for non-Debug build configurations. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Configure Flutter Library and Dependencies Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/flutter/CMakeLists.txt This section configures the Flutter library and its interface using CMake. It finds necessary packages like PkgConfig, GTK, GLIB, and GIO, sets paths for the Flutter library and AOT library, and defines include directories and link libraries for the 'flutter' target. Ensure these packages are installed on your system. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Clean and Copy Assets Directory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Removes the existing assets directory and copies the new assets from the build directory to the data directory within the bundle on each install. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Enable Testing Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Enables testing if the include_volume_controller_tests variable is set. This ensures tests are only built when the example is built. ```cmake if (${include_${PROJECT_NAME}_tests}) set(TEST_RUNNER "${PROJECT_NAME}_test") enable_testing() # Add the Google Test dependency. include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/release-1.11.0.zip ) # Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Disable install commands for gtest so it doesn't end up in the bundle. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE) FetchContent_MakeAvailable(googletest) # The plugin's C API is not very useful for unit testing, so build the sources # directly into the test binary rather than using the DLL. add_executable(${TEST_RUNNER} test/volume_controller_plugin_test.cpp ${PLUGIN_SOURCES} ) apply_standard_settings(${TEST_RUNNER}) target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin) target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock) # flutter_wrapper_plugin has link dependencies on the Flutter DLL. add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${FLUTTER_LIBRARY}" $) # Enable automatic test discovery. include(GoogleTest) gtest_discover_tests(${TEST_RUNNER}) endif() ``` -------------------------------- ### Configure Minimum CMake Version Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Sets the minimum required CMake version for the project. Ensure CMake 3.10 or later is installed. Do not increase this version to avoid compilation issues. ```cmake cmake_minimum_required(VERSION 3.10) ``` -------------------------------- ### Get Current System Volume Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Retrieve the current system volume level. The returned value is a double between 0.0 and 1.0. ```dart double volume = await VolumeController.instance.getVolume(); ``` -------------------------------- ### Set Flutter Library and ICU Data Path Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/flutter/CMakeLists.txt Configures the Flutter library path and ICU data file path. These are published to the parent scope for use in the install step. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) ``` -------------------------------- ### Configure Cross-Building Root Filesystem Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Sets up the sysroot and find root path for cross-building environments. ```cmake 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() ``` -------------------------------- ### Include Directories and Link Libraries Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Specifies interface include directories and links necessary libraries. Add any plugin-specific dependencies here. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Applies a standard set of build settings configured in the application-level CMakeLists.txt. This can be removed for full control. ```cmake apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### AddListener Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Registers a callback function to be invoked whenever the system volume changes. Optionally fetches the initial volume upon listener registration. ```APIDOC ## AddListener ### Description Add a listener to monitor system volume changes. ### Method POST (conceptual) ### Endpoint N/A (This is a method call) ### Parameters - **callback** (Function(double volume)) - Required - A function that accepts the new volume level as a double. - **fetchInitialVolume** (boolean) - Optional - If `true`, the initial volume is fetched and passed to the callback when the listener is added. Defaults to `true`. ### Request Example ```dart VolumeController.instance.addListener((volume) { print('Volume changed to: $volume'); }, fetchInitialVolume: true); ``` ``` -------------------------------- ### Set Include Directories and Link Libraries Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Specifies include directories for plugin headers and links necessary libraries. Includes the 'flutter' library and PkgConfig::GTK. ```cmake target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/runner/CMakeLists.txt Specifies the libraries and include directories required for the application. Add any application-specific dependencies here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### List Plugin Source Files Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Appends all necessary source files for the plugin to the PLUGIN_SOURCES list. Ensure all new source files are added here. ```cmake list(APPEND PLUGIN_SOURCES "volume_controller_plugin.cc" "volume_controller.cc" "audio_controller.cc" "include/volume_controller/constants.h" "include/volume_controller/volume_controller.h" "include/volume_controller/audio_controller.h" ) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the application target. This can be customized for applications requiring different build configurations. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### ShowSystemUI Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Controls the visibility of the system's volume user interface. This feature is exclusively supported on Android and iOS. The default setting is to display the UI. ```APIDOC ## ShowSystemUI ### Description Show or hide the volume system UI. Supported on iOS and Android only. The default value is `true`. ### Endpoint N/A (This is a variable setting) ### Parameters - **showSystemUI** (boolean) - Required - Set to `true` to show the system UI, `false` to hide it. ### Request Example ```dart VolumeController.instance.showSystemUI = true; ``` ``` -------------------------------- ### Enable Volume Controller Tests Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Sets a flag to enable the test target for the volume controller. ```cmake set(include_volume_controller_tests TRUE) ``` -------------------------------- ### Add Volume Change Listener Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Register a callback function to be notified of system volume changes. Optionally fetch the initial volume when the listener is added. The default for fetchInitialVolume is true. ```dart VolumeController.instance.addListener((volume) { // Do something with the volume }, fetchInitialVolume: true); ``` -------------------------------- ### Configure C++ Application Build Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/runner/CMakeLists.txt Defines the main executable for the C++ application, including source files and generated files. Ensure BINARY_NAME is consistent with top-level CMakeLists.txt for `flutter run` compatibility. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, 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. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add preprocessor definitions for the application ID. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt A function to apply common compilation settings like C++ standard, warning levels, and exception handling to a target. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Include Generated Plugin CMake Rules Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Includes the CMake rules for building generated plugins and adding them to the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Project Configuration Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Defines the project name and the languages it supports. The project name is used for internal references. ```cmake set(PROJECT_NAME "volume_controller") project(${PROJECT_NAME} LANGUAGES CXX) ``` -------------------------------- ### Set Runtime Path for Bundled Libraries Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Configures the runtime path to load bundled libraries from the 'lib/' directory relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Define Flutter Tool Backend Custom Command Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/flutter/CMakeLists.txt Sets up a custom command to execute the Flutter tool backend script. This command is designed to run every time by using a phony output file, as direct input/output listing is not currently supported. ```cmake # _phony_ is a non-existent file to force this command to run every time, since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Define Project and Plugin Name Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Sets the project name and the specific name for the plugin library. The PLUGIN_NAME must not be changed as it's used in build generation. ```cmake set(PROJECT_NAME "volume_controller") project(${PROJECT_NAME} LANGUAGES CXX) set(PLUGIN_NAME "volume_controller_plugin") ``` -------------------------------- ### Plugin Source Files Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Appends all source files belonging to the plugin to the PLUGIN_SOURCES list. Ensure all new source files are added here. ```cmake list(APPEND PLUGIN_SOURCES "volume_controller_plugin.cpp" "volume_controller_plugin.h" "include/volume_controller/constants.h" "include/volume_controller/volume_callback.h" "include/volume_controller/helper.cpp" "include/volume_controller/helper.h" "include/volume_controller/volume_controller.cpp" "include/volume_controller/volume_controller.h" "include/volume_controller/volume_listener.cpp" "include/volume_controller/volume_listener.h" "include/volume_controller/volume_stream_handler.cpp" "include/volume_controller/volume_stream_handler.h" ) ``` -------------------------------- ### Define Bundled Libraries Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Sets a list for libraries to be bundled with the plugin. This can include prebuilt libraries or those from external builds. ```cmake set(volume_controller_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Sets compilation and linking flags for the Profile build mode, often mirroring Release settings. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Enable Modern CMake Behaviors Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Configure Static Library for Flutter Wrapper Plugin Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper plugin, including core and plugin-specific sources. It applies standard settings, sets position-independent code, and links against the Flutter library. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Project and Minimum CMake Version Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Sets the minimum required CMake version and defines the project name and languages. ```cmake cmake_minimum_required(VERSION 3.14) project(volume_controller_example LANGUAGES CXX) ``` -------------------------------- ### Integrate Flutter Tool Build Steps Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's build steps are executed as part of the main application target's dependencies. This is a mandatory step and must not be removed. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Configure Static Library for Flutter Wrapper App Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper application, including core and app-specific sources. It links against the Flutter library and sets include directories. ```cmake # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/flutter/CMakeLists.txt This custom command uses the Flutter tool's backend script to generate build artifacts like the Flutter library and headers. The `_phony_` output is a non-existent file used to ensure the command runs on every build, as determining the exact output list for the Flutter tool is not straightforward. Environment variables like `FLUTTER_TOOL_ENVIRONMENT` and `FLUTTER_ROOT` must be correctly set. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Unicode Support Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Enables Unicode support for all projects by defining specific preprocessor macros. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Include Flutter Subdirectory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Includes the Flutter build rules from the specified managed directory. ```cmake add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### CMake Policy Opt-in Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Find and Link ALSA Dependency Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Finds the ALSA development libraries required for volume control. If found, it sets up include directories and links the libraries. If not found, it causes a fatal error. ```cmake find_package(ALSA REQUIRED) if (ALSA_FOUND) message(STATUS "ALSA found: ${ALSA_LIBRARIES}") target_include_directories(${PLUGIN_NAME} PRIVATE ${ALSA_INCLUDE_DIRS}) target_link_libraries(${PLUGIN_NAME} PRIVATE ${ALSA_LIBRARIES}) else() message(FATAL_ERROR "ALSA not found. Please install ALSA development libraries.") endif() ``` -------------------------------- ### Find GTK Package Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Finds the PkgConfig module and checks for the GTK+ 3.0 library, making its imported target available. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Build Configuration Types Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Configures the available build types (Debug, Profile, Release) based on whether the generator is multi-configuration. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() 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() endif() ``` -------------------------------- ### Define Executable Target Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable target for the application. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. Add all application source files here. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, 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. add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Defines a function to apply standard compilation features, options, and definitions to a target. It enables C++14, sets Wall and Werror, applies optimization for non-Debug builds, and defines NDEBUG for non-Debug builds. ```cmake 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 "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Define Executable and Application IDs Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Sets the name of the executable and the unique GTK application identifier for the application. ```cmake set(BINARY_NAME "volume_controller_example") set(APPLICATION_ID "com.kurenai7968.volume_controller") ``` -------------------------------- ### GetVolume Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Retrieves the current system volume level. The returned value is a double representing the volume, typically in the range of 0.0 to 1.0. ```APIDOC ## GetVolume ### Description Get the current system volume. ### Method GET (conceptual) ### Endpoint N/A (This is a method call) ### Returns - **volume** (double) - The current system volume level, usually between 0.0 and 1.0. ### Request Example ```dart double volume = await VolumeController.instance.getVolume(); ``` ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Specifies the minimum required CMake version and defines the project name and languages. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) ``` -------------------------------- ### SetVolume Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Adjusts the system volume to a specified level. The input value must be a double between 0.0 and 1.0, inclusive. ```APIDOC ## SetVolume ### Description Set the system volume. ### Method POST (conceptual) ### Endpoint N/A (This is a method call) ### Parameters - **volume** (double) - Required - The desired volume level, must be between 0.0 and 1.0. ### Request Example ```dart await VolumeController.instance.setVolume(0.75); ``` ``` -------------------------------- ### Add Runner Subdirectory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Includes the CMake build rules for the application runner from the 'runner' subdirectory. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Set Runtime Output Directory for Executable Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Configures the executable's runtime output directory to a specific subdirectory to prevent running unbundled copies. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Show or Hide System Volume UI Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Control the visibility of the system's volume user interface. This feature is supported on Android and iOS only. The default value is true. ```dart VolumeController.instance.showSystemUI = true; ``` -------------------------------- ### Flutter Managed Directory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Sets the path to the Flutter managed directory, typically containing Flutter's build system files. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") ``` -------------------------------- ### Plugin Name Definition Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Sets the name of the plugin library. This name must not be changed as it's used during the build process. ```cmake set(PLUGIN_NAME "volume_controller_plugin") ``` -------------------------------- ### Include Flutter Managed Directory Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Loads Flutter managed libraries from the 'flutter' directory relative to the current source directory. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Add Flutter Version Preprocessor Definitions Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/runner/CMakeLists.txt Adds preprocessor definitions for the Flutter build version components. These are useful for conditional compilation based on the Flutter version. ```cmake # Add preprocessor definitions for the build version. target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Define list_prepend CMake Function Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/flutter/CMakeLists.txt This CMake function prepends a prefix to each element in a given list. It is used as a workaround for versions of CMake older than 3.10 which do not support `list(TRANSFORM ... PREPEND ...)`. Ensure the list variable is correctly set before calling this function. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Executable Binary Name Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/CMakeLists.txt Defines the name of the executable file for the application. This can be changed to alter the on-disk name. ```cmake set(BINARY_NAME "volume_controller_example") ``` -------------------------------- ### Define Plugin Library Target Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Defines the shared library target for the plugin. The name must match PLUGIN_NAME. Standard build settings are applied. ```cmake add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SOURCES} ) apply_standard_settings(${PLUGIN_NAME}) ``` -------------------------------- ### Set System Volume Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Adjust the system volume to a specific level. The input value must be between 0.0 and 1.0. ```dart await VolumeController.instance.setVolume(double volume); ``` -------------------------------- ### Define Plugin Library Target Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Defines the shared library target for the plugin. The name must match PLUGIN_NAME. It includes C API headers and plugin sources. ```cmake add_library(${PLUGIN_NAME} SHARED "include/volume_controller/volume_controller_plugin_c_api.h" "volume_controller_plugin_c_api.cpp" ${PLUGIN_SOURCES} ) ``` -------------------------------- ### Define Flutter Library Interface Target Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/flutter/CMakeLists.txt Creates an interface library target for Flutter, setting include directories and linking against the Flutter library. It also adds a dependency on flutter_assemble. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/kurenai7968/volume_controller/blob/master/windows/CMakeLists.txt Specifies the minimum required CMake version for the project. Ensure this version is compatible with the Flutter tooling. ```cmake cmake_minimum_required(VERSION 3.14) ``` -------------------------------- ### Configure Symbol Visibility and Definitions Source: https://github.com/kurenai7968/volume_controller/blob/master/linux/CMakeLists.txt Hides symbols by default to prevent conflicts. Explicitly export symbols intended for external use with FLUTTER_PLUGIN_EXPORT. Defines FLUTTER_PLUGIN_IMPL for plugin implementation. ```cmake set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) ``` -------------------------------- ### Create Flutter Assemble Custom Target Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/flutter/CMakeLists.txt Defines a custom target named 'flutter_assemble' that depends on the Flutter library, its headers, and all C++ wrapper sources. This target ensures these components are built. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Add Dependency on Flutter Assemble Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Ensures that the application executable depends on the Flutter assemble target, which is necessary for building. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Set Default Build Type Source: https://github.com/kurenai7968/volume_controller/blob/master/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already configured, and restricts it to valid Flutter build modes. ```cmake 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() ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/kurenai7968/volume_controller/blob/master/example/windows/runner/CMakeLists.txt Disables Windows-specific macros like NOMINMAX that can conflict with C++ standard library functions, preventing potential compilation errors. ```cmake # Disable Windows macros that collide with C++ standard library functions. target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Mute or Unmute System Volume Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Control the mute state of the system volume. On Android and iOS, this action sets the volume to 0 or restores the previously saved volume. ```dart await VolumeController.instance.setMute(bool mute); ``` -------------------------------- ### Remove Volume Listener Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Deregister the currently active system volume change listener. ```dart VolumeController.instance.removeListener(); ``` -------------------------------- ### Check if System is Muted Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Determine if the system volume is currently muted. On Android and iOS, a volume level of 0 is considered muted. ```dart bool isMuted = await VolumeController.instance.isMuted(); ``` -------------------------------- ### SetMute Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Mutes or unmutes the system volume. On Android and iOS, this action sets the volume to 0 when muting and restores the previously saved volume level when unmuting. ```APIDOC ## SetMute ### Description Mute or unmute the system volume. On iOS and Android, this sets the volume level to `0` and restores the previous volume level when unmuted. ### Method POST (conceptual) ### Endpoint N/A (This is a method call) ### Parameters - **mute** (boolean) - Required - Set to `true` to mute the volume, `false` to unmute. ### Request Example ```dart await VolumeController.instance.setMute(true); ``` ``` -------------------------------- ### IsMuted Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Determines if the system volume is currently muted. On Android and iOS, a volume level of 0 is considered muted. ```APIDOC ## IsMuted ### Description Check whether the system is muted. On iOS and Android, this checks whether the volume level is `0`. ### Method GET (conceptual) ### Endpoint N/A (This is a method call) ### Returns - **isMuted** (boolean) - `true` if the system is muted, `false` otherwise. ### Request Example ```dart bool isMuted = await VolumeController.instance.isMuted(); ``` ``` -------------------------------- ### RemoveListener Source: https://github.com/kurenai7968/volume_controller/blob/master/README.md Deregisters the currently active volume change listener, stopping further callbacks. ```APIDOC ## RemoveListener ### Description Remove the volume listener. ### Method DELETE (conceptual) ### Endpoint N/A (This is a method call) ### Request Example ```dart VolumeController.instance.removeListener(); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.