CMakeLists.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # This will create a Windows Runtime Component that can be consumed by any WinRT or UWP project.
  3. # You need to specify -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 at command line
  4. # to generate correctly UWP projects. You can also use Toolchain-Win10.cmake as tool chain file
  5. # which defined these for you.
  6. #
  7. # You can add EXTENSION_SDK_OUTPUT variable to deploy the build as UWP Extension SDK
  8. # e.g. -DEXTENSION_SDK_OUTPUT:STRING=<path_to_folder_parent_of_SDKManifest.xml>
  9. #
  10. cmake_minimum_required (VERSION 3.14)
  11. project (ZXingWinRT)
  12. set (CMAKE_CONFIGURATION_TYPES "RelWithDebInfo;Release" CACHE STRING "" FORCE)
  13. set (WINRT ON)
  14. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO" )
  15. add_definitions (-DUNICODE -D_UNICODE)
  16. if (MSVC)
  17. add_definitions (
  18. -DNOMINMAX -wd4996
  19. )
  20. endif()
  21. include(TargetArch.cmake)
  22. get_target_architecture (TARGET_ARCHITECTURE)
  23. set (TARGET_ARCHITECTURE ${TARGET_ARCHITECTURE} CACHE INTERNAL "")
  24. message (STATUS "Building for " ${TARGET_ARCHITECTURE})
  25. if (NOT DEFINED EXTENSION_SDK_OUTPUT)
  26. set (EXTENSION_SDK_OUTPUT "" CACHE PATH "Path to folder parent of SDKManifest")
  27. endif()
  28. add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/../../core ${CMAKE_BINARY_DIR}/ZXingCore)
  29. file (GLOB SOURCE_FILES *.cpp)
  30. file (GLOB HEADER_FILES *.h)
  31. set (ROOT_NAMESPACE "ZXing")
  32. set (OUTPUT_FILE_BASE_NAME "ZXing")
  33. add_library (ZXingWinRT SHARED ${HEADER_FILES} ${SOURCE_FILES})
  34. target_link_libraries (ZXingWinRT
  35. PRIVATE ZXing::ZXing
  36. )
  37. target_compile_options (ZXingWinRT PRIVATE
  38. -D_WINRT_DLL
  39. -ZW # Consume Windows Runtime Extension
  40. )
  41. set_target_properties (ZXingWinRT PROPERTIES
  42. LINK_FLAGS "/WINMD" # Generate Windows Metadata
  43. VS_GLOBAL_ROOTNAMESPACE "${ROOT_NAMESPACE}"
  44. OUTPUT_NAME ${OUTPUT_FILE_BASE_NAME}
  45. )
  46. set_target_properties (ZXingWinRT ZXing PROPERTIES
  47. VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "10.0.10240.0"
  48. )
  49. if (EXTENSION_SDK_OUTPUT)
  50. add_custom_command (TARGET ZXingWinRT POST_BUILD
  51. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different "$<TARGET_FILE:ZXingWinRT>" "${EXTENSION_SDK_OUTPUT}/Redist/$<$<CONFIG:Release>:Retail>$<$<CONFIG:RelWithDebInfo>:Debug>/${TARGET_ARCHITECTURE}/$<TARGET_FILE_NAME:ZXingWinRT>"
  52. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different "$<TARGET_FILE_DIR:ZXingWinRT>/${ROOT_NAMESPACE}.winmd" "${EXTENSION_SDK_OUTPUT}/References/CommonConfiguration/Neutral/${ROOT_NAMESPACE}.winmd"
  53. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different "$<TARGET_FILE_DIR:ZXingWinRT>/${ROOT_NAMESPACE}.pri" "${EXTENSION_SDK_OUTPUT}/References/CommonConfiguration/Neutral/${ROOT_NAMESPACE}.pri"
  54. )
  55. endif()