132
|
1 ##--------------------------------------------
|
|
2 ## Variables.
|
|
3 ##--------------------------------------------
|
|
4
|
|
5 ## Find D compiler and parsing its version.
|
166
|
6 find_program(DC NAMES dmd ldc)
|
132
|
7 if (DC)
|
|
8 get_filename_component(dc_path ${DC} PATH)
|
|
9 if("${dc_path}" STREQUAL ${CMAKE_BINARY_DIR})
|
|
10 get_filename_component(DC ${DC} NAME)
|
|
11 endif("${dc_path}" STREQUAL ${CMAKE_BINARY_DIR})
|
|
12 exec_program(${DC} ARGS "" OUTPUT_VARIABLE d_output)
|
|
13 string(REGEX MATCH "Digital Mars D Compiler v[0-9]\\.[0-9]+" dmd_version "${d_output}")
|
|
14 if (dmd_version)
|
|
15 set(D_IS_MARS true)
|
|
16 set(D_IS_DMD true)
|
|
17 set(D_COMPILER_NAME "Digital Mars D Compiler")
|
|
18 string(REGEX REPLACE "Digital Mars D Compiler v([0-9])\\.[0-9]+" "\\1" D_VERSION "${dmd_version}")
|
|
19 string(REGEX REPLACE "Digital Mars D Compiler v[0-9]\\.([0-9]+)" "\\1" D_FRONTEND "${dmd_version}")
|
|
20 else (dmd_version)
|
|
21 string(REGEX MATCH "LLVM-based D Compiler" is_ldc "${d_output}")
|
|
22 if (is_ldc)
|
|
23 exec_program(${DC} ARGS "--version" OUTPUT_VARIABLE d_output)
|
|
24 string(REGEX MATCH "based on DMD v[0-9]\\.[0-9]+" ldc_version "${d_output}")
|
|
25 set(D_IS_LLVM true)
|
|
26 set(D_IS_LDC true)
|
|
27 if(ldc_version)
|
|
28 set(D_IS_LLVM true)
|
|
29 set(D_COMPILER_NAME "LLVM-based D Compiler")
|
|
30 string(REGEX REPLACE "based on DMD v([0-9])\\.[0-9]+" "\\1" D_VERSION "${ldc_version}")
|
|
31 string(REGEX REPLACE "based on DMD v[0-9]\\.([0-9]+)" "\\1" D_FRONTEND "${ldc_version}")
|
|
32 else(ldc_version)
|
|
33 message(FATAL_ERROR "LDC compiler was found, but the version can not be processed")
|
|
34 endif(ldc_version)
|
|
35 else (is_ldc)
|
|
36 message(FATAL_ERROR "D compliler not found")
|
|
37 endif(is_ldc)
|
|
38 endif(dmd_version)
|
|
39 message(STATUS "D compiler found -- ${D_COMPILER_NAME} v${D_VERSION}.${D_FRONTEND}")
|
|
40 else (DC)
|
|
41 message(FATAL_ERROR "D compliler not found")
|
|
42 endif (DC)
|
|
43
|
|
44 ## Get D compiler path.
|
|
45 get_filename_component(DC_PATH ${DC} PATH)
|
|
46 if("${DC_PATH}" STREQUAL "")
|
|
47 find_program(dc_path_tmp ${DC})
|
|
48 get_filename_component(DC_PATH ${dc_path_tmp} PATH)
|
|
49 mark_as_advanced(dc_path_tmp)
|
|
50 endif("${DC_PATH}" STREQUAL "")
|
|
51 get_filename_component(dc_parent_dir ${DC_PATH} NAME)
|
|
52 if("${dc_parent_dir}" STREQUAL "bin")
|
|
53 get_filename_component(DC_PATH ${DC_PATH} PATH)
|
|
54 endif("${dc_parent_dir}" STREQUAL "bin")
|
|
55
|
|
56 #option(ONE_BUILD_COMMAND "Build in one command" "OFF")
|
|
57 set(ONE_BUILD_COMMAND OFF) ## TODO: test it and uncomment the previous line.
|
|
58
|
|
59 if (NOT ONE_BUILD_COMMAND)
|
|
60 ## TODO: disable SINGLE_D_OBJECT option for ldc < rev. 1433.
|
|
61 if(D_IS_MARS)
|
|
62 set(opt_tmp "ON")
|
|
63 else(D_IS_MARS)
|
|
64 set(opt_tmp "OFF")
|
|
65 endif(D_IS_MARS)
|
|
66 option(SINGLE_D_OBJECT "Build all d sources to one object file" ${opt_tmp})
|
|
67 if(SINGLE_D_OBJECT AND D_IS_LLVM)
|
|
68 set(D_FLAGS ${D_FLAGS} -singleobj)
|
|
69 endif(SINGLE_D_OBJECT AND D_IS_LLVM)
|
|
70 endif(NOT ONE_BUILD_COMMAND)
|
|
71
|
|
72 ## Specifics flags for build configurations.
|
|
73 ## TODO: Add another targets.
|
|
74 set(D_RELEASE_FLAGS -O -release)
|
139
|
75 set(D_DEBUG_FLAGS -g )
|
132
|
76 if(D_IS_LLVM)
|
|
77 set(D_RELEASE_FLAGS ${D_RELEASE_FLAGS} -enable-inlining)
|
139
|
78 set(D_DEBUG_FLAGS ${D_DEBUG_FLAGS} -d-debug)
|
132
|
79 else(D_IS_LLVM)
|
|
80 set(D_RELEASE_FLAGS ${D_RELEASE_FLAGS} -inline)
|
139
|
81 set(D_DEBUG_FLAGS ${D_DEBUG_FLAGS} -debug)
|
132
|
82 endif(D_IS_LLVM)
|
|
83 if(CMAKE_HOST_WIN32)
|
|
84 set(D_RELEASE_FLAGS ${D_RELEASE_FLAGS} -L/subsystem:windows)
|
|
85 endif(CMAKE_HOST_WIN32)
|
139
|
86
|
132
|
87
|
|
88 ## Settings.
|
|
89 if(CMAKE_HOST_WIN32)
|
|
90 set(D_OBJECT_SUFFIX .obj)
|
|
91 if(D_IS_MARS)
|
|
92 set(D_LIB_SUFFIX .lib)
|
|
93 set(D_LIB_PREFIX )
|
|
94 elseif(D_IS_LDC)
|
|
95 set(D_LIB_SUFFIX .a)
|
|
96 set(D_LIB_PREFIX lib)
|
|
97 endif(D_IS_MARS)
|
|
98 elseif(CMAKE_HOST_UNIX)
|
|
99 set(D_LIB_SUFFIX .a)
|
|
100 set(D_LIB_PREFIX lib)
|
|
101 set(D_OBJECT_SUFFIX .o)
|
|
102 endif(CMAKE_HOST_WIN32)
|
|
103
|
|
104 ##--------------------------------------------
|
|
105 ## Macroses and functions.
|
|
106 ##--------------------------------------------
|
|
107
|
|
108 ## Make native path.
|
|
109 ## Usage:
|
|
110 ## set(path c:/file_path/file_name.cpp)
|
|
111 ## make_native_path(path)
|
|
112 ## message(STATUS ${path})
|
|
113 ## Output:
|
|
114 ## -- "c:\file_path\file_name.cpp"
|
|
115 ## Command "file(TO_NATIVE_PATH ...)" is wrong on Windows
|
|
116 macro(make_native_path pathname)
|
|
117 if(CMAKE_HOST_WIN32)
|
|
118 # An extra \\ escape is necessary to get a \ through CMake's processing.
|
|
119 string(REPLACE "/" "\\" ${pathname} "${${pathname}}")
|
|
120 # Enclose with UNESCAPED quotes. This means we need to escape our
|
|
121 # quotes once here, i.e. with \"
|
|
122 set(${pathname} \"${${pathname}}\")
|
|
123 endif(CMAKE_HOST_WIN32)
|
|
124 endmacro(make_native_path)
|
|
125
|
|
126 ##
|
|
127 ## Example:
|
|
128 ## set(path 24.3+23.bin)
|
|
129 ## obj_path(path)
|
|
130 ## message(STATUS ${path})
|
|
131 ## Example output:
|
|
132 ## -- 24\.3\+23\.bin
|
|
133 macro(regex_safe_string outvariable)
|
|
134 set(${outvariable} ${ARGN})
|
|
135 set(__regex_chars__ ^ $ . ] [ - * + ? | \( \))
|
|
136 foreach(__regex_char__ ${__regex_chars__})
|
|
137 string(REPLACE "${__regex_char__}"
|
|
138 "\\${__regex_char__}" ${outvariable} ${${outvariable}}
|
|
139 )
|
|
140 endforeach(__regex_char__ ${__regex_chars__})
|
|
141 endmacro(regex_safe_string outvariable)
|
|
142
|
|
143 ## Remove unnecessary path to the object file.
|
|
144 ## path -- path to object file.
|
|
145 ## Example:
|
|
146 ## set(path ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/target.dir/main.d.obj)
|
|
147 ## obj_path(path)
|
|
148 ## message(STATUS ${path})
|
|
149 ## Example output:
|
|
150 ## -- CMakeFiles/target.dir/main.d.obj
|
|
151 macro(obj_path path)
|
|
152 regex_safe_string(cbd_safe_tmp ${CMAKE_CURRENT_BINARY_DIR})
|
|
153 regex_safe_string(csd_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR})
|
|
154 set(regexp_str_tmp "(${cbd_safe_tmp}/|${csd_safe_tmp}/|)(.+)")
|
|
155 string(REGEX REPLACE ${regexp_str_tmp} "\\2" ${path} "${${path}}")
|
|
156 endmacro(obj_path path)
|
|
157
|
|
158 ## Compile d files.
|
|
159 ## target -- name of a new target.
|
|
160 ## objects_list -- created object files.
|
|
161 ## params -- sources files.
|
|
162 macro(compile_d_files target objects_list)
|
|
163 set(${objects_list})
|
|
164 set(tmp_dir_tmp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir)
|
|
165
|
|
166 set(type_tmp SOURCES)
|
|
167 set(SOURCES_tmp )
|
|
168 set(FLAGS_tmp )
|
|
169
|
|
170 ## Parse parameters list.
|
|
171 set(params_tmp SOURCES FLAGS)
|
|
172 foreach(arg_tmp ${ARGN})
|
|
173 set(founded_type_tmp)
|
|
174 if(NOT founded_type_tmp)
|
|
175 foreach(param_tmp ${params_tmp})
|
|
176 if(arg_tmp STREQUAL param_tmp)
|
|
177 set(type_tmp ${param_tmp})
|
|
178 set(founded_type_tmp 1)
|
|
179 break(param_tmp ${params_tmp})
|
|
180 endif(arg_tmp STREQUAL param_tmp)
|
|
181 endforeach(param_tmp ${params_tmp})
|
|
182 endif(NOT founded_type_tmp)
|
|
183 if(NOT founded_type_tmp)
|
|
184 set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp})
|
|
185 endif(NOT founded_type_tmp)
|
|
186 endforeach(arg_tmp ${ARGN})
|
|
187
|
|
188 if(NOT SINGLE_D_OBJECT)
|
|
189 set(${objects_list})
|
|
190 foreach (d_source_p_tmp ${SOURCES_tmp})
|
|
191 get_filename_component(ext_tmp ${d_source_p_tmp} EXT)
|
|
192 find_file(d_source_p_tmp ${d_source_p_tmp} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
|
|
193 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
|
|
194 set (d_source_tmp ${d_source_p_tmp})
|
|
195 obj_path(d_source_tmp)
|
|
196 set(d_obj_tmp ${tmp_dir_tmp}/${d_source_tmp}${D_OBJECT_SUFFIX})
|
|
197 set(${objects_list} ${${objects_list}} ${d_obj_tmp})
|
|
198 get_filename_component(path_tmp ${d_obj_tmp} PATH)
|
|
199 file(MAKE_DIRECTORY ${path_tmp})
|
|
200 set(d_obj_out_tmp ${d_obj_tmp})
|
|
201 obj_path(d_obj_out_tmp)
|
|
202 #get_imported_files(depends_tmp ${d_source_p_tmp}) ## Too slow.....
|
|
203 add_custom_command(OUTPUT "${d_obj_tmp}"
|
|
204 COMMAND "${DC}"
|
|
205 ARGS ${FLAGS_tmp} ${d_source_p_tmp} -c -of${d_obj_tmp}
|
|
206 COMMENT "Building ${d_obj_out_tmp}"
|
|
207 DEPENDS ${d_source_p} ${depends_tmp}
|
|
208 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
209 )
|
|
210 endforeach (d_source_p_tmp ${SOURCES_tmp})
|
|
211 else(NOT SINGLE_D_OBJECT)
|
|
212 set(object_tmp ${tmp_dir_tmp}/${target}${D_OBJECT_SUFFIX})
|
|
213 set(d_obj_out_tmp ${${objects_list}})
|
|
214 obj_path(d_obj_out_tmp)
|
|
215 set(parameters_tmp ${FLAGS_tmp} -c ${SOURCES_tmp} -of${object_tmp})
|
|
216 set(parameters_list_file_tmp ${tmp_dir_tmp}/parameters_obj)
|
|
217 if(CMAKE_HOST_WIN32)
|
|
218 file(REMOVE ${parameters_list_file_tmp})
|
|
219 foreach(arg_tmp ${parameters_tmp})
|
|
220 file(APPEND ${parameters_list_file_tmp} "${arg_tmp}\n")
|
|
221 endforeach(arg_tmp)
|
|
222 set(param_tmp @${parameters_list_file_tmp})
|
|
223 elseif(CMAKE_HOST_UNIX)
|
|
224 set(param_tmp ${parameters_tmp})
|
|
225 endif(CMAKE_HOST_WIN32)
|
|
226 #get_imported_files(depends_tmp ${ARGN})
|
|
227 add_custom_command(OUTPUT "${object_tmp}"
|
|
228 COMMAND "${DC}"
|
|
229 ARGS ${param_tmp}
|
|
230 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
231 DEPENDS ${SOURCES_tmp} ${depends_tmp}
|
|
232 COMMENT ""
|
|
233 )
|
|
234 set(${objects_list} ${object_tmp})
|
|
235 endif(NOT SINGLE_D_OBJECT)
|
|
236 #add_custom_target(${target} DEPENDS "${${objects_list}}")
|
|
237 endmacro(compile_d_files objects_list)
|
|
238
|
|
239
|
|
240 ## Add D target.
|
|
241 ## name -- target name.
|
|
242 ## Params:
|
|
243 ## TYPE -- target type.
|
|
244 ## STATIC -- static library.
|
|
245 ## SHARED -- shared library.
|
|
246 ## BINARY -- executable.
|
|
247 ## SOURCES -- sources of the target.
|
|
248 ## INCLUDES -- include paths.
|
|
249 ## FLAGS -- build flags.
|
|
250 ## LIBS -- libraries for link.
|
|
251 ## LIB_PATHS -- libraries paths.
|
|
252 ## DEPENDS -- target depends.
|
|
253 macro(add_d_target name)
|
|
254 set(type_tmp SOURCES)
|
|
255 set(TYPE_tmp)
|
|
256 set(INCLUDES_tmp )
|
|
257 set(FLAGS_tmp )
|
|
258 set(SOURCES_tmp )
|
|
259 set(OBJECTS_tmp )
|
|
260 set(LIBS_tmp )
|
|
261 set(LIB_PATHS_tmp)
|
|
262 set(DEPENDS_tmp)
|
|
263 set(OUTPUT_PATH_tmp )
|
|
264 set(compile_flags_tmp ${D_FLAGS})
|
|
265 set(additional_commands_tmp )
|
|
266 set(link_flags_tmp )
|
|
267
|
|
268 ## Parse parameters list.
|
|
269 set(params_tmp TYPE INCLUDES FLAGS SOURCES OBJECTS LIBS LIB_PATHS DEPENDS OUTPUT_PATH)
|
|
270 foreach(arg_tmp ${ARGN})
|
|
271 set(founded_type_tmp)
|
|
272 if(${arg_tmp} STREQUAL "DETECT_DEPENDS")
|
|
273 set(auto_detect_depentes_tmp 1)
|
|
274 set(founded_type_tmp 1)
|
|
275 endif(${arg_tmp} STREQUAL "DETECT_DEPENDS")
|
|
276 if(NOT founded_type_tmp)
|
|
277 foreach(param_tmp ${params_tmp})
|
|
278 if(arg_tmp STREQUAL param_tmp)
|
|
279 set(type_tmp ${param_tmp})
|
|
280 set(founded_type_tmp 1)
|
|
281 break(param_tmp ${params_tmp})
|
|
282 endif(arg_tmp STREQUAL param_tmp)
|
|
283 endforeach(param_tmp ${params_tmp})
|
|
284 endif(NOT founded_type_tmp)
|
|
285 if(NOT founded_type_tmp)
|
|
286 set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp})
|
|
287 endif(NOT founded_type_tmp)
|
|
288 endforeach(arg_tmp ${ARGN})
|
|
289
|
|
290 ## Init target type.
|
|
291 if (OUTPUT_PATH_tmp)
|
|
292 set(output_name_tmp "${OUTPUT_PATH_tmp}")
|
|
293 endif (OUTPUT_PATH_tmp)
|
|
294 if("${TYPE_tmp}" STREQUAL "STATIC")
|
|
295 set(link_flags_tmp ${link_flags_tmp} -lib)
|
|
296 if(NOT OUTPUT_PATH_tmp)
|
|
297 if(ARCHIVE_OUTPUT_DIRECTORY)
|
|
298 set(output_name_tmp ${ARCHIVE_OUTPUT_DIRECTORY})
|
|
299 else(ARCHIVE_OUTPUT_DIRECTORY)
|
|
300 set(output_name_tmp ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
|
301 endif(ARCHIVE_OUTPUT_DIRECTORY)
|
|
302 endif(NOT OUTPUT_PATH_tmp)
|
|
303 set(output_name_tmp ${output_name_tmp}/${D_LIB_PREFIX}${name}${D_LIB_SUFFIX})
|
|
304 elseif("${TYPE_tmp}" STREQUAL "BINARY")
|
|
305 set(build_binary_tmp 1)
|
|
306 if(NOT OUTPUT_PATH_tmp)
|
|
307 if(RUNTIME_OUTPUT_DIRECTORY)
|
|
308 set(output_name ${RUNTIME_OUTPUT_DIRECTORY})
|
|
309 else(RUNTIME_OUTPUT_DIRECTORY)
|
|
310 set(output_name_tmp ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
|
311 endif(RUNTIME_OUTPUT_DIRECTORY)
|
|
312 endif(NOT OUTPUT_PATH_tmp)
|
|
313 set(output_name_tmp ${output_name_tmp}/${name}${CMAKE_EXECUTABLE_SUFFIX})
|
|
314 elseif("${TYPE_tmp}" STREQUAL "SHARED")
|
|
315 if(D_IS_MARS)
|
|
316 message(FATAL_ERROR "DMD not support building shared library")
|
|
317 endif(D_IS_MARS)
|
|
318 if(NOT OUTPUT_PATH_tmp)
|
|
319 if(LIBRARY_OUTPUT_DIRECTORY)
|
|
320 set(output_name_tmp ${LIBRARY_OUTPUT_DIRECTORY})
|
|
321 else(LIBRARY_OUTPUT_DIRECTORY)
|
|
322 set(output_name_tmp ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
|
323 endif(LIBRARY_OUTPUT_DIRECTORY)
|
|
324 endif(NOT OUTPUT_PATH_tmp)
|
|
325 set(build_binary 1)
|
|
326 set(output_name_tmp ${output_name_tmp}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
327 set(link_flags_tmp ${compile_flags_tmp} -L-shared)
|
|
328 else("${TYPE_tmp}" STREQUAL "STATIC")
|
|
329 message(FATAL_ERROR "D target ${TYPE_tmp} not supported")
|
|
330 endif("${TYPE_tmp}" STREQUAL "STATIC")
|
|
331
|
|
332 ## Include paths.
|
|
333 foreach(inc_tmp ${INCLUDES_tmp} ${D_INCLUDES})
|
|
334 set(compile_flags_tmp ${compile_flags_tmp} -I${inc_tmp})
|
|
335 endforeach(inc_tmp ${INCLUDES_tmp} ${D_INCLUDES})
|
|
336
|
|
337 ## Libraries and paths of them.
|
|
338 set(libs_tmp)
|
|
339 if(build_binary_tmp)
|
|
340 if(D_IS_MARS AND CMAKE_HOST_WIN32)
|
|
341 foreach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS})
|
|
342 make_native_path(lib_path_tmp)
|
|
343 string(REPLACE "/" "\\" lib_path_tmp "${lib_path_tmp}//")
|
|
344 set(lib_path_tmp \"${lib_path_tmp}\")
|
|
345 set(link_flags_tmp ${link_flags_tmp} -L+${lib_path_tmp})
|
|
346 endforeach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS})
|
|
347 #set(additional_commands_tmp COMMAND set ARGS LIB=)
|
|
348 #foreach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS})
|
|
349 #MAKE_NATIVE_PATH(lib_path_tmp)
|
|
350 #set(additional_commands_tmp ${additional_commands_tmp}${lib_path_tmp};)
|
|
351 #endforeach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS})
|
|
352 else(D_IS_MARS AND CMAKE_HOST_WIN32)
|
|
353 foreach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS})
|
|
354 set(link_flags_tmp ${link_flags_tmp} -L-L${lib_path_tmp})
|
|
355 endforeach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS})
|
|
356 endif(D_IS_MARS AND CMAKE_HOST_WIN32)
|
|
357 foreach(lib_tmp ${LIBS_tmp} ${D_LIBS})
|
|
358 if(D_IS_MARS AND CMAKE_HOST_WIN32)
|
|
359 set(link_flags_tmp ${link_flags_tmp} -L+${lib_tmp})
|
|
360 else(D_IS_MARS AND CMAKE_HOST_WIN32)
|
|
361 set(link_flags_tmp ${link_flags_tmp} -L-l${lib_tmp})
|
|
362 endif(D_IS_MARS AND CMAKE_HOST_WIN32)
|
|
363 endforeach(lib_tmp ${LIBS_tmp} ${D_LIBS})
|
|
364 endif(build_binary_tmp)
|
|
365
|
|
366 set(not_obj_tmp ${ONE_BUILD_COMMAND})
|
|
367 ## Ldc not support -lib flag.
|
|
368 if(ONE_BUILD_COMMAND AND ${TYPE_tmp} STREQUAL "STATIC" AND D_IS_LLVM)
|
|
369 set(not_obj_tmp OFF)
|
|
370 endif(ONE_BUILD_COMMAND AND ${TYPE_tmp} STREQUAL "STATIC" AND D_IS_LLVM)
|
|
371
|
|
372 if(build_binary_tmp AND NOT D_IS_MARS)
|
|
373 set(compile_flags_tmp ${compile_flags_tmp} -od${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${name}.dir)
|
|
374 endif(build_binary_tmp AND NOT D_IS_MARS)
|
|
375
|
|
376 if(CMAKE_BUILD_TYPE)
|
|
377 string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
|
|
378 set(compile_flags_tmp ${compile_flags_tmp} ${D_${CMAKE_BUILD_TYPE_UPPER}_FLAGS})
|
|
379 endif(CMAKE_BUILD_TYPE)
|
|
380
|
|
381 if(auto_detect_depentes_tmp)
|
|
382 get_files_depends(SOURCES_tmp ${SOURCES_tmp})
|
|
383 endif(auto_detect_depentes_tmp)
|
|
384
|
|
385 set(used_ar_tmp)
|
|
386 get_filename_component(output_path_tmp ${output_name_tmp} PATH)
|
|
387 if (NOT not_obj_tmp)
|
|
388 compile_d_files(${name} objs_tmp ${SOURCES_tmp} FLAGS ${compile_flags_tmp})
|
|
389 set(SOURCES_tmp ${objs_tmp})
|
|
390 if(NOT D_IS_MARS AND ${TYPE_tmp} STREQUAL "STATIC")
|
|
391 set(parameters_tmp rcs ${output_name_tmp} ${SOURCES_tmp} ${OBJECTS_tmp})
|
|
392 set(parameters_list_file_tmp ${tmp_dir_tmp}/parameters)
|
|
393 if(CMAKE_HOST_WIN32)
|
|
394 file(REMOVE ${parameters_list_file_tmp})
|
|
395 foreach(arg_tmp ${parameters_tmp})
|
|
396 file(APPEND ${parameters_list_file_tmp} "${arg_tmp}\n")
|
|
397 endforeach(arg_tmp)
|
|
398 set(param_tmp @${parameters_list_file_tmp})
|
|
399 elseif(CMAKE_HOST_UNIX)
|
|
400 set(param_tmp ${parameters_tmp})
|
|
401 endif(CMAKE_HOST_WIN32)
|
|
402 add_custom_command(
|
|
403 OUTPUT "${output_name_tmp}"
|
|
404 COMMAND "${CMAKE_AR}"
|
|
405 ARGS ${param_tmp}
|
|
406 DEPENDS ${SOURCES_tmp}
|
|
407 COMMENT "Linking ${lib_name}"
|
|
408 )
|
|
409 set(used_ar_tmp 1)
|
|
410 endif(NOT D_IS_MARS AND ${TYPE_tmp} STREQUAL "STATIC")
|
|
411 endif (NOT not_obj_tmp)
|
|
412
|
|
413 if (NOT used_ar_tmp)
|
|
414 set(output_name_native_tmp ${output_name_tmp})
|
|
415 if(D_IS_MARS)
|
|
416 set(additional_commands_tmp ${additional_commands_tmp} COMMAND ${CMAKE_COMMAND} -E make_directory ${output_path_tmp})
|
|
417 make_native_path(output_name_native_tmp)
|
|
418 endif(D_IS_MARS)
|
|
419 set(parameters_tmp ${compile_flags_tmp} ${link_flags_tmp} ${SOURCES_tmp} ${OBJECTS_tmp} -of${output_name_native_tmp})
|
|
420 set(parameters_list_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${name}.dir/parameters)
|
|
421 if(CMAKE_HOST_WIN32)
|
|
422 file(REMOVE ${parameters_list_file_tmp})
|
|
423 foreach(arg_tmp ${parameters_tmp})
|
|
424 file(APPEND ${parameters_list_file_tmp} "${arg_tmp}\n")
|
|
425 endforeach(arg_tmp)
|
|
426 set(param_tmp @${parameters_list_file_tmp})
|
|
427 elseif(CMAKE_HOST_UNIX)
|
|
428 set(param_tmp ${parameters_tmp})
|
|
429 endif(CMAKE_HOST_WIN32)
|
|
430 #get_imported_files(depends_tmp ${SOURCES_tmp})
|
|
431 add_custom_command(
|
|
432 OUTPUT ${output_name_tmp}
|
|
433 ${additional_commands_tmp}
|
|
434 COMMAND ${DC}
|
|
435 ARGS ${param_tmp}
|
|
436 DEPENDS ${SOURCES_tmp} ${depends_tmp}
|
|
437 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
438 COMMENT "Linking ${name}"
|
|
439 )
|
|
440 endif(NOT used_ar_tmp)
|
|
441 add_custom_target(${name} ALL DEPENDS ${DEPENDS_tmp} ${output_name_tmp})
|
|
442 endmacro(add_d_target name)
|
|
443
|
|
444 ## Add static library target.
|
|
445 macro(add_d_static_lib name)
|
|
446 add_d_target(${name} TYPE STATIC SOURCES ${ARGN})
|
|
447 endmacro(add_d_static_lib name)
|
|
448
|
|
449 ## Add binary target.
|
|
450 macro(add_d_program name)
|
|
451 add_d_target(${name} TYPE BINARY SOURCES ${ARGN})
|
|
452 endmacro(add_d_program name)
|
|
453
|
|
454 ## Add shared library target.
|
|
455 macro(add_d_shared_lib name)
|
|
456 add_d_target(${name} TYPE SHARED SOURCES ${ARGN})
|
|
457 endmacro(add_d_shared_lib name)
|
|
458
|
|
459 ## Add library target.
|
|
460 ## If it support library would shared.
|
|
461 macro(add_d_lib name)
|
|
462 if(D_IS_MARS)
|
|
463 add_d_target(${name} TYPE STATIC ${ARGN})
|
|
464 else(D_IS_MARS)
|
|
465 add_d_target(${name} TYPE SHARED ${ARGN})
|
|
466 endif(D_IS_MARS)
|
|
467 endmacro(add_d_lib name)
|
|
468
|
|
469 ##
|
|
470 macro(get_imported_files imported)
|
|
471 execute_process(COMMAND ${DC} -c -o- -v ${compile_flags_tmp} ${ARGN}
|
|
472 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
473 OUTPUT_VARIABLE dc_output_tmp
|
|
474 )
|
|
475 string(REGEX MATCHALL "import[^\\(]*([^\\)]*)" dc_output_tmp "${dc_output_tmp}")
|
|
476 set(${imported})
|
|
477 foreach(import_tmp ${dc_output_tmp})
|
|
478 string(REGEX REPLACE "import[^\\(]*\\(([^\\)]*)" "\\1" import_tmp ${import_tmp})
|
|
479 set(${imported} ${${imported}} ${import_tmp})
|
|
480 endforeach(import_tmp ${dc_output_tmp})
|
|
481 endmacro(get_imported_files imported)
|
|
482
|
|
483 macro(filter_paths result)
|
|
484 set(${result})
|
|
485 set(read_now_tmp paths)
|
|
486 set(include_tmp)
|
|
487 set(paths_tmp)
|
|
488 foreach(arg_tmp ${ARGN})
|
|
489 set(founded_tmp)
|
|
490 if(${arg_tmp} STREQUAL "INCLUDE_PATHS")
|
|
491 set(read_now_tmp includes)
|
|
492 set(founded_tmp 1)
|
|
493 elseif(${arg_tmp} STREQUAL "INCLUDE_CURRENT_DIR")
|
|
494 set(locale_tmp 1)
|
|
495 set(read_now_tmp paths)
|
|
496 set(founded_tmp 1)
|
|
497 endif(${arg_tmp} STREQUAL "INCLUDE_PATHS")
|
|
498 if(NOT founded_tmp)
|
|
499 set(${read_now_tmp}_tmp ${${read_now_tmp}_tmp} ${arg_tmp})
|
|
500 endif(NOT founded_tmp)
|
|
501 endforeach(arg_tmp ${ARGN})
|
|
502 regex_safe_string(include_tmp ${includes_tmp})
|
|
503 set(regex_include_tmp)
|
|
504 set(is_first_tmp 1)
|
|
505 foreach(include_tmp ${includes_tmp})
|
|
506 if(is_first_tmp)
|
|
507 set(is_first_tmp 1)
|
|
508 else(is_first_tmp)
|
|
509 set(regex_includes_tmp ${regex_includes_tmp}|)
|
|
510 endif(is_first_tmp)
|
|
511 set(regex_includes_tmp ${regex_includes_tmp}${include_tmp})
|
|
512 endforeach(include_tmp ${include_tmp})
|
|
513 foreach(path_tmp ${paths_tmp})
|
|
514 file(TO_CMAKE_PATH path_tmp ${path_tmp})
|
|
515 string(REGEX MATCH "(${regex_includes_tmp})[^/]*" found "${path_tmp}")
|
|
516 set(full_path_tmp 1)
|
|
517 if(locale_tmp)
|
|
518 string(SUBSTRING "${path_tmp}" 0 1 first_sym_tmp)
|
|
519 set(full_path_tmp)
|
|
520 if(${first_sym_tmp} STREQUAL "/")
|
|
521 set(full_path_tmp 1)
|
|
522 endif(${first_sym_tmp} STREQUAL "/")
|
|
523 endif(locale_tmp)
|
|
524 if(NOT found AND full_path_tmp)
|
|
525 else(NOT found AND full_path_tmp)
|
|
526 set(${result} ${${result}} ${path_tmp})
|
|
527 endif(NOT found AND full_path_tmp)
|
|
528 endforeach(path_tmp ${paths_tmp})
|
|
529 endmacro(filter_paths )
|
|
530
|
|
531 macro(get_files_depends out)
|
|
532 get_imported_files(${out} ${ARGN})
|
|
533 filter_paths(${out} ${${out}} INCLUDE_CURRENT_DIR INCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
|
534 set(${out} ${ARGN} ${${out}})
|
|
535 endmacro(get_files_depends out) |