-
Notifications
You must be signed in to change notification settings - Fork 0
/
SA_TargetSources.cmake
236 lines (179 loc) · 5.08 KB
/
SA_TargetSources.cmake
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Copyright (c) 2023 Sapphire's Suite. All Rights Reserved.
# Add *public* sources and include directory to a target (using target_sources and target_include_directories).
#
# USAGE:
# SA_TargetPublicSources(
# <target>
# SRC_DIR <public_src_dir>
# INCL_DIR <public_include_dir>
# )
#
# ARGUMENTS:
# TARGET
# Name of the cmake target.
#
# SRC_DIR
# Public source folder.
# Default is "Include/SA/<module_name>".
#
# INCL_DIR
# Public include directory.
# Path used from outside target to access include directory.
# Default is "Include"
function(SA_TargetPublicSources _target)
#{ Args
cmake_parse_arguments(
PARGS
""
"SRC_DIR;INCL_DIR"
""
${ARGN}
)
# Remove SA_ from target name to get folder name.
string(REPLACE "SA_" "" MODULE_NAME ${_target})
# Default "Include/SA/<module_name>".
if(NOT PARGS_SRC_DIR)
set(PARGS_SRC_DIR "Include/SA/${MODULE_NAME}")
endif()
# Default "Include".
if(NOT PARGS_INCL_DIR)
set(PARGS_INCL_DIR Include)
endif()
#}
file(GLOB_RECURSE SA_SOURCES_PUBLIC "${PARGS_SRC_DIR}/*.hpp")
message(VERBOSE "[SA] ${_target} public sources: ${SA_SOURCES_PUBLIC}")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/${PARGS_SRC_DIR}" PREFIX Public FILES ${SA_SOURCES_PUBLIC})
target_sources(${_target} PUBLIC ${SA_SOURCES_PUBLIC})
## Include directories
if(NOT "${PARGS_INCL_DIR}" STREQUAL "OFF")
# Public include directory (access from project's outside).
target_include_directories(${_target} PUBLIC ${PARGS_INCL_DIR})
endif()
# Private include directory (access from project's inside).
target_include_directories(${_target} PRIVATE ${PARGS_SRC_DIR})
endfunction(SA_TargetPublicSources)
# Add *private* sources and include directory to a target (using target_sources and target_include_directories).
#
# USAGE:
# SA_TargetPrivateSources(
# <target>
# SRC_DIR <private_src_dir>
# )
#
# ARGUMENTS:
# TARGET
# Name of the cmake target.
#
# SRC_DIR
# Private source folder.
# Default is "Source/SA/<module_name>".
function(SA_TargetPrivateSources _target)
#{ Args
cmake_parse_arguments(
PARGS
""
"SRC_DIR"
""
${ARGN}
)
# Remove SA_ from target name to get folder name.
string(REPLACE "SA_" "" MODULE_NAME ${_target})
# Default "Source/SA/<module_name>".
if(NOT PARGS_SRC_DIR)
set(PARGS_SRC_DIR "Source/SA/${MODULE_NAME}")
endif()
#}
file(GLOB_RECURSE SA_SOURCES_PRIVATE "${PARGS_SRC_DIR}/*.hpp" "${PARGS_SRC_DIR}/*.cpp")
message(VERBOSE "[SA] ${_target} private sources: ${SA_SOURCES_PRIVATE}")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/${PARGS_SRC_DIR}" PREFIX Private FILES ${SA_SOURCES_PRIVATE})
target_sources(${_target} PRIVATE ${SA_SOURCES_PRIVATE})
endfunction(SA_TargetPrivateSources)
# Add *interface* sources and include directory to a target (using target_sources and target_include_directories).
#
# USAGE:
# SA_TargetInterfaceSources(
# <target>
# SRC_DIR <interface_src_folder>
# INCL_DIR <public_include_dir>
# )
#
# ARGUMENTS:
# TARGET
# Name of the cmake target.
#
# SRC_DIR
# Interface source folder.
# Default is "Include/SA/<module_name>".
#
# INCL_DIR
# Interface include directory.
# Path used from outside target to access include directory.
# Default is "Include"
function(SA_TargetInterfaceSources _target)
#{ Args
cmake_parse_arguments(
PARGS
""
"SRC_DIR;INCL_DIR"
""
${ARGN}
)
# Remove SA_ from target name to get folder name.
string(REPLACE "SA_" "" MODULE_NAME ${_target})
# Default "Include/SA/<module_name>".
if(NOT PARGS_SRC_DIR)
set(PARGS_SRC_DIR "Include/SA/${MODULE_NAME}")
endif()
# Default "Include".
if(NOT PARGS_INCL_DIR)
set(PARGS_INCL_DIR Include)
endif()
#}
file(GLOB_RECURSE SA_SOURCES_INTERFACE "${PARGS_SRC_DIR}/*.hpp")
message(VERBOSE "[SA] ${_target} interface sources: ${SA_SOURCES_INTERFACE}")
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/${PARGS_SRC_DIR}" PREFIX Public FILES ${SA_SOURCES_INTERFACE})
target_sources(${_target} INTERFACE ${SA_SOURCES_INTERFACE})
## Include directories
if(NOT "${PARGS_INCL_DIR}" STREQUAL "OFF")
# Interface include directory (access from project's outside).
target_include_directories(${_target} INTERFACE ${PARGS_INCL_DIR})
endif()
endfunction(SA_TargetInterfaceSources)
# Add sources and include directories to a target (using target_sources and target_include_directories).
#
# USAGE:
# SA_TargetSources(
# <target>
# PUBLIC_SRC_DIR <public_folder>
# PUBLIC_INCL_DIR <public_folder>
# PRIVATE_SRC_DIR <private_folder>
# )
#
# ARGUMENTS:
# TARGET
# Name of the cmake target.
#
# PUBLIC_SRC_DIR
# Public source directory.
# Default is "Include/SA/<module_name>".
#
# PUBLIC_INCL_DIR
# Public include directory.
# Default is "Include/"
#
# PRIVATE_SRC_DIR
# Private source directory.
# Default is "Source/SA/<module_name>".
function(SA_TargetSources _target)
#{ Args
cmake_parse_arguments(
PARGS
""
"PUBLIC_SRC_DIR;PUBLIC_INCL_DIR;PRIVATE_SRC_DIR"
""
${ARGN}
)
#}
SA_TargetPublicSources(${_target} SRC_DIR ${PARGS_PUBLIC_SRC_DIR} INCL_DIR ${PARGS_PUBLIC_INCL_DIR})
SA_TargetPrivateSources(${_target} SRC_DIR ${PARGS_PRIVATE_SRC_DIR})
endfunction(SA_TargetSources)