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