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