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