Skip to content

Commit de938f3

Browse files
committed
build: use target_sources instead of custom lists
Use the target_sources function to add additional sources to the dispatch target rather than managing lists. This simplifies the handling and modernises the CMake usage.
1 parent c87c6bb commit de938f3

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

src/CMakeLists.txt

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,6 @@
11

22
include(SwiftSupport)
33

4-
set(dispatch_BLOCK_SOURCES block.cpp)
5-
if(HAVE_OBJC)
6-
list(APPEND dispatch_BLOCK_SOURCES data.m object.m)
7-
endif()
8-
set(dispatch_SWIFT_SOURCES)
9-
if(CMAKE_SWIFT_COMPILER)
10-
set(swift_optimization_flags)
11-
if(CMAKE_BUILD_TYPE MATCHES Release)
12-
set(swift_optimization_flags -O)
13-
endif()
14-
add_swift_library(swiftDispatch
15-
MODULE_NAME
16-
Dispatch
17-
MODULE_LINK_NAME
18-
dispatch
19-
MODULE_PATH
20-
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
21-
OUTPUT
22-
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
23-
SOURCES
24-
swift/Block.swift
25-
swift/Data.swift
26-
swift/Dispatch.swift
27-
swift/IO.swift
28-
swift/Private.swift
29-
swift/Queue.swift
30-
swift/Source.swift
31-
swift/Time.swift
32-
swift/Wrapper.swift
33-
CFLAGS
34-
-fblocks
35-
-fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
36-
SWIFT_FLAGS
37-
-I ${CMAKE_SOURCE_DIR}
38-
${swift_optimization_flags})
39-
list(APPEND dispatch_SWIFT_SOURCES
40-
swift/DispatchStubs.cc;${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
41-
endif()
424
add_library(dispatch
435
allocator.c
446
apply.c
@@ -90,9 +52,51 @@ add_library(dispatch
9052
shims/perfmon.h
9153
shims/time.h
9254
shims/tsd.h
93-
shims/yield.h
94-
${dispatch_BLOCK_SOURCES}
95-
${dispatch_SWIFT_SOURCES})
55+
shims/yield.h)
56+
target_sources(dispatch
57+
PRIVATE
58+
block.cpp)
59+
if(HAVE_OBJC)
60+
target_sources(dispatch
61+
PRIVATE
62+
data.m
63+
object.m)
64+
endif()
65+
if(CMAKE_SWIFT_COMPILER)
66+
set(swift_optimization_flags)
67+
if(CMAKE_BUILD_TYPE MATCHES Release)
68+
set(swift_optimization_flags -O)
69+
endif()
70+
add_swift_library(swiftDispatch
71+
MODULE_NAME
72+
Dispatch
73+
MODULE_LINK_NAME
74+
dispatch
75+
MODULE_PATH
76+
${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
77+
OUTPUT
78+
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o
79+
SOURCES
80+
swift/Block.swift
81+
swift/Data.swift
82+
swift/Dispatch.swift
83+
swift/IO.swift
84+
swift/Private.swift
85+
swift/Queue.swift
86+
swift/Source.swift
87+
swift/Time.swift
88+
swift/Wrapper.swift
89+
CFLAGS
90+
-fblocks
91+
-fmodule-map-file=${CMAKE_SOURCE_DIR}/dispatch/module.modulemap
92+
SWIFT_FLAGS
93+
-I ${CMAKE_SOURCE_DIR}
94+
${swift_optimization_flags})
95+
target_sources(dispatch
96+
PRIVATE
97+
swift/DispatchStubs.cc
98+
${CMAKE_CURRENT_BINARY_DIR}/swiftDispatch.o)
99+
endif()
96100
target_include_directories(dispatch
97101
PRIVATE
98102
${CMAKE_BINARY_DIR}

0 commit comments

Comments
 (0)