root/CMakeLists.txt

Revision 402:e67ce7c21758, 24.5 kB (checked in by Eldar Insafutdinov, 1 year ago)

gdc & 64 bit changes

Line 
1 cmake_minimum_required(VERSION 2.6)
2 PROJECT(qtd CXX C)
3
4 # Debug and release flags.
5 if (NOT CMAKE_BUILD_TYPE)
6     set(CMAKE_BUILD_TYPE Release)
7 endif ()
8
9 if(${CMAKE_BUILD_TYPE} MATCHES [dD][eE][bB][uU][gG])
10     set(CMAKE_BUILD_TYPE Debug)
11     #set( SUFFIXLIB "${SUFFIXLIB}-debug" )
12     #set( SUFFIXBIN "${SUFFIXBIN}-debug" )
13     add_definitions(-DDEBUG)
14 elseif (NOT ${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS])
15     message(STATUS "Only debug and release configurations are supported. The configuration is changed to 'Release'")
16     set(CMAKE_BUILD_TYPE Release)
17 endif ()
18
19 if (${CMAKE_BUILD_TYPE} MATCHES [rR][eE][lL][eE][aA][sS])
20     #add_definitions(-UNO_DEBUG)
21 endif()
22
23 ##########################################################
24 ## Build generator.
25 ##########################################################
26 if (NOT SECOND_RUN)
27
28 option(ALLOW_IN_SOURCE_BUILDS "Allow in-source builds" "OFF")
29 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT ALLOW_IN_SOURCE_BUILDS)
30     message(FATAL_ERROR "In-source builds are not allowed. "
31     "Please create a directory and run cmake from there, passing the path "
32     "to this source directory as the last argument. "
33     "This process created the file `CMakeCache.txt` and the directory `CMakeFiles'. Please delete them. "
34     "Or you can restart cmake with `-DALLOW_IN_SOURCE_BUILDS=1`, but it is not recommended."
35     )
36 endif ()
37
38 FIND_PACKAGE(Qt4 REQUIRED)
39 set(QT_USE_QTMAIN false)
40 set(QT_USE_QTGUI false)
41
42 ##--------------------------------------------
43 ## Settings.
44 ##--------------------------------------------
45
46 ## Options.
47 option(BUILD_EXAMPLES "Build examples" "OFF")
48 # option(BUILD_SHARED_LIBRARIES "Build shared library (very experemental and only for ldc)" "OFF")
49
50 if (CMAKE_HOST_WIN32)
51     set(CPP_SHARED true CACHE INTERNAL "")
52 else()
53     option(CPP_SHARED "Build C++ part into shared libraries" "ON")
54 endif()
55
56 option(BUILD_TOOLS "Build tools" "ON")
57 #option(GENERATE_DI_FILES "Generate *.di files with DC -H command" "OFF")
58 set(GENERATE_DI_FILES OFF) ## Very experimental option. Temporarily disabled.
59 option(VERBOSE_DEBUG "Verbose debug" "OFF")
60
61 set(all_packages Core Gui OpenGL Xml Svg Network WebKit Qwt CACHE INTERNAL "")
62
63 ## Init D toolkit.
64 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
65 FIND_PACKAGE(D REQUIRED)
66
67 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "")
68     set(CMAKE_INSTALL_PREFIX
69     ${DC_PATH} CACHE PATH "QtD install prefix"
70     )
71 endif()
72
73 set(D_MODULE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/d" CACHE PATH "D module install path" )
74
75 # Check D compiler version
76 if(D_VERSION EQUAL "1")
77     if (D_FRONTEND LESS "050")
78     message(STATUS "Minimum required version of D compiler is 1.050 (or compiler based on this version)")
79     endif(D_FRONTEND LESS "050")
80     set(D_TARGET d1-tango CACHE INTERNAL "")
81 elseif(D_VERSION EQUAL "2")
82     set(D_TARGET d2-phobos CACHE INTERNAL "")
83 endif()
84
85 # System specific settings.
86 if(CMAKE_HOST_WIN32)
87     set(implib implib)
88     find_program(IMPLIB ${implib})
89     if (NOT IMPLIB)
90         message(FATAL_ERROR "implib is not found. You can donwload it from http://ftp.digitalmars.com/bup.zip")
91     endif ()
92 endif()
93
94 if(CPP_SHARED)
95     set(GEN_OPT ${GEN_OPT} --cpp-shared)
96     add_definitions(-DCPP_SHARED)
97 endif()
98
99 set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ./)
100 set(GEN_OPT ${GEN_OPT} --d-target=${D_TARGET})
101
102 set(packages CACHE INTERNAL "")
103 foreach(package_big ${all_packages})
104     string(TOLOWER ${package_big} package)
105     string(TOUPPER ${package_big} package_upper)
106     set(package_default_option "ON")
107     if(${package_big} STREQUAL "Qwt")
108         set(package_default_option "OFF")
109     endif()
110     option(BUILD_QT_${package_upper} "Build Qt${package_big}" ${package_default_option})
111     if(BUILD_QT_${package_upper})
112         set(packages ${packages} ${package_big})
113     endif()
114 endforeach()
115
116 set(QWT_INCLUDE_PATH "/usr/include/qwt-qt4" CACHE STRING "Qwt include path")
117 if(CMAKE_HOST_WIN32)
118     set(QWT_LIB_PATH "" CACHE STRING "Qwt lib path")
119 endif()
120 set(inc_paths "")
121
122 if(CMAKE_HOST_WIN32)
123     set(sep "*")
124 else()
125     set(sep ":")
126 endif()
127
128 if(BUILD_QT_QWT)
129     set(inc_paths ${inc_paths}${sep}${QWT_INCLUDE_PATH}${sep})
130 endif()
131
132 add_subdirectory(generator)
133
134 add_custom_target(main ALL)
135 add_dependencies(main dgen)
136
137 if(${CMAKE_GENERATOR} STREQUAL "NMake Makefiles")
138     set(make_util nmake)
139 elseif(${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles" OR
140     ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
141     set(make_util $(MAKE))
142 else()
143     message(FATAL_ERROR "${CMAKE_GENERATOR} is not supported")
144 endif()
145
146 if(${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
147     set(cd_path ${CMAKE_SOURCE_DIR})
148 else()
149     set(cd_path ${CMAKE_BINARY_DIR}/build)
150 endif()
151
152 make_native_path(cd_path)
153 add_custom_command(TARGET main POST_BUILD
154     COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${CMAKE_BINARY_DIR}/build
155     COMMAND cd  ARGS ${cd_path} && ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -DSECOND_RUN=1 ${CMAKE_SOURCE_DIR} && ${make_util}
156     COMMENT ""
157     )
158
159 ## "Make install" command.
160 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/build)
161
162 set(native_build_path ${CMAKE_BINARY_DIR}/build)
163 make_native_path(native_build_path)
164 add_custom_target(install
165     COMMAND cd ${native_build_path} && ${make_util} install
166     COMMENT ""
167     )
168 add_dependencies(install preinstall)
169
170 ##########################################################
171 ## Build QtD.
172 ##########################################################
173 else(NOT SECOND_RUN)
174
175 PROJECT(qtd CXX C)
176 if(NOT ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
177     load_cache(${CMAKE_BINARY_DIR}/.. INCLUDE_INTERNALS all_packages QTD_VERSION_STR QTD_VERSION CPP_SHARED D_MODULE_INSTALL_DIR)
178 endif()
179 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
180 FIND_PACKAGE(D REQUIRED)
181 FIND_PACKAGE(Qt4 REQUIRED)
182
183 set(QTD_VERSION_STR ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
184 math(EXPR QTD_VERSION "(${QT_VERSION_MAJOR} << 16) + (${QT_VERSION_MINOR} << 8) + ${QT_VERSION_PATCH}")
185
186 include_directories(${QT_INCLUDES} ${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
187 if(BUILD_QT_QWT)
188     include_directories(${QWT_INCLUDE_PATH})
189 endif()
190
191 # System specifc settings.
192 if(CMAKE_HOST_WIN32)
193     string(REGEX REPLACE ".dll([A-Za-z\\.0-9]+)" "\\1" CMAKE_IMPORT_LIBRARY_SUFFIX "${CMAKE_IMPORT_LIBRARY_SUFFIX}")
194 endif()
195
196 if(CPP_SHARED)
197     set(D_FLAGS -version=QtdCppShared)
198     add_definitions(-DCPP_SHARED)
199 endif()
200
201 if(UNITTEST)
202     add_d_versions(QtdUnittest)
203     set(D_FLAGS ${D_FLAGS} -unittest)
204 endif()
205
206 if(VERBOSE_DEBUG)
207     add_d_debugs(QtdVerbose)
208 endif()
209
210 if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
211     add_d_debugs(QtdDebug)
212 endif()
213
214 ## Bootstrap settings for QtD.
215 set(DRCC ${CMAKE_BINARY_DIR}/tools/drcc/drcc CACHE INTERNAL "")
216 set(DUIC ${CMAKE_BINARY_DIR}/tools/duic/duic CACHE INTERNAL "")
217 set(QTD_IMPORT_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/d${D_VERSION} CACHE INTERNAL "")
218 set(QTD_LIBRARIES_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "")
219
220 ##--------------------------------------------
221 ## Macros and functions.
222 ##--------------------------------------------
223
224 macro(load_generated_classes )
225     include(${CMAKE_BINARY_DIR}/cpp/qt_${package}/qt_${package}.txt)
226 endmacro()
227
228 macro(qtd_add_resource output)
229     set (params NAME OPTIONS)
230     qtd_parse_params (RESOURCES  params ${ARGN})
231     if(NAME_tmp)
232         set(OPTIONS_tmp ${OPTIONS_tmp} -name ${NAME_tmp})
233     endif()
234     qtd_command ("${output}" "${DRCC}" "${OPTIONS_tmp}" "qrc_"
235     "Generate" ${RESOURCES_tmp})
236 endmacro()
237
238 macro(qtd_wrap_ui output)
239     set (params OPTIONS)
240     qtd_parse_params (UI params ${ARGN})
241     qtd_command ("${output}" "${DUIC}" "${OPTIONS_tmp}"  "uic_"
242     "Generate" ${UI_tmp})
243 endmacro()
244
245 macro(qtd_command output command options prefix comment)
246     foreach(file "${ARGN}")
247         ## Test if the input file exists
248         get_filename_component(file_path ${file} PATH)
249         get_filename_component(file_name ${file} NAME_WE)
250         get_filename_component(file_ext ${file} EXT)
251
252         set(out ${CMAKE_CURRENT_BINARY_DIR}/${file_path}${prefix}${file_name}.d)
253         add_custom_command(OUTPUT "${out}"
254             COMMAND "${command}"
255             ARGS ${options} ${file} -o ${out}
256             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
257             DEPENDS ${file}
258             COMMENT "${comment} ${file}"
259             )
260         set(${output} ${${output}} ${out})
261     endforeach()
262 endmacro()
263
264 ## Parses the parameters list.
265 macro(qtd_parse_params default params)
266     set(type_tmp ${default})
267     set(params_tmp ${default} ${${params}})
268     foreach(param_tmp ${params_tmp})
269         set(${param_tmp}_tmp )
270     endforeach()
271     foreach(arg_tmp ${ARGN})
272         set(found_type_tmp)
273         if(NOT found_type_tmp)
274             foreach(param_tmp ${params_tmp})
275                 if(arg_tmp STREQUAL param_tmp)
276                     set(type_tmp ${param_tmp})
277                     set(found_type_tmp 1)
278                     break(param_tmp ${params_tmp})
279                 endif()
280             endforeach()
281         endif()
282         if(NOT found_type_tmp)
283             set(${type_tmp}_tmp ${${type_tmp}_tmp} ${arg_tmp})
284         endif()
285     endforeach()
286 endmacro()
287
288 ## Adds a new example.
289 ## name -- example name.
290 ## Options:
291 ##    PACKAGES -- list of packages for link to example (for example, QtCore QtGui QtOpenGL).
292 ##        Default value is "QtCore QtGui".
293 ## params -- sources d files.
294 ## Usage:
295 ##    build_example(ExampleName PACKAGES QtCore QtGui QtXml  main.d another_d_file.d)
296 macro(build_example name)
297     set (params UIC RESOURCES PACKAGES)
298     qtd_parse_params (SOURCES params ${ARGN})
299
300     if(NOT PACKAGES_tmp)
301         set(PACKAGES_tmp QtCore QtGui)
302     endif()
303
304     if(RESOURCES_tmp)
305         if(NOT BUILD_TOOLS)
306             message(STATUS "Example '${name}' requires drcc. Example will not be built")
307             return(build_example name)
308         endif()
309         qtd_add_resource(res_sources ${RESOURCES_tmp} NAME ${name} )
310     endif()
311
312     if(UIC_tmp)
313         if(NOT BUILD_TOOLS)
314             message(STATUS "Example '${name}' requires drcc. Example will not be built")
315             return(build_example name)
316         endif()
317         qtd_wrap_ui(uic_sources ${UIC_tmp})
318     endif()
319
320     foreach(package ${PACKAGES_tmp})
321         string(REGEX REPLACE "Qt([A-Za-z0-9])" "\\1" req "${package}")
322         set(is_found)
323         foreach(package_big ${packages_big})
324             string(TOLOWER ${package_big} package)
325             if(${req} STREQUAL ${package_big})
326                 set(is_found 1)
327                 break(package_big ${packages_big})
328             endif()
329         endforeach()
330         if(NOT is_found)
331             message(STATUS "Example '${name}' requires the package '${req}', but it is not active. Example will not be built")
332             return(build_example name)
333         else()
334             set(qtd_libs ${${package}_lib_param} ${qtd_libs})
335             if(CPP_SHARED AND CMAKE_HOST_UNIX)
336                 set(qtd_libs cpp_${package} ${qtd_libs})
337             endif()
338         endif()
339     endforeach()
340     add_d_program(${name} ${SOURCES_tmp} NO_DEPS_SOURCES ${res_sources} ${uic_sources}
341     DEPENDS ${res_sources} INCLUDES ${QTD_IMPORT_PATH} ${CMAKE_CURRENT_BINARY_DIR}
342     LIB_PATHS ${QTD_LIBRARIES_PATH} ${CMAKE_SOURCE_DIR}/lib ${QT_LIBRARY_DIR} LIBS ${qtd_libs})
343     ## TODO: Uncomment.
344     #if(STRIP AND ${CMAKE_BUILD_TYPE} EQUAL "Release" AND CMAKE_HOST_UNIX) ##
345     #    add_custom_command(TARGET example_${name} POST_BUILD COMMAND "${STRIP}" ARGS "${output}")
346     #endif(STRIP AND ${CMAKE_BUILD_TYPE} EQUAL "Release" AND CMAKE_HOST_UNIX)
347     add_dependencies(examples ${name})
348     add_dependencies(${name} allpackages tools)
349 endmacro()
350
351 ##--------------------------------------------
352 ## Build and install the QtD libraries.
353 ##--------------------------------------------
354
355 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
356 add_custom_target(allpackages)
357 link_directories(${CMAKE_BINARY_DIR}/CMakeFiles)
358
359 foreach(package_big ${all_packages})
360     string(TOLOWER ${package_big} package)
361     string(TOUPPER ${package} package_upper)
362     ## Load settings for the package.
363     set(required)
364     set(d_objs)
365     set(cpp_objs)
366     set(d_sources)
367     set(cpp_sources)
368     set(lib_name)
369     set(link_cpp)
370     set(link_d)
371     set(cpp_files)
372     set(cpp_generated_files)
373     set(d_qt_files)
374     set(d_qtd_files)
375     set(classes)
376     set(d_generated_files)
377     set(link_example)
378     include (${CMAKE_SOURCE_DIR}/build/${package}.txt)
379
380     set(all_req_found 1)
381     if(BUILD_QT_${package_upper})
382         foreach(req ${required})
383             set(req_found)
384             foreach(pack ${packages_big})
385             if(${pack} STREQUAL ${req})
386                 set(req_found 1)
387             endif()
388             endforeach(pack ${packages})
389             if(NOT req_found)
390                 set(req_found)
391                 foreach(pack ${all_packages})
392                     if(${pack} STREQUAL ${req})
393                         set(req_found 1)
394                     endif(${pack} STREQUAL ${req})
395                 endforeach(pack ${all_packages})
396                 if(req_found)
397                     message(STATUS "Package '${package_big}' requires '${req}', but it is not active")
398                 else()
399                     message(STATUS "Package '${package_big}' requires '${req}', but it is not found")
400                 endif()
401                 set(all_req_found)
402             endif()
403         endforeach(req ${required})
404     else(BUILD_QT_${package_upper})
405         set(all_req_found)
406     endif(BUILD_QT_${package_upper})
407
408     if("${all_req_found}" EQUAL 1)
409         set(packages_big ${packages_big} ${package_big})
410         set(packages ${packages} ${package})
411         ## Load a package sources list.
412         foreach(d_source ${package}/ArrayOps2 ${d_generated_files})
413             set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}.d)
414             if(EXISTS ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d)
415                 set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${d_source}_aux.d)
416             endif()
417         endforeach()
418         set(classes ArrayOps ${classes})
419         foreach(class ${classes})
420             set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}.d)
421             set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/qt_${package}/${class}_shell.cpp)
422             if(EXISTS ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d)
423                 set(d_sources ${d_sources} ${CMAKE_BINARY_DIR}/qt/${package}/${class}_aux.d)
424             endif()
425         endforeach()
426         set(files_for_gen ${files_for_gen} ${cpp_sources} ${d_sources})
427
428         foreach (cpp_source ${cpp_files})
429             set(cpp_sources ${cpp_sources} ${CMAKE_SOURCE_DIR}/cpp/${cpp_source}.cpp)
430         endforeach()
431         foreach (cpp_source ${cpp_generated_files})
432             set(cpp_sources ${cpp_sources} ${CMAKE_BINARY_DIR}/cpp/${cpp_source}.cpp)
433         endforeach()
434         foreach(d_source ${d_qt_files})
435             set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/d${D_VERSION}/qt/${d_source}.d)
436         endforeach()
437         foreach(d_source ${d_qtd_files})
438             set(d_sources ${d_sources} ${CMAKE_SOURCE_DIR}/d${D_VERSION}/qtd/${d_source}.d)
439         endforeach()
440
441         if(NOT GENERATE_DI_FILES)
442             foreach(d_source ${d_sources})
443             get_filename_component(path ${d_source} PATH)
444             get_filename_component(name ${d_source} NAME_WE)
445             regex_safe_string(cbd_safe_tmp ${CMAKE_CURRENT_BINARY_DIR})
446             regex_safe_string(csd_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR})
447             regex_safe_string(ver_safe_tmp ${CMAKE_CURRENT_SOURCE_DIR}/d${D_VERSION})
448             set(regexp_str_tmp "(${ver_safe_tmp}/|${cbd_safe_tmp}/|${csd_safe_tmp}/|)(.+)")
449             string(REGEX REPLACE ${regexp_str_tmp} "\\2" ins_path "${path}")
450             install(FILES ${d_source} DESTINATION ${D_MODULE_INSTALL_DIR}/${ins_path} COMPONENT qtd RENAME ${name}.di)
451             endforeach()
452         endif(NOT GENERATE_DI_FILES)
453
454         ### Build the CPP part.
455         if(CPP_SHARED)
456             set(cpp_method SHARED)
457         else()
458             set(cpp_method STATIC)
459         endif()
460         add_library(cpp_${package} ${cpp_method} ${cpp_sources})
461
462         set_target_properties(cpp_${package} PROPERTIES
463             LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
464             RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
465             ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
466             COMPILE_DEFINITIONS QTD_${package_upper}
467         )
468
469         if(CMAKE_HOST_WIN32)
470             set_target_properties(cpp_${package} PROPERTIES
471                 LINK_FLAGS -Wl,-enable-auto-import
472             )
473         endif()
474
475         set(link_cpp ${link_cpp} ${QT_QT${package_upper}_LIBRARY})
476         if(NOT CPP_SHARED)
477             ## Get an objects list. It will be used in building the D part.
478             foreach(cpp_source ${cpp_sources})
479             set(cpp_source ${cpp_source})
480             obj_path(cpp_source)
481             set(cpp_objs ${cpp_objs} ${CMAKE_BINARY_DIR}/CMakeFiles/cpp_${package}.dir/${cpp_source}${CMAKE_CXX_OUTPUT_EXTENSION})
482             endforeach()
483         endif()
484
485         ## Settings for the D part.
486         set(lib_name qtd${package})
487         # if(BUILD_SHARED_LIBRARIES)
488         #    set(lib lib/${CMAKE_SHARED_LIBRARY_PREFIX}${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX})
489         #    set(build_type SHARED)
490         # else()
491             set(lib lib/${D_LIB_PREFIX}${lib_name}${D_LIB_SUFFIX})
492             set(build_type STATIC)
493         # endif()
494
495         ## Package dependencies.
496         foreach(req ${required})
497             set(is_found)
498             foreach(pack ${packages_big})
499                 if("${pack}" STREQUAL "${req}")
500                     set(is_found 1)
501                     break(pack ${packages_big})
502                 endif()
503             endforeach()
504             if(NOT is_found)
505                 message(FATAL_ERROR "Package ${package_big} requires ${req}, but it is not found")
506             endif()
507             string(TOUPPER ${req} req_upper)
508             string(TOLOWER ${req} req_lower)
509             set(link_cpp ${link_cpp} cpp_${req_lower} ${QT_QT${req_upper}_LIBRARY})
510         endforeach()
511
512         if(${package_big} STREQUAL "Qwt" AND CMAKE_HOST_WIN32)
513             set(qwt_release_lib ${QWT_LIB_PATH}/libqwt5.a)
514             set(qwt_debug_lib ${QWT_LIB_PATH}/libqwtd5.a)
515             if(EXISTS ${qwt_release_lib})
516                 set(qwt_lib ${qwt_release_lib})
517             elseif(EXISTS ${qwt_debug_lib})
518                 set(qwt_lib ${qwt_debug_lib})
519             endif()
520             set(link_cpp ${link_cpp} ${qwt_lib})
521         endif()
522
523         target_link_libraries(cpp_${package} ${link_cpp} )
524         set(d_objs ${d_objs} ${objects})
525
526         if(CPP_SHARED)
527             set(cpp_lib ${CMAKE_BINARY_DIR}/lib/libcpp_${package}${CMAKE_SHARED_LIBRARY_SUFFIX})
528             install(FILES ${cpp_lib} COMPONENT qtd DESTINATION lib)
529
530             if(CMAKE_HOST_WIN32)
531                 ## Create an implib library which will be linked to the D part.
532                 set(cpp_lib_native ${cpp_lib})
533                 make_native_path(cpp_lib_native)
534                 set(d_implib ${CMAKE_BINARY_DIR}/CMakeFiles/${package}.dir/cpp_${package}.lib)
535                 set(d_implib_native ${d_implib})
536                 make_native_path(d_implib_native)
537                 add_custom_command(
538                     OUTPUT "${d_implib}"
539                     COMMAND "${IMPLIB}"
540                     ARGS  /system /PAGESIZE:64 ${d_implib_native} ${cpp_lib_native}
541                     DEPENDS  "cpp_${package}"
542                     COMMENT "Creating implib ${lib_name}"
543                     )
544             endif()
545         else()
546             set(${package}_lib_param Qt${package_big})
547         endif()
548
549         ## Link the D part.
550         add_d_target(${lib_name} NOT_DETECT_DEPENDS TYPE ${build_type} INCLUDES ${QTD_IMPORT_PATH} SOURCES ${d_sources} OBJECTS ${cpp_objs} ${d_implib}
551               OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib DEPENDS ${d_implib} )
552         install(FILES ${CMAKE_BINARY_DIR}/${lib} COMPONENT qtd DESTINATION lib)
553         ## Paths for the QtD libs. It is necessary for examples.
554         set(${package}_lib_param qtd${package} ${${package}_lib_param} ${link_example})
555
556         ## Generate dependences for make (or nmake).
557         add_custom_target(${package})
558         add_dependencies(${package} ${lib_name})
559
560         add_dependencies(${lib_name} cpp_${package})
561         foreach(depend ${required})
562             string(TOLOWER ${depend} depend)
563             add_dependencies(cpp_${package} cpp_${depend})
564             add_dependencies(${package} ${depend})
565         endforeach()
566         add_dependencies(allpackages ${package})
567
568         ## TODO: Do we need to generate *.di files?
569         if(GENERATE_DI_FILES)
570             regexseafestring(cbd_safe ${CMAKE_BINARY_DIR})
571             regexseafestring(csd_safe ${CMAKE_SOURCE_DIR})
572             set(regexp_str "(${csd}/qt/d${D_VERSION}|${csd_safe}|${cbd_safe})/([A-Za-z0-9\\-_\\\\/]+)[/]+([A-Za-z0-9\\-_\\\\]+).d")
573             foreach(source ${d_sources})
574             #     find_file(source ${source} PATHS ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
575             #           ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
576                 string(REGEX REPLACE ${regexp_str} "\\2" inc_path "${source}")
577                 string(REGEX REPLACE ${regexp_str} "\\3" file_name "${source}")
578                 set(interface_file_path ${CMAKE_BINARY_DIR}/d/${inc_path})
579                 set(interface_file "${interface_file_path}/${file_name}.di")
580                 if(NOT "${file_name}" STREQUAL "QGlobal")
581                     add_custom_command(OUTPUT "${interface_file}"
582                         COMMAND "${DC}"
583                         ARGS ${D_FLAGS} -o- -H -Hd${interface_file_path} ${source}
584                         COMMENT "Generating header for ${source}"
585                         DEPENDS ${source}
586                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
587                         )
588                 else(NOT "${file_name}" STREQUAL "QGlobal") ## The DMD frontend crashes on this file.
589                     add_custom_command(OUTPUT "${interface_file}"
590                         COMMAND ${CMAKE_COMMAND} -E make_directory ${interface_file_path}
591                         COMMAND ${CMAKE_COMMAND} -E remove -f ${interface_file}
592                         COMMAND ${CMAKE_COMMAND} -E copy ${source} ${interface_file}
593                         COMMENT ""
594                         DEPENDS ${source}
595                         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
596                         )
597                 endif(NOT "${file_name}" STREQUAL "QGlobal" AND GENERATE_DI_FILES)
598                 set(interfaces_list ${interfaces_list} ${interface_file_path}/${file_name}.di)
599                 install(FILES ${interface_file} COMPONENT qtd DESTINATION ${D_MODULE_INSTALL_DIR}/${inc_path})
600             endforeach()
601         endif()
602     endif()
603 endforeach()
604 if(GENERATE_DI_FILES)
605     add_custom_target(generate_headers ALL DEPENDS ${interfaces_list})
606 endif(GENERATE_DI_FILES)
607
608 set(CPACK_COMPONENTS_ALL qtd qtd_tools)
609
610 ##--------------------------------------------
611 ## Build other parts of the QtD.
612 ##--------------------------------------------
613
614 if(BUILD_TOOLS)
615     add_custom_target(tools ALL)
616     add_subdirectory(tools)
617     add_dependencies(tools drcc duic)
618 endif(BUILD_TOOLS)
619
620 if(BUILD_EXAMPLES)
621     add_custom_target(examples ALL)
622     add_dependencies(examples allpackages tools)
623     add_subdirectory(demos)
624     add_subdirectory(examples)
625 endif(BUILD_EXAMPLES)
626
627 set(SECOND_RUN 0 CACHE INTERNAL "")
628
629 endif(NOT SECOND_RUN)
630
631 ##--------------------------------------------
632 ## CPack.
633 ##--------------------------------------------
634 set(CPACK_PACKAGE_VERSION_PATCH 1)
635 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "QtD is a D binding to the Qt application and UI framework.")
636 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/changelog.txt")
637 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/license.txt")
638 set(CPACK_PACKAGE_VENDOR "QtD team")
639 set(CPACK_PACKAGE_CONTACT "qtd@qtd.org")
640 set(CPACK_PACKAGE_VERSION "0.6")
641 set(CPACK_PACKAGE_INSTALL_DIRECTORY "qtd ${CPACK_PACKAGE_VERSION}")
642 set(CPACK_PACKAGE_FILE_NAME "qtd-${CPACK_PACKAGE_VERSION}")
643 set(CPACK_SOURCE_PACKAGE_FILE_NAME "qtd-${CPACK_PACKAGE_VERSION}")
644 if(CMAKE_HOST_WIN32)
645     set(CPACK_GENERATOR "ZIP")
646 elseif(CMAKE_HOST_UNIX)
647     set(CPACK_GENERATOR "TBZ2;DEB")
648 endif()
649 include(CPack)
Note: See TracBrowser for help on using the browser.