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