Mercurial > projects > qtd
annotate cmake/FindD.cmake @ 215:8aaa84d48451
Improve examples.
author | SokoL_SD |
---|---|
date | Tue, 14 Jul 2009 15:25:45 +0000 |
parents | bc1525b955d8 |
children | 7f150ad4cb5f |
rev | line source |
---|---|
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}) | |
215 | 174 set(found_type_tmp) |
175 if(NOT found_type_tmp) | |
132 | 176 foreach(param_tmp ${params_tmp}) |
177 if(arg_tmp STREQUAL param_tmp) | |
178 set(type_tmp ${param_tmp}) | |
215 | 179 set(found_type_tmp 1) |
132 | 180 break(param_tmp ${params_tmp}) |
181 endif(arg_tmp STREQUAL param_tmp) | |
182 endforeach(param_tmp ${params_tmp}) | |
215 | 183 endif(NOT found_type_tmp) |
184 if(NOT found_type_tmp) | |
132 | 185 set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp}) |
215 | 186 endif(NOT found_type_tmp) |
132 | 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 ) | |
203
d3383b16f1d7
Add a 'NO_DEPS_SOURCES' option to the 'add_d_target' macro. And use it for resources and forms in QtD examples.
SokoL_SD
parents:
181
diff
changeset
|
285 set(GEN_FILES_tmp ) |
132 | 286 set(OBJECTS_tmp ) |
287 set(LIBS_tmp ) | |
288 set(LIB_PATHS_tmp) | |
289 set(DEPENDS_tmp) | |
290 set(OUTPUT_PATH_tmp ) | |
291 set(compile_flags_tmp ${D_FLAGS}) | |
292 set(additional_commands_tmp ) | |
215 | 293 set(detect_deps_tmp 1) |
132 | 294 set(link_flags_tmp ) |
295 | |
296 ## Parse parameters list. | |
203
d3383b16f1d7
Add a 'NO_DEPS_SOURCES' option to the 'add_d_target' macro. And use it for resources and forms in QtD examples.
SokoL_SD
parents:
181
diff
changeset
|
297 set(params_tmp TYPE INCLUDES FLAGS SOURCES NO_DEPS_SOURCES OBJECTS LIBS LIB_PATHS DEPENDS OUTPUT_PATH) |
215 | 298 |
132 | 299 foreach(arg_tmp ${ARGN}) |
215 | 300 set(found_type_tmp) |
301 if(${arg_tmp} STREQUAL "NOT_DETECT_DEPENDS") | |
302 set(detect_deps_tmp 0) | |
303 set(found_type_tmp 1) | |
304 endif(${arg_tmp} STREQUAL "NOT_DETECT_DEPENDS") | |
305 if(NOT found_type_tmp) | |
132 | 306 foreach(param_tmp ${params_tmp}) |
307 if(arg_tmp STREQUAL param_tmp) | |
308 set(type_tmp ${param_tmp}) | |
215 | 309 set(found_type_tmp 1) |
132 | 310 break(param_tmp ${params_tmp}) |
311 endif(arg_tmp STREQUAL param_tmp) | |
312 endforeach(param_tmp ${params_tmp}) | |
215 | 313 endif(NOT found_type_tmp) |
314 if(NOT found_type_tmp) | |
132 | 315 set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp}) |
215 | 316 endif(NOT found_type_tmp) |
132 | 317 endforeach(arg_tmp ${ARGN}) |
318 | |
319 ## Init target type. | |
320 if (OUTPUT_PATH_tmp) | |
321 set(output_name_tmp "${OUTPUT_PATH_tmp}") | |
322 endif (OUTPUT_PATH_tmp) | |
323 if("${TYPE_tmp}" STREQUAL "STATIC") | |
324 set(link_flags_tmp ${link_flags_tmp} -lib) | |
325 if(NOT OUTPUT_PATH_tmp) | |
326 if(ARCHIVE_OUTPUT_DIRECTORY) | |
327 set(output_name_tmp ${ARCHIVE_OUTPUT_DIRECTORY}) | |
328 else(ARCHIVE_OUTPUT_DIRECTORY) | |
329 set(output_name_tmp ${CMAKE_CURRENT_BINARY_DIR}/lib) | |
330 endif(ARCHIVE_OUTPUT_DIRECTORY) | |
331 endif(NOT OUTPUT_PATH_tmp) | |
332 set(output_name_tmp ${output_name_tmp}/${D_LIB_PREFIX}${name}${D_LIB_SUFFIX}) | |
333 elseif("${TYPE_tmp}" STREQUAL "BINARY") | |
334 set(build_binary_tmp 1) | |
335 if(NOT OUTPUT_PATH_tmp) | |
336 if(RUNTIME_OUTPUT_DIRECTORY) | |
337 set(output_name ${RUNTIME_OUTPUT_DIRECTORY}) | |
338 else(RUNTIME_OUTPUT_DIRECTORY) | |
339 set(output_name_tmp ${CMAKE_CURRENT_BINARY_DIR}/bin) | |
340 endif(RUNTIME_OUTPUT_DIRECTORY) | |
341 endif(NOT OUTPUT_PATH_tmp) | |
342 set(output_name_tmp ${output_name_tmp}/${name}${CMAKE_EXECUTABLE_SUFFIX}) | |
343 elseif("${TYPE_tmp}" STREQUAL "SHARED") | |
344 if(D_IS_MARS) | |
345 message(FATAL_ERROR "DMD not support building shared library") | |
346 endif(D_IS_MARS) | |
347 if(NOT OUTPUT_PATH_tmp) | |
348 if(LIBRARY_OUTPUT_DIRECTORY) | |
349 set(output_name_tmp ${LIBRARY_OUTPUT_DIRECTORY}) | |
350 else(LIBRARY_OUTPUT_DIRECTORY) | |
351 set(output_name_tmp ${CMAKE_CURRENT_BINARY_DIR}/lib) | |
352 endif(LIBRARY_OUTPUT_DIRECTORY) | |
353 endif(NOT OUTPUT_PATH_tmp) | |
354 set(build_binary 1) | |
355 set(output_name_tmp ${output_name_tmp}/${CMAKE_SHARED_LIBRARY_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}) | |
356 set(link_flags_tmp ${compile_flags_tmp} -L-shared) | |
357 else("${TYPE_tmp}" STREQUAL "STATIC") | |
358 message(FATAL_ERROR "D target ${TYPE_tmp} not supported") | |
359 endif("${TYPE_tmp}" STREQUAL "STATIC") | |
360 | |
361 ## Include paths. | |
362 foreach(inc_tmp ${INCLUDES_tmp} ${D_INCLUDES}) | |
363 set(compile_flags_tmp ${compile_flags_tmp} -I${inc_tmp}) | |
364 endforeach(inc_tmp ${INCLUDES_tmp} ${D_INCLUDES}) | |
365 | |
366 ## Libraries and paths of them. | |
367 set(libs_tmp) | |
368 if(build_binary_tmp) | |
369 if(D_IS_MARS AND CMAKE_HOST_WIN32) | |
370 foreach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS}) | |
371 make_native_path(lib_path_tmp) | |
372 string(REPLACE "/" "\\" lib_path_tmp "${lib_path_tmp}//") | |
373 set(lib_path_tmp \"${lib_path_tmp}\") | |
374 set(link_flags_tmp ${link_flags_tmp} -L+${lib_path_tmp}) | |
375 endforeach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS}) | |
376 #set(additional_commands_tmp COMMAND set ARGS LIB=) | |
377 #foreach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS}) | |
378 #MAKE_NATIVE_PATH(lib_path_tmp) | |
379 #set(additional_commands_tmp ${additional_commands_tmp}${lib_path_tmp};) | |
380 #endforeach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS}) | |
381 else(D_IS_MARS AND CMAKE_HOST_WIN32) | |
382 foreach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS}) | |
383 set(link_flags_tmp ${link_flags_tmp} -L-L${lib_path_tmp}) | |
384 endforeach(lib_path_tmp ${LIB_PATHS_tmp} ${D_LIB_PATHS}) | |
385 endif(D_IS_MARS AND CMAKE_HOST_WIN32) | |
386 foreach(lib_tmp ${LIBS_tmp} ${D_LIBS}) | |
387 if(D_IS_MARS AND CMAKE_HOST_WIN32) | |
388 set(link_flags_tmp ${link_flags_tmp} -L+${lib_tmp}) | |
389 else(D_IS_MARS AND CMAKE_HOST_WIN32) | |
390 set(link_flags_tmp ${link_flags_tmp} -L-l${lib_tmp}) | |
391 endif(D_IS_MARS AND CMAKE_HOST_WIN32) | |
392 endforeach(lib_tmp ${LIBS_tmp} ${D_LIBS}) | |
393 endif(build_binary_tmp) | |
394 | |
395 set(not_obj_tmp ${ONE_BUILD_COMMAND}) | |
396 ## Ldc not support -lib flag. | |
397 if(ONE_BUILD_COMMAND AND ${TYPE_tmp} STREQUAL "STATIC" AND D_IS_LLVM) | |
398 set(not_obj_tmp OFF) | |
399 endif(ONE_BUILD_COMMAND AND ${TYPE_tmp} STREQUAL "STATIC" AND D_IS_LLVM) | |
400 | |
401 if(build_binary_tmp AND NOT D_IS_MARS) | |
402 set(compile_flags_tmp ${compile_flags_tmp} -od${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${name}.dir) | |
403 endif(build_binary_tmp AND NOT D_IS_MARS) | |
404 | |
405 if(CMAKE_BUILD_TYPE) | |
406 string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) | |
407 set(compile_flags_tmp ${compile_flags_tmp} ${D_${CMAKE_BUILD_TYPE_UPPER}_FLAGS}) | |
408 endif(CMAKE_BUILD_TYPE) | |
409 | |
215 | 410 if(detect_deps_tmp) |
411 message(STATUS "Getting dependencies for ${name}") | |
203
d3383b16f1d7
Add a 'NO_DEPS_SOURCES' option to the 'add_d_target' macro. And use it for resources and forms in QtD examples.
SokoL_SD
parents:
181
diff
changeset
|
412 get_files_depends(tmp ${SOURCES_tmp}) |
d3383b16f1d7
Add a 'NO_DEPS_SOURCES' option to the 'add_d_target' macro. And use it for resources and forms in QtD examples.
SokoL_SD
parents:
181
diff
changeset
|
413 set(SOURCES_tmp ${tmp}) |
215 | 414 endif(detect_deps_tmp) |
212 | 415 set(SOURCES_tmp ${SOURCES_tmp} ${NO_DEPS_SOURCES_tmp}) |
132 | 416 |
417 set(used_ar_tmp) | |
418 get_filename_component(output_path_tmp ${output_name_tmp} PATH) | |
419 if (NOT not_obj_tmp) | |
420 compile_d_files(${name} objs_tmp ${SOURCES_tmp} FLAGS ${compile_flags_tmp}) | |
421 set(SOURCES_tmp ${objs_tmp}) | |
422 if(NOT D_IS_MARS AND ${TYPE_tmp} STREQUAL "STATIC") | |
423 set(parameters_tmp rcs ${output_name_tmp} ${SOURCES_tmp} ${OBJECTS_tmp}) | |
424 set(parameters_list_file_tmp ${tmp_dir_tmp}/parameters) | |
425 if(CMAKE_HOST_WIN32) | |
426 file(REMOVE ${parameters_list_file_tmp}) | |
427 foreach(arg_tmp ${parameters_tmp}) | |
428 file(APPEND ${parameters_list_file_tmp} "${arg_tmp}\n") | |
429 endforeach(arg_tmp) | |
430 set(param_tmp @${parameters_list_file_tmp}) | |
431 elseif(CMAKE_HOST_UNIX) | |
432 set(param_tmp ${parameters_tmp}) | |
433 endif(CMAKE_HOST_WIN32) | |
434 add_custom_command( | |
435 OUTPUT "${output_name_tmp}" | |
436 COMMAND "${CMAKE_AR}" | |
437 ARGS ${param_tmp} | |
438 DEPENDS ${SOURCES_tmp} | |
439 COMMENT "Linking ${lib_name}" | |
440 ) | |
441 set(used_ar_tmp 1) | |
442 endif(NOT D_IS_MARS AND ${TYPE_tmp} STREQUAL "STATIC") | |
443 endif (NOT not_obj_tmp) | |
444 | |
445 if (NOT used_ar_tmp) | |
446 set(output_name_native_tmp ${output_name_tmp}) | |
447 if(D_IS_MARS) | |
448 set(additional_commands_tmp ${additional_commands_tmp} COMMAND ${CMAKE_COMMAND} -E make_directory ${output_path_tmp}) | |
449 make_native_path(output_name_native_tmp) | |
450 endif(D_IS_MARS) | |
451 set(parameters_tmp ${compile_flags_tmp} ${link_flags_tmp} ${SOURCES_tmp} ${OBJECTS_tmp} -of${output_name_native_tmp}) | |
452 set(parameters_list_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${name}.dir/parameters) | |
453 if(CMAKE_HOST_WIN32) | |
454 file(REMOVE ${parameters_list_file_tmp}) | |
455 foreach(arg_tmp ${parameters_tmp}) | |
456 file(APPEND ${parameters_list_file_tmp} "${arg_tmp}\n") | |
457 endforeach(arg_tmp) | |
458 set(param_tmp @${parameters_list_file_tmp}) | |
459 elseif(CMAKE_HOST_UNIX) | |
460 set(param_tmp ${parameters_tmp}) | |
461 endif(CMAKE_HOST_WIN32) | |
462 #get_imported_files(depends_tmp ${SOURCES_tmp}) | |
463 add_custom_command( | |
464 OUTPUT ${output_name_tmp} | |
465 ${additional_commands_tmp} | |
466 COMMAND ${DC} | |
467 ARGS ${param_tmp} | |
468 DEPENDS ${SOURCES_tmp} ${depends_tmp} | |
469 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
470 COMMENT "Linking ${name}" | |
471 ) | |
472 endif(NOT used_ar_tmp) | |
473 add_custom_target(${name} ALL DEPENDS ${DEPENDS_tmp} ${output_name_tmp}) | |
474 endmacro(add_d_target name) | |
475 | |
476 ## Add static library target. | |
477 macro(add_d_static_lib name) | |
478 add_d_target(${name} TYPE STATIC SOURCES ${ARGN}) | |
479 endmacro(add_d_static_lib name) | |
480 | |
481 ## Add binary target. | |
482 macro(add_d_program name) | |
483 add_d_target(${name} TYPE BINARY SOURCES ${ARGN}) | |
484 endmacro(add_d_program name) | |
485 | |
486 ## Add shared library target. | |
487 macro(add_d_shared_lib name) | |
488 add_d_target(${name} TYPE SHARED SOURCES ${ARGN}) | |
489 endmacro(add_d_shared_lib name) | |
490 | |
491 ## Add library target. | |
492 ## If it support library would shared. | |
493 macro(add_d_lib name) | |
494 if(D_IS_MARS) | |
495 add_d_target(${name} TYPE STATIC ${ARGN}) | |
496 else(D_IS_MARS) | |
497 add_d_target(${name} TYPE SHARED ${ARGN}) | |
498 endif(D_IS_MARS) | |
499 endmacro(add_d_lib name) | |
500 | |
501 ## | |
502 macro(get_imported_files imported) | |
503 execute_process(COMMAND ${DC} -c -o- -v ${compile_flags_tmp} ${ARGN} | |
504 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
505 OUTPUT_VARIABLE dc_output_tmp | |
215 | 506 |
132 | 507 ) |
508 string(REGEX MATCHALL "import[^\\(]*([^\\)]*)" dc_output_tmp "${dc_output_tmp}") | |
509 set(${imported}) | |
510 foreach(import_tmp ${dc_output_tmp}) | |
511 string(REGEX REPLACE "import[^\\(]*\\(([^\\)]*)" "\\1" import_tmp ${import_tmp}) | |
512 set(${imported} ${${imported}} ${import_tmp}) | |
513 endforeach(import_tmp ${dc_output_tmp}) | |
514 endmacro(get_imported_files imported) | |
515 | |
516 macro(filter_paths result) | |
517 set(${result}) | |
518 set(read_now_tmp paths) | |
519 set(include_tmp) | |
520 set(paths_tmp) | |
521 foreach(arg_tmp ${ARGN}) | |
522 set(founded_tmp) | |
523 if(${arg_tmp} STREQUAL "INCLUDE_PATHS") | |
524 set(read_now_tmp includes) | |
525 set(founded_tmp 1) | |
526 elseif(${arg_tmp} STREQUAL "INCLUDE_CURRENT_DIR") | |
527 set(locale_tmp 1) | |
528 set(read_now_tmp paths) | |
529 set(founded_tmp 1) | |
530 endif(${arg_tmp} STREQUAL "INCLUDE_PATHS") | |
531 if(NOT founded_tmp) | |
532 set(${read_now_tmp}_tmp ${${read_now_tmp}_tmp} ${arg_tmp}) | |
533 endif(NOT founded_tmp) | |
534 endforeach(arg_tmp ${ARGN}) | |
535 regex_safe_string(include_tmp ${includes_tmp}) | |
536 set(regex_include_tmp) | |
537 set(is_first_tmp 1) | |
538 foreach(include_tmp ${includes_tmp}) | |
539 if(is_first_tmp) | |
540 set(is_first_tmp 1) | |
541 else(is_first_tmp) | |
542 set(regex_includes_tmp ${regex_includes_tmp}|) | |
543 endif(is_first_tmp) | |
544 set(regex_includes_tmp ${regex_includes_tmp}${include_tmp}) | |
545 endforeach(include_tmp ${include_tmp}) | |
546 foreach(path_tmp ${paths_tmp}) | |
547 file(TO_CMAKE_PATH path_tmp ${path_tmp}) | |
548 string(REGEX MATCH "(${regex_includes_tmp})[^/]*" found "${path_tmp}") | |
549 set(full_path_tmp 1) | |
550 if(locale_tmp) | |
551 string(SUBSTRING "${path_tmp}" 0 1 first_sym_tmp) | |
552 set(full_path_tmp) | |
553 if(${first_sym_tmp} STREQUAL "/") | |
554 set(full_path_tmp 1) | |
555 endif(${first_sym_tmp} STREQUAL "/") | |
556 endif(locale_tmp) | |
557 if(NOT found AND full_path_tmp) | |
558 else(NOT found AND full_path_tmp) | |
559 set(${result} ${${result}} ${path_tmp}) | |
560 endif(NOT found AND full_path_tmp) | |
561 endforeach(path_tmp ${paths_tmp}) | |
562 endmacro(filter_paths ) | |
563 | |
564 macro(get_files_depends out) | |
565 get_imported_files(${out} ${ARGN}) | |
566 filter_paths(${out} ${${out}} INCLUDE_CURRENT_DIR INCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | |
567 set(${out} ${ARGN} ${${out}}) | |
568 endmacro(get_files_depends out) |