annotate CMakeLists.txt @ 379:a795eeb3b21f

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