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