/ app / packages / ble_peripheral / windows / CMakeLists.txt
CMakeLists.txt
 1  cmake_minimum_required(VERSION 3.21)
 2  set(PROJECT_NAME "ble_peripheral")
 3  project(${PROJECT_NAME} LANGUAGES CXX)
 4  cmake_policy(VERSION 3.14...3.25)
 5  include(FetchContent)
 6  set(CPPWINRT_VERSION "2.0.220418.1")
 7  set(PLUGIN_NAME "ble_peripheral_plugin")
 8  
 9  # ############### NuGet intall begin ################
10  FetchContent_Declare(nuget
11    URL "https://dist.nuget.org/win-x86-commandline/v6.0.0/nuget.exe"
12    URL_HASH SHA256=04eb6c4fe4213907e2773e1be1bbbd730e9a655a3c9c58387ce8d4a714a5b9e1
13    DOWNLOAD_NO_EXTRACT true
14  )
15  
16  find_program(NUGET nuget)
17  
18  if(NOT NUGET)
19    message("Nuget.exe not found, trying to download or use cached version.")
20    FetchContent_MakeAvailable(nuget)
21    set(NUGET ${nuget_SOURCE_DIR}/nuget.exe)
22  endif()
23  
24  execute_process(COMMAND
25    ${NUGET} install "Microsoft.Windows.CppWinRT" -Version ${CPPWINRT_VERSION} -OutputDirectory packages
26    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
27    RESULT_VARIABLE ret)
28  
29  if(NOT ret EQUAL 0)
30    message(FATAL_ERROR "Failed to install nuget package Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}")
31  endif()
32  
33  # ############### NuGet install end ################
34  list(APPEND PLUGIN_SOURCES
35    "Utils.cpp"
36    "Utils.h"
37    "BlePeripheral.g.cpp"
38    "BlePeripheral.g.h"
39    "ble_peripheral_plugin.cpp"
40    "ble_peripheral_plugin.h"
41    "ui_thread_handler.hpp"
42  )
43  
44  add_library(${PLUGIN_NAME} SHARED
45    "include/ble_peripheral/ble_peripheral_plugin_c_api.h"
46    "ble_peripheral_plugin_c_api.cpp"
47    ${PLUGIN_SOURCES}
48  )
49  
50  apply_standard_settings(${PLUGIN_NAME})
51  
52  # ############### NuGet import begin ################
53  set_target_properties(${PLUGIN_NAME} PROPERTIES VS_PROJECT_IMPORT
54    ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}/build/native/Microsoft.Windows.CppWinRT.props
55  )
56  
57  target_link_libraries(${PLUGIN_NAME} PRIVATE
58    ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT.${CPPWINRT_VERSION}/build/native/Microsoft.Windows.CppWinRT.targets
59  )
60  
61  # ############### NuGet import end ################
62  set_target_properties(${PLUGIN_NAME} PROPERTIES
63    CXX_VISIBILITY_PRESET hidden)
64  target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
65  
66  target_include_directories(${PLUGIN_NAME} INTERFACE
67    "${CMAKE_CURRENT_SOURCE_DIR}/include")
68  target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
69  
70  set(ble_peripheral_bundled_libraries
71    ""
72    PARENT_SCOPE
73  )