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