flutter plugin for zebra multiplatform sdk

CMakeLists.txt 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # The Flutter tooling requires that developers have a version of Visual Studio
  2. # installed that includes CMake 3.14 or later. You should not increase this
  3. # version, as doing so will cause the plugin to fail to compile for some
  4. # customers of the plugin.
  5. cmake_minimum_required(VERSION 3.14)
  6. # Project-level configuration.
  7. set(PROJECT_NAME "flutter_zsdk")
  8. project(${PROJECT_NAME} LANGUAGES CXX)
  9. # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
  10. # versions of CMake.
  11. cmake_policy(VERSION 3.14...3.25)
  12. # This value is used when generating builds using this plugin, so it must
  13. # not be changed
  14. set(PLUGIN_NAME "flutter_zsdk_plugin")
  15. # Any new source files that you add to the plugin should be added here.
  16. list(APPEND PLUGIN_SOURCES
  17. "flutter_zsdk_plugin.cpp"
  18. "flutter_zsdk_plugin.h"
  19. )
  20. # Define the plugin library target. Its name must not be changed (see comment
  21. # on PLUGIN_NAME above).
  22. add_library(${PLUGIN_NAME} SHARED
  23. "include/flutter_zsdk/flutter_zsdk_plugin_c_api.h"
  24. "flutter_zsdk_plugin_c_api.cpp"
  25. ${PLUGIN_SOURCES}
  26. )
  27. # Apply a standard set of build settings that are configured in the
  28. # application-level CMakeLists.txt. This can be removed for plugins that want
  29. # full control over build settings.
  30. apply_standard_settings(${PLUGIN_NAME})
  31. # Symbols are hidden by default to reduce the chance of accidental conflicts
  32. # between plugins. This should not be removed; any symbols that should be
  33. # exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
  34. set_target_properties(${PLUGIN_NAME} PROPERTIES
  35. CXX_VISIBILITY_PRESET hidden)
  36. target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
  37. # Source include directories and library dependencies. Add any plugin-specific
  38. # dependencies here.
  39. target_include_directories(${PLUGIN_NAME} INTERFACE
  40. "${CMAKE_CURRENT_SOURCE_DIR}/include")
  41. target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
  42. # List of absolute paths to libraries that should be bundled with the plugin.
  43. # This list could contain prebuilt libraries, or libraries created by an
  44. # external build triggered from this build file.
  45. set(flutter_zsdk_bundled_libraries
  46. ""
  47. PARENT_SCOPE
  48. )
  49. # === Tests ===
  50. # These unit tests can be run from a terminal after building the example, or
  51. # from Visual Studio after opening the generated solution file.
  52. # Only enable test builds when building the example (which sets this variable)
  53. # so that plugin clients aren't building the tests.
  54. if (${include_${PROJECT_NAME}_tests})
  55. set(TEST_RUNNER "${PROJECT_NAME}_test")
  56. enable_testing()
  57. # Add the Google Test dependency.
  58. include(FetchContent)
  59. FetchContent_Declare(
  60. googletest
  61. URL https://github.com/google/googletest/archive/release-1.11.0.zip
  62. )
  63. # Prevent overriding the parent project's compiler/linker settings
  64. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  65. # Disable install commands for gtest so it doesn't end up in the bundle.
  66. set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE)
  67. FetchContent_MakeAvailable(googletest)
  68. # The plugin's C API is not very useful for unit testing, so build the sources
  69. # directly into the test binary rather than using the DLL.
  70. add_executable(${TEST_RUNNER}
  71. test/flutter_zsdk_plugin_test.cpp
  72. ${PLUGIN_SOURCES}
  73. )
  74. apply_standard_settings(${TEST_RUNNER})
  75. target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
  76. target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin)
  77. target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock)
  78. # flutter_wrapper_plugin has link dependencies on the Flutter DLL.
  79. add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD
  80. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  81. "${FLUTTER_LIBRARY}" $<TARGET_FILE_DIR:${TEST_RUNNER}>
  82. )
  83. # Enable automatic test discovery.
  84. include(GoogleTest)
  85. gtest_discover_tests(${TEST_RUNNER})
  86. endif()