Skip to content

Commit 039d8fa

Browse files
committed
refactor
1 parent 9164f7e commit 039d8fa

File tree

2 files changed

+52
-58
lines changed

2 files changed

+52
-58
lines changed

SwiftTargets.cmake

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ define_property(TARGET
156156
BRIEF_DOCS "Swift target type"
157157
FULL_DOCS "For use by other modules in this repository which need to know the classification of target. One of executable, library, tool, tool_library, test, test_library")
158158

159+
define_property(TARGET
160+
PROPERTY INTERFACE_SWIFT_TYPE
161+
BRIEF_DOCS "Swift target type"
162+
FULL_DOCS "Identical use as SWIFT_TYPE except that this applies to ALL target types, including INTERFACE")
163+
164+
define_property(TARGET
165+
PROPERTY SWIFT_PROJECT
166+
BRIEF_DOCS "Swift project name"
167+
FULL_DOCS "For use by other modules in this repository which need to know the project which this target belongs to")
168+
169+
define_property(TARGET
170+
PROPERTY INTERFACE_SWIFT_PROJECT
171+
BRIEF_DOCS "Swift project name"
172+
FULL_DOCS "Identical use as SWIFT_PROJECT except that this applies to ALL target types, including INTERFACE")
173+
174+
define_property(TARGET
175+
PROPERTY SWIFT_TEST_TYPE
176+
BRIEF_DOCS "Swift test type"
177+
FULL_DOCS "When target's SWIFT_PROJECT property is \"test\", this option, if set, will identify what type of test it is. Currently support \"unit\" or \"integration\"")
178+
159179
macro(swift_collate_arguments prefix name)
160180
set(exclusion_list ${ARGN})
161181
set(${name}_args "")
@@ -257,13 +277,6 @@ function(swift_add_target target type)
257277
if (type STREQUAL "executable")
258278
add_executable(${target} ${x_SOURCES})
259279
list(APPEND extra_flags -pedantic)
260-
261-
get_property(targets GLOBAL PROPERTY SWIFT_EXECUTABLE_TARGETS)
262-
set_property(GLOBAL PROPERTY SWIFT_EXECUTABLE_TARGETS ${targets} ${target})
263-
set_target_properties(${target}
264-
PROPERTIES
265-
SWIFT_PROJECT ${PROJECT_NAME}
266-
)
267280
elseif(type STREQUAL "library")
268281
if (x_INTERFACE)
269282
add_library(${target} INTERFACE)
@@ -273,28 +286,6 @@ function(swift_add_target target type)
273286
add_library(${target} ${library_type} ${x_SOURCES})
274287
endif()
275288
list(APPEND extra_flags -pedantic)
276-
277-
get_property(targets GLOBAL PROPERTY SWIFT_LIBRARY_TARGETS)
278-
set_property(GLOBAL PROPERTY SWIFT_LIBRARY_TARGETS ${targets} ${target})
279-
280-
#
281-
# This edge case is needed for cmake version < 3.19.0 where INTERFACE
282-
# classes cannot contain any property other than those prefixed with
283-
# "INTERFACE_".
284-
#
285-
# see: https://stackoverflow.com/questions/68502038/custom-properties-for-interface-libraries
286-
#
287-
set_target_properties(${target}
288-
PROPERTIES
289-
INTERFACE_SWIFT_PROJECT ${PROJECT_NAME}
290-
)
291-
292-
if (NOT x_INTERFACE)
293-
set_target_properties(${target}
294-
PROPERTIES
295-
SWIFT_PROJECT ${PROJECT_NAME}
296-
)
297-
endif()
298289
elseif(type STREQUAL "test_library")
299290
if (x_INTERFACE)
300291
add_library(${target} INTERFACE)
@@ -303,28 +294,6 @@ function(swift_add_target target type)
303294
else()
304295
add_library(${target} ${library_type} ${x_SOURCES})
305296
endif()
306-
307-
get_property(targets GLOBAL PROPERTY SWIFT_TEST_TARGETS)
308-
set_property(GLOBAL PROPERTY SWIFT_TEST_TARGETS ${targets} ${target})
309-
310-
#
311-
# This edge case is needed for cmake version < 3.19.0 where INTERFACE
312-
# classes cannot contain any property other than those prefixed with
313-
# "INTERFACE_".
314-
#
315-
# see: https://stackoverflow.com/questions/68502038/custom-properties-for-interface-libraries
316-
#
317-
set_target_properties(${target}
318-
PROPERTIES
319-
INTERFACE_SWIFT_PROJECT ${PROJECT_NAME}
320-
)
321-
322-
if (NOT x_INTERFACE)
323-
set_target_properties(${target}
324-
PROPERTIES
325-
SWIFT_PROJECT ${PROJECT_NAME}
326-
)
327-
endif()
328297
elseif(type STREQUAL "tool")
329298
add_executable(${target} ${x_SOURCES})
330299
elseif(type STREQUAL "tool_library")
@@ -339,8 +308,31 @@ function(swift_add_target target type)
339308
message(FATAL_ERROR "Unknown Swift target type ${type}")
340309
endif()
341310

311+
#
312+
# This edge case is needed for cmake version < 3.19.0 where INTERFACE
313+
# classes cannot contain any property other than those prefixed with
314+
# "INTERFACE_".
315+
#
316+
# see: https://stackoverflow.com/questions/68502038/custom-properties-for-interface-libraries
317+
#
318+
# Until we migrate the cmake scripts to require 3.19.0, we should use the
319+
# "INTERFACE_*" properties. If you want to go the extra mile, make sure to
320+
# check both `INTERFACE_` and non `INTERFACE_` properties, later on we can
321+
# delete the `INTERFACE_` once this illogical constraint is removed.
322+
#
323+
set_target_properties(${target}
324+
PROPERTIES
325+
INTERFACE_SWIFT_PROJECT ${PROJECT_NAME}
326+
INTERFACE_SWIFT_TYPE ${type}
327+
)
328+
342329
if (NOT x_INTERFACE)
343-
set_target_properties(${target} PROPERTIES SWIFT_TYPE ${type})
330+
set_target_properties(${target}
331+
PROPERTIES
332+
SWIFT_PROJECT ${PROJECT_NAME}
333+
SWIFT_TYPE ${type}
334+
)
335+
344336
swift_set_language_standards(${target} ${language_standards_args})
345337
target_code_coverage(${target} NO_RUN)
346338

TestTargets.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,16 @@ function(swift_add_test target)
332332
add_dependencies(do-all-tests do-${target})
333333
endif()
334334

335+
set_target_properties(${target}
336+
PROPERTIES
337+
SWIFT_PROJECT ${PROJECT_NAME}
338+
INTERFACE_SWIFT_PROJECT ${PROJECT_NAME}
339+
)
340+
335341
if (x_INTEGRATION_TEST)
336-
get_property(targets GLOBAL PROPERTY SWIFT_INTEGRATION_TEST_TARGETS)
337-
set_property(GLOBAL PROPERTY SWIFT_INTEGRATION_TEST_TARGETS ${targets} ${target})
338342
set_target_properties(${target}
339343
PROPERTIES
340-
SWIFT_PROJECT ${PROJECT_NAME}
344+
SWIFT_TEST_TYPE integration
341345
)
342346

343347
if (NOT TARGET do-all-integration-tests)
@@ -352,11 +356,9 @@ function(swift_add_test target)
352356
endif()
353357

354358
if (x_UNIT_TEST)
355-
get_property(targets GLOBAL PROPERTY SWIFT_UNIT_TEST_TARGETS)
356-
set_property(GLOBAL PROPERTY SWIFT_UNIT_TEST_TARGETS ${targets} ${target})
357359
set_target_properties(${target}
358360
PROPERTIES
359-
SWIFT_PROJECT ${PROJECT_NAME}
361+
SWIFT_TEST_TYPE unit
360362
)
361363

362364
if (NOT TARGET do-all-unit-tests)

0 commit comments

Comments
 (0)