Mercurial > projects > qtd
comparison CMakeLists.txt @ 9:16eec94c5b33
Bug fixes in CMake script.
author | SokoL_SD |
---|---|
date | Thu, 14 May 2009 13:22:16 +0000 |
parents | b8a79f9fba5a |
children | 390725da0980 |
comparison
equal
deleted
inserted
replaced
8:c0c94c0066fa | 9:16eec94c5b33 |
---|---|
9 include_directories(${QT_INCLUDES} include ${CMAKE_CURRENT_BINARY_DIR}/include) | 9 include_directories(${QT_INCLUDES} include ${CMAKE_CURRENT_BINARY_DIR}/include) |
10 | 10 |
11 ## Options. | 11 ## Options. |
12 option(BUILD_QT_OPENGL "Build QtOpenGL" "ON") | 12 option(BUILD_QT_OPENGL "Build QtOpenGL" "ON") |
13 option(BUILD_EXAMPLES "Build examples" "ON") | 13 option(BUILD_EXAMPLES "Build examples" "ON") |
14 option(GENERATE_DI_FILES "Generate *.di files with DC -H command" "OFF") | |
14 | 15 |
15 ## Packages list. | 16 ## Packages list. |
16 set(packages_big Core Gui) | 17 set(packages_big Core Gui) |
17 if(BUILD_QT_OPENGL) | 18 if(BUILD_QT_OPENGL) |
18 set(packages_big ${packages_big} OpenGL) | 19 set(packages_big ${packages_big} OpenGL) |
56 else (DC) | 57 else (DC) |
57 message(FATAL_ERROR "D compliler not founded") | 58 message(FATAL_ERROR "D compliler not founded") |
58 endif (DC) | 59 endif (DC) |
59 | 60 |
60 if(D_IS_MARS) | 61 if(D_IS_MARS) |
61 option(COMBINED_OBJECT_FILE "Build all d sources to one object file" "ON") | 62 option(SINGLE_D_OBJECT "Build all d sources to one object file" "ON") |
62 elseif(D_IS_LLVM) | 63 elseif(D_IS_LLVM) |
63 option(COMBINED_OBJECT_FILE "Build all d sources to one object file" "OFF") | 64 option(SINGLE_D_OBJECT "Build all d sources to one object file" "OFF") |
65 if(SINGLE_D_OBJECT) | |
66 set(D_FLAGS ${D_FLAGS} -singleobj) | |
67 endif(SINGLE_D_OBJECT) | |
64 endif(D_IS_MARS) | 68 endif(D_IS_MARS) |
65 | 69 |
66 # Check D compiler version | 70 # Check D compiler version |
67 if(D_VERSION EQUAL "1") | 71 if(D_VERSION EQUAL "1") |
68 if (D_FRONTEND LESS "041") | 72 if (D_FRONTEND LESS "041") |
69 message(STATUS "Minimum required version of D compiler is 1.041 (or compiler based on this version)") | 73 message(STATUS "Minimum required version of D compiler is 1.041 (or compiler based on this version)") |
70 endif(D_FRONTEND LESS "041") | 74 endif(D_FRONTEND LESS "041") |
71 set(D_TARGET d1-tango) | 75 set(D_TARGET d1-tango) |
76 #set(D_FLAGS ${D_FLAGS} -I${CMAKE_SOURCE_DIR}/qtd/d1) | |
72 elseif(D_VERSION EQUAL "2") | 77 elseif(D_VERSION EQUAL "2") |
73 set(D_TARGET ) ## TODO: hm... I don`t known this parameter for D2 ^( | 78 set(D_TARGET ) ## TODO: hm... I don`t known this parameter for D2 ^( |
79 #set(D_FLAGS ${D_FLAGS} -I${CMAKE_SOURCE_DIR}/qtd/d2) | |
74 endif(D_VERSION EQUAL "1") | 80 endif(D_VERSION EQUAL "1") |
75 | 81 |
76 # Debug and release flags. | 82 # Debug and release flags. |
77 if (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) | 83 if (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) |
78 #set(CMAKE_BUILD_TYPE Debug) | 84 #set(CMAKE_BUILD_TYPE Debug) |
79 #set( SUFFIXLIB "${SUFFIXLIB}-debug" ) | 85 #set( SUFFIXLIB "${SUFFIXLIB}-debug" ) |
80 #set( SUFFIXBIN "${SUFFIXBIN}-debug" ) | 86 #set( SUFFIXBIN "${SUFFIXBIN}-debug" ) |
81 add_definitions(-DDEBUG) | 87 add_definitions(-DDEBUG) |
82 set(D_FLAGS -g -gc -debug) | 88 set(D_FLAGS ${D_FLAGS} -g -gc -debug) |
83 else (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) | 89 else (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) |
84 #set(CMAKE_BUILD_TYPE Release) | 90 #set(CMAKE_BUILD_TYPE Release) |
85 add_definitions(-UNO_DEBUG) | 91 add_definitions(-UNO_DEBUG) |
86 set(D_FLAGS -O -release -inline) | 92 set(D_FLAGS ${D_FLAGS} -O -release -inline) |
87 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) | 93 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) |
88 set(D_FLAGS ${D_FLAGS} -L/subsystem:windows) | 94 set(D_FLAGS ${D_FLAGS} -L/subsystem:windows) |
89 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows) | 95 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows) |
90 endif (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) | 96 endif (${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG]) |
91 set(D_FLAGS ${D_FLAGS} -I${CMAKE_BINARY_DIR} -I${CMAKE_SOURCE_DIR}) | 97 set(D_FLAGS ${D_FLAGS} -I${CMAKE_BINARY_DIR} -I${CMAKE_SOURCE_DIR}) |
92 if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT D_IS_MARS) | 98 if(NOT (${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS)) |
93 set(D_FLAGS ${D_FLAGS} -L-L${CMAKE_BINARY_DIR}/lib) | 99 set(D_FLAGS ${D_FLAGS} -L-L${CMAKE_BINARY_DIR}/lib) |
94 endif(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT D_IS_MARS) | 100 endif(NOT (${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS)) |
95 | 101 |
96 | 102 # System specifc settings. |
97 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) | 103 if(${CMAKE_SYSTEM_NAME} STREQUAL Windows) |
98 set(implib implib) | 104 set(implib implib) |
99 find_program(IMPLIB ${implib}) | 105 find_program(IMPLIB ${implib}) |
100 if (NOT IMPLIB) | 106 if (NOT IMPLIB) |
101 message(FATAL_ERROR "implib not found. You can donwload it from http://ftp.digitalmars.com/bup.zip") | 107 message(FATAL_ERROR "implib not found. You can donwload it from http://ftp.digitalmars.com/bup.zip") |
149 ## obj_path(path) | 155 ## obj_path(path) |
150 ## message(STATUS ${path}) | 156 ## message(STATUS ${path}) |
151 ## Example output: | 157 ## Example output: |
152 ## -- CMakeFiles/target.dir/main.d.obj | 158 ## -- CMakeFiles/target.dir/main.d.obj |
153 macro(OBJ_PATH path) | 159 macro(OBJ_PATH path) |
154 unset(test) | 160 set(test) |
155 string(REGEX MATCH "${CMAKE_CURRENT_BINARY_DIR}/.*" test "${${path}}") | 161 string(REGEX MATCH "${CMAKE_CURRENT_BINARY_DIR}/.*" test "${${path}}") |
156 if(NOT ${test} EQUAL "") | 162 if(NOT ${test} EQUAL "") |
157 string(LENGTH "${CMAKE_CURRENT_BINARY_DIR}" first) | 163 string(LENGTH "${CMAKE_CURRENT_BINARY_DIR}" first) |
158 string(LENGTH "${${path}}" last) | 164 string(LENGTH "${${path}}" last) |
159 math(EXPR first "${first} + 1") | 165 math(EXPR first "${first} + 1") |
175 ## Compile d files. | 181 ## Compile d files. |
176 ## target -- name of a new target. | 182 ## target -- name of a new target. |
177 ## objects_list -- created object files. | 183 ## objects_list -- created object files. |
178 ## params -- sources files. | 184 ## params -- sources files. |
179 macro(compile_d_files target objects_list) | 185 macro(compile_d_files target objects_list) |
180 unset(${objects_list}) | 186 set(${objects_list}) |
181 set(tmp_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir) | 187 set(tmp_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir) |
182 file(MAKE_DIRECTORY ${tmp_dir}) | 188 file(MAKE_DIRECTORY ${tmp_dir}) |
183 if(NOT COMBINED_OBJECT_FILE) | 189 if(NOT SINGLE_D_OBJECT) |
184 foreach (d_source_p ${ARGN}) | 190 foreach (d_source_p ${ARGN}) |
185 ## TODO: why find_file command work wrong? | 191 ## TODO: why find_file command work wrong? |
186 find_file(d_source_p ${d_source_p} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} | 192 find_file(d_source_p ${d_source_p} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} |
187 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) | 193 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) |
188 set (d_source ${d_source_p}) | 194 set (d_source ${d_source_p}) |
199 COMMENT "Building ${d_obj_out}" | 205 COMMENT "Building ${d_obj_out}" |
200 DEPENDS ${d_source_p} | 206 DEPENDS ${d_source_p} |
201 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | 207 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
202 ) | 208 ) |
203 endforeach(d_source_p) | 209 endforeach(d_source_p) |
204 else(NOT COMBINED_OBJECT_FILE) | 210 else(NOT SINGLE_D_OBJECT) |
205 set(${objects_list} ${tmp_dir}/${target}${D_OBJECT_SUFFIX}) | 211 set(${objects_list} ${tmp_dir}/${target}${D_OBJECT_SUFFIX}) |
206 set(d_obj_out ${${objects_list}}) | 212 set(d_obj_out ${${objects_list}}) |
207 obj_path(d_obj_out) | 213 obj_path(d_obj_out) |
208 set(parameters_list_file ${tmp_dir}/parameters) | 214 set(parameters_list_file ${tmp_dir}/parameters) |
209 set(parameters ${D_FLAGS} -c ${ARGN} -of${${objects_list}}) | 215 set(parameters ${D_FLAGS} -c ${ARGN} -of${${objects_list}}) |
216 ARGS @${parameters_list_file} | 222 ARGS @${parameters_list_file} |
217 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | 223 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
218 DEPENDS ${ARGN} | 224 DEPENDS ${ARGN} |
219 COMMENT "" | 225 COMMENT "" |
220 ) | 226 ) |
221 endif(NOT COMBINED_OBJECT_FILE) | 227 endif(NOT SINGLE_D_OBJECT) |
222 add_custom_target(${target} DEPENDS "${${objects_list}}") | 228 add_custom_target(${target} DEPENDS "${${objects_list}}") |
223 endmacro(compile_d_files objects_list) | 229 endmacro(compile_d_files objects_list) |
224 | 230 |
225 ## Build example macro. | 231 ## Build example macro. |
226 ## name -- example name. | 232 ## name -- example name. |
229 ## Default value is "QtCore QtGui". | 235 ## Default value is "QtCore QtGui". |
230 ## params -- sources d files. | 236 ## params -- sources d files. |
231 ## Usage: | 237 ## Usage: |
232 ## build_example(ExampleName PACKAGES QtCore QtGui QtXml main.d another_d_file.d) | 238 ## build_example(ExampleName PACKAGES QtCore QtGui QtXml main.d another_d_file.d) |
233 macro(build_example name) | 239 macro(build_example name) |
234 unset(is_sources) | 240 set(is_sources) |
235 unset(is_libs) | 241 set(is_libs) |
236 set(qtd_libs ${core_lib_param} ${gui_lib_param}) | 242 set(qtd_libs ${core_lib_param} ${gui_lib_param}) |
237 foreach(param ${ARGN}) | 243 foreach(param ${ARGN}) |
238 if(is_libs) | 244 if(is_libs) |
239 string(REGEX REPLACE "Qt([A-Za-z0-9])" "\\1" param_package "${param}") | 245 string(REGEX REPLACE "Qt([A-Za-z0-9])" "\\1" param_package "${param}") |
240 if(${param_package} STREQUAL ${param}) | 246 if(${param_package} STREQUAL ${param}) |
241 unset(is_libs) | 247 set(is_libs) |
242 set(is_sources 1) | 248 set(is_sources 1) |
243 else(${param_package} STREQUAL ${param}) | 249 else(${param_package} STREQUAL ${param}) |
244 unset(is_founded) | 250 set(is_founded) |
245 foreach(package_big ${packages_big}) | 251 foreach(package_big ${packages_big}) |
246 string(TOLOWER ${package_big} package) | 252 string(TOLOWER ${package_big} package) |
247 if(${param_package} STREQUAL ${package_big}) | 253 if(${param_package} STREQUAL ${package_big}) |
248 set(qtd_libs ${qtd_libs} ${${package}_lib_param}) | 254 set(qtd_libs ${qtd_libs} ${${package}_lib_param}) |
249 set(is_founded 1) | 255 set(is_founded 1) |
275 set(output_native ${output}) | 281 set(output_native ${output}) |
276 make_native_path(output_native) | 282 make_native_path(output_native) |
277 ## Bug fix: Reverse libs for ldc. | 283 ## Bug fix: Reverse libs for ldc. |
278 if(D_IS_LLVM) | 284 if(D_IS_LLVM) |
279 set(qtd_libs_tmp ${qtd_libs}) | 285 set(qtd_libs_tmp ${qtd_libs}) |
280 unset(qtd_libs) | 286 set(qtd_libs) |
281 foreach(libs ${qtd_libs_tmp}) | 287 foreach(libs ${qtd_libs_tmp}) |
282 set(qtd_libs ${libs} ${qtd_libs}) | 288 set(qtd_libs ${libs} ${qtd_libs}) |
283 endforeach(libs ${qtd_libs_tmp}) | 289 endforeach(libs ${qtd_libs_tmp}) |
284 endif(D_IS_LLVM) | 290 endif(D_IS_LLVM) |
285 | |
286 add_custom_command(OUTPUT "${output}" | 291 add_custom_command(OUTPUT "${output}" |
287 COMMAND "${DC}" | 292 COMMAND "${DC}" |
288 ARGS ${D_FLAGS} ${libs_path} ${qtd_libs} ${objects} | 293 ARGS ${D_FLAGS} ${libs_path} ${qtd_libs} ${objects} |
289 -of${output_native} | 294 -of${output_native} |
290 DEPENDS ${objects} | 295 DEPENDS ${objects} |
304 link_directories(${CMAKE_BINARY_DIR}/CMakeFiles) | 309 link_directories(${CMAKE_BINARY_DIR}/CMakeFiles) |
305 | 310 |
306 foreach(package_big ${packages_big}) | 311 foreach(package_big ${packages_big}) |
307 string(TOLOWER ${package_big} package) | 312 string(TOLOWER ${package_big} package) |
308 ## Loading settings for package. | 313 ## Loading settings for package. |
309 unset(d_objs) | 314 set(d_objs) |
310 unset(cpp_objs) | 315 set(cpp_objs) |
311 unset(d_sources) | 316 set(d_sources) |
312 unset(cpp_sources) | 317 set(cpp_sources) |
313 unset(lib_name) | 318 set(lib_name) |
314 unset(link_cpp) | 319 set(link_cpp) |
315 unset(link_d) | 320 set(link_d) |
316 unset(cpp_files) | 321 set(cpp_files) |
317 unset(d_files) | 322 set(d_files) |
318 unset(classes) | 323 set(classes) |
319 unset(d_generated_files) | 324 set(d_generated_files) |
320 unset(link_example) | 325 set(link_example) |
321 include (${CMAKE_SOURCE_DIR}/build/${package}.txt) | 326 include (${CMAKE_SOURCE_DIR}/build/${package}.txt) |
322 | 327 |
323 ## Loading package sources list. | 328 ## Loading package sources list. |
324 foreach(d_source ${d_files}) | 329 foreach(d_source ${d_files}) |
325 set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/qt/${d_source}.d) | 330 set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/qt/${d_source}.d) |
331 set(cpp_sources ${cpp_sources} ${CMAKE_SOURCE_DIR}/cpp/${cpp_source}.cpp) | 336 set(cpp_sources ${cpp_sources} ${CMAKE_SOURCE_DIR}/cpp/${cpp_source}.cpp) |
332 endforeach(cpp_source) | 337 endforeach(cpp_source) |
333 set(classes ArrayOps ${classes}) | 338 set(classes ArrayOps ${classes}) |
334 foreach(class ${classes}) | 339 foreach(class ${classes}) |
335 set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}.d) | 340 set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}.d) |
336 set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp) | 341 set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp) |
342 add_sources_for_generating(${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp) | |
343 add_sources_for_generating(${CMAKE_BINARY_DIR}/qt/${package}/${class}.d) | |
337 endforeach(class) | 344 endforeach(class) |
338 add_sources_for_generating(${cpp_sources}) | |
339 | 345 |
340 ## Link CPP library. | 346 ## Link CPP library. |
341 set(lib_name ${D_LIB_PREFIX}qtd${package}${D_LIB_SUFFIX}) | 347 set(lib_name ${D_LIB_PREFIX}qtd${package}${D_LIB_SUFFIX}) |
342 add_library(cpp_${package} SHARED ${cpp_sources}) | 348 add_library(cpp_${package} SHARED ${cpp_sources}) |
343 | 349 |
409 set(${package}_lib_param -L-lqtd${package} -L-lQt${package_big}) | 415 set(${package}_lib_param -L-lqtd${package} -L-lQt${package_big}) |
410 foreach(link ${link_example}) | 416 foreach(link ${link_example}) |
411 set(${package}_lib_param ${${package}_lib_param} ${link}) | 417 set(${package}_lib_param ${${package}_lib_param} ${link}) |
412 endforeach(link ${link_example}) | 418 endforeach(link ${link_example}) |
413 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS) | 419 endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows AND D_IS_MARS) |
414 endforeach(package_big ${packages_big}) | 420 |
421 # set(regexp_str "(${CMAKE_BINARY_DIR}|${CMAKE_SOURCE_DIR})/([A-Za-z0-9\\-_\\\\/]+)[/]+([A-Za-z0-9\\-_\\\\]+).d") | |
422 # foreach(source ${d_sources}) | |
423 # # find_file(source ${source} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} | |
424 # # ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}) | |
425 # string(REGEX REPLACE ${regexp_str} "\\2" inc_path "${source}") | |
426 # string(REGEX REPLACE ${regexp_str} "\\3" file_name "${source}") | |
427 # set(interface_file_path ${CMAKE_BINARY_DIR}/include/${inc_path}) | |
428 # set(interface_file "${interface_file_path}/${file_name}.di") | |
429 # if(NOT "${file_name}" STREQUAL "QGlobal" AND GENERATE_DI_FILES) | |
430 # add_custom_command(OUTPUT "${interface_file}" | |
431 # COMMAND "${DC}" | |
432 # ARGS ${D_FLAGS} -o- -H -Hd${interface_file_path} ${source} | |
433 # COMMENT "Generating header for ${source}" | |
434 # DEPENDS ${source} | |
435 # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
436 # ) | |
437 # else(NOT "${file_name}" STREQUAL "QGlobal" AND GENERATE_DI_FILES) | |
438 # add_custom_command(OUTPUT "${interface_file}" | |
439 # COMMAND ${CMAKE_COMMAND} -E make_directory ${interface_file_path} | |
440 # COMMAND ${CMAKE_COMMAND} -E remove -f ${interface_file} | |
441 # COMMAND ${CMAKE_COMMAND} -E copy ${source} ${interface_file} | |
442 # COMMENT "" | |
443 # DEPENDS ${source} | |
444 # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | |
445 # ) | |
446 # endif(NOT "${file_name}" STREQUAL "QGlobal" AND GENERATE_DI_FILES) | |
447 # set(interfaces_list ${interfaces_list} ${interface_file_path}/${file_name}.di) | |
448 # endforeach(source) | |
449 endforeach(package_big ${packages_big}) | |
450 # add_custom_target(generate_headers DEPENDS ${interfaces_list}) | |
415 | 451 |
416 ##-------------------------------------------- | 452 ##-------------------------------------------- |
417 ## Build other parts of the QtD. | 453 ## Build other parts of the QtD. |
418 ##-------------------------------------------- | 454 ##-------------------------------------------- |
419 if(BUILD_EXAMPLES) | 455 if(BUILD_EXAMPLES) |