summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/XcodeProject-Embed/RunCMakeTest.cmake
blob: 26749cd5c98e317110df3c614bd78b860af20197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
include(RunCMake)

# Build dependencies that the other tests will use and treat as external.
# Always build in the Debug configuration so that the path to the framework
# is predictable.
function(ExternalDependencies)
  set(RunCMake_TEST_NO_CLEAN 1)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExternalDependencies-build)
  set(externalFramework ${RunCMake_TEST_BINARY_DIR}/Debug/sharedFrameworkExt.framework PARENT_SCOPE)
  set(externalDylib ${RunCMake_TEST_BINARY_DIR}/Debug/libsharedDylibExt.dylib PARENT_SCOPE)

  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")

  run_cmake(ExternalDependencies)
  run_cmake_command(ExternalDependencies-build
    ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
                     --config Debug
                     --target sharedFrameworkExt sharedDylibExt
  )
endfunction()
ExternalDependencies()

function(TestFlagsOn testName dependencyName)
  set(RunCMake_TEST_NO_CLEAN 1)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-${dependencyName}-build)

  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")

  run_cmake(${testName})
  run_cmake_command(${testName}-${dependencyName}-build
    ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
                     --config Debug
                     --target app
  )
endfunction()

foreach(dependency ${externalFramework} ${externalDylib})
  cmake_path(GET dependency FILENAME dependencyName)
  set(RunCMake_TEST_OPTIONS -DEXTERNAL_DEPENDENCY=${dependency} -DEXTERNAL_DEPENDENCY_NAME=${dependencyName})
  run_cmake(EmbedFrameworksFlagsOff)
  TestFlagsOn(EmbedFrameworksFlagsOnNoSubdir ${dependencyName})
  TestFlagsOn(EmbedFrameworksFlagsOnWithSubdir ${dependencyName})
endforeach()
unset(RunCMake_TEST_OPTIONS)

block()
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/EmbedFrameworksFlagsOffAndOn-build)
  run_cmake(EmbedFrameworksFlagsOffAndOn)
  set(RunCMake_TEST_NO_CLEAN 1)
  run_cmake_command(EmbedFrameworksFlagsOffAndOn-build
    ${CMAKE_COMMAND} --build .
                     --config Debug
                     --target app1
                     --target app2
  )
endblock()

function(TestAppExtension platform)
  set(testName EmbedAppExtensions-${platform})
  if(NOT platform STREQUAL "macOS")
    set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform})
  endif()
  set(RunCMake_TEST_NO_CLEAN 1)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)

  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")

  run_cmake(${testName})
  run_cmake_command(${testName}-build
    ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
                     --config Debug
                     --target app
  )
endfunction()

function(TestExtensionKitExtension platform)
  set(testName EmbedExtensionKitExtensions-${platform})
  if(NOT platform STREQUAL "macOS")
    set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform})
  endif()
  set(RunCMake_TEST_NO_CLEAN 1)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)

  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")

  run_cmake(${testName})
  run_cmake_command(${testName}-build
    ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
                     --config Debug
                     --target app
  )
endfunction()

function(TestEmbedCommon what platform)
  set(testName Embed${what}-${platform})
  if(NOT platform STREQUAL "macOS")
    set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform})
  endif()
  set(RunCMake_TEST_NO_CLEAN 1)
  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)

  file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")

  run_cmake(${testName})
  run_cmake_command(${testName}-build
    ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR}
                     --config Debug
                     --target app
  )
endfunction()

# Isolate device tests from host architecture selection.
unset(ENV{CMAKE_OSX_ARCHITECTURES})

if(XCODE_VERSION VERSION_GREATER_EQUAL 8)
  # The various flag on/off combinations are tested by the EmbedFrameworks...
  # tests, so we don't duplicate all the combinations here. We only verify the
  # defaults, which is to remove headers on copy, but not code sign.
  TestAppExtension(macOS)
  TestAppExtension(iOS)
endif()

if(XCODE_VERSION VERSION_GREATER_EQUAL 14.1)
  # The various flag on/off combinations are tested by the EmbedFrameworks...
  # tests, so we don't duplicate all the combinations here. We only verify the
  # defaults, which is to remove headers on copy, but not code sign.
  TestAppExtension(macOS)
  TestAppExtension(iOS)
  TestEmbedCommon(Resources macOS)
  TestEmbedCommon(Resources iOS)
  TestEmbedCommon(PlugIns macOS)
  TestEmbedCommon(XPCServices macOS)
endif()