xcodebuild.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright 2017 Google
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. include(CMakeParseArguments)
  15. include(ExternalProject)
  16. # Builds an existing Xcode project or workspace as an external project in CMake.
  17. #
  18. # xcodebuild(<framework> [<option>...])
  19. #
  20. # Options:
  21. # ``DEPENDS <projects>...``
  22. # Targets on which the project depends
  23. # ``SCHEME <scheme>``
  24. # The scheme to build in the workspace, defaults to <framework>-<platform>,
  25. # where <platform> is always "macOS".
  26. # ``WORKSPACE <workspace>``
  27. # Location of the xcworkspace file containing the target to build. Defaults to
  28. # Example/Firebase.xcworkspace.
  29. function(xcodebuild framework)
  30. # Parse arguments
  31. set(options "")
  32. set(single_value SCHEME WORKSPACE)
  33. set(multi_value DEPENDS)
  34. cmake_parse_arguments(xcb "${options}" "${single_value}" "${multi_value}" ${ARGN})
  35. if(NOT xcb_WORKSPACE)
  36. set(xcb_WORKSPACE ${PROJECT_SOURCE_DIR}/Example/Firebase.xcworkspace)
  37. endif()
  38. # TODO(mcg): Investigate supporting non-macOS platforms
  39. # The canonical way to build and test for iOS is via Xcode and CocoaPods so
  40. # it's not super important to make this work here
  41. set(platform macOS)
  42. set(destination "platform=macOS,arch=x86_64")
  43. set(scheme "${framework}-${platform}")
  44. # CMake has a variety of release types, but Xcode has just one by default.
  45. if(CMAKE_BUILD_TYPE STREQUAL Debug)
  46. set(configuration Debug)
  47. else()
  48. set(configuration Release)
  49. endif()
  50. # Pipe build output through xcpretty if it's available
  51. find_program(xcpretty_cmd xcpretty)
  52. if(xcpretty_cmd)
  53. set(pipe_xcpretty "|" ${xcpretty_cmd})
  54. endif()
  55. ExternalProject_Add(
  56. ${framework}
  57. DEPENDS ${xcb_DEPENDS}
  58. PREFIX ${PROJECT_BINARY_DIR}/external/${framework}
  59. # The source directory doesn't actually matter
  60. SOURCE_DIR ${PROJECT_SOURCE_DIR}
  61. BINARY_DIR ${PROJECT_BINARY_DIR}/Frameworks
  62. CONFIGURE_COMMAND ""
  63. BUILD_COMMAND
  64. xcodebuild
  65. -workspace ${xcb_WORKSPACE}
  66. -scheme ${scheme}
  67. -configuration ${configuration}
  68. -destination ${destination}
  69. CONFIGURATION_BUILD_DIR=<BINARY_DIR>
  70. build
  71. ${pipe_xcpretty}
  72. BUILD_ALWAYS ${BUILD_PODS}
  73. INSTALL_COMMAND ""
  74. TEST_COMMAND ""
  75. )
  76. endfunction()