Warning, /graphics/kst-plot/cmake/modules/KstMacros.cmake is written in an unsupported language. File is not indexed.

0001 # ***************************************************************************
0002 # *                                                                         *
0003 # *   Copyright : (C) 2010 The University of Toronto                        *
0004 # *   email     : netterfield@astro.utoronto.ca                             *
0005 # *                                                                         *
0006 # *   Copyright : (C) 2010 Peter Kümmel                                     *
0007 # *   email     : syntheticpp@gmx.net                                       *
0008 # *                                                                         *
0009 # *   This program is free software; you can redistribute it and/or modify  *
0010 # *   it under the terms of the GNU General Public License as published by  *
0011 # *   the Free Software Foundation; either version 2 of the License, or     *
0012 # *   (at your option) any later version.                                   *
0013 # *                                                                         *
0014 # ***************************************************************************
0015 
0016 include(MergedFilesBuild)
0017 include(KstPchSupport)
0018 
0019 
0020 macro(kst_dbg)
0021         foreach(it ${ARGN})
0022                 message(STATUS "dgb: ${it} = ${${it}}")
0023         endforeach()
0024 endmacro()
0025 
0026 
0027 macro(kst_init prefix name_base)
0028         set(kst_name ${prefix}${name_base})
0029         set(kst_name_base ${name_base})
0030         set(kst_${kst_name}_dont_merge)
0031         set(kst_${kst_name}_ignore)
0032         set(kst_${kst_name}_info_files)
0033 endmacro()
0034 
0035 
0036 macro(kst_revision_project_name name)
0037         set(kst_revision_project ${name})
0038 endmacro()
0039 
0040 
0041 macro(kst_revision_add_dependency)
0042         if(kst_revision_project)
0043                 add_dependencies(${kst_name} ${kst_revision_project})
0044         endif()
0045 endmacro()
0046 
0047 
0048 macro(kst_files_find folder)
0049         set(_folder ${kst_dir}/${folder})
0050         file(GLOB _sources     ${_folder}/*.c)
0051         file(GLOB _sources_cpp ${_folder}/*.cpp)
0052         file(GLOB _headers     ${_folder}/*.h)
0053         file(GLOB _ui_files    ${_folder}/*.ui)
0054         set(kst_${kst_name}_folder  ${_folder})
0055         kst_files_remove(_sources     ${kst_${kst_name}_ignore})
0056         kst_files_remove(_sources_cpp ${kst_${kst_name}_ignore})
0057         kst_files_remove(_headers     ${kst_${kst_name}_ignore})
0058         set(_mocs)
0059         if(kst_qt5)
0060                 qt5_wrap_cpp(_mocs ${_headers} OPTIONS "-nw")
0061                 qt5_wrap_cpp(_mocs ${_headers} OPTIONS "-nw")
0062                 set(_uis)
0063                 qt5_wrap_ui(_uis ${_ui_files})
0064         else()
0065                 qt4_wrap_cpp(_mocs ${_headers} OPTIONS "-nw")
0066                 qt4_wrap_cpp(_mocs ${_headers} OPTIONS "-nw")
0067                 set(_uis)
0068                 qt4_wrap_ui(_uis ${_ui_files})
0069         endif()
0070         set(kst_${kst_name}_sources_not_generated ${_sources} ${_sources_cpp})
0071         set(kst_${kst_name}_sources ${_sources} ${_sources_cpp} ${_mocs} ${_uis})
0072         set(kst_${kst_name}_headers ${_headers})
0073         set(kst_${kst_name}_mocs    ${_mocs})
0074         set(kst_${kst_name}_ui_files ${_ui_files})
0075         set(kst_${kst_name}_uis     ${_uis})
0076         set(kst_${kst_name}_includes ${_folder} ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "Include dir for ${kst_name}" FORCE)
0077         source_group("Ui" FILES ${_mocs} ${_ui_files})
0078         source_group("Generated" FILES ${_mocs} ${_uis})
0079 endmacro()
0080 
0081 
0082 macro(kst_dont_merge)
0083         set(kst_${kst_name}_dont_merge)
0084         foreach(_it ${ARGV})
0085                 set(kst_${kst_name}_dont_merge ${kst_${kst_name}_dont_merge} ${kst_${kst_name}_folder}/${_it})
0086         endforeach()
0087 endmacro()
0088 
0089 
0090 
0091 macro(kst_add_executable)
0092         set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ${kst_build_dir}/bin)
0093         include_directories(${kst_${kst_name}_folder} ${CMAKE_CURRENT_BINARY_DIR})
0094         add_executable(${kst_name} ${ARGN} ${kst_${kst_name}_sources} ${kst_${kst_name}_headers} ${kst_${kst_name}_info_files})
0095         target_link_libraries(${kst_name} ${kst_qtmain_library})
0096         set_property(TARGET ${kst_name} PROPERTY DEBUG_POSTFIX ${kst_debug_postfix})
0097         kst_revision_add_dependency()
0098         kst_flat_source_group(${kst_${kst_name}_headers} ${kst_${kst_name}_sources_not_generated})
0099 endmacro()
0100 
0101 
0102 macro(kst_add_test _source_file)
0103         set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ${kst_build_dir}/bin)
0104         get_filename_component(_file_name ${_source_file} NAME)
0105         if(CMAKE_GENERATOR MATCHES Ninja) 
0106         set(_moced ${CMAKE_CURRENT_BINARY_DIR}/moc_${_file_name}) # ninja generator bug
0107         else()
0108         set(_moced moc_${_file_name})
0109         endif()
0110         qt4_generate_moc(${_source_file} ${_moced})
0111         set_source_files_properties(${_source_file} PROPERTIES OBJECT_DEPENDS ${_moced}) # moc on source file changes
0112         add_executable(${kst_name} ${_source_file})
0113         set_target_properties(${kst_name} PROPERTIES DEPEND ${_moced})
0114         target_link_libraries(${kst_name} ${QT_QTTEST_LIBRARY})
0115         set_property(TARGET ${kst_name} PROPERTY DEBUG_POSTFIX ${kst_debug_postfix})
0116         kst_link(${libcore} ${libmath} ${libapp} ${libwidgets} ${QT_QTTEST_LIBRARY})
0117         if(kst_debug_postfix)
0118                 set_target_properties(${kst_name} PROPERTIES DEBUG_POSTFIX ${kst_debug_postfix})
0119         endif()
0120         add_test(NAME ${kst_name} COMMAND ${kst_name})
0121 endmacro()
0122 
0123 
0124 macro(kst_install_executable)
0125         install(TARGETS ${kst_name}
0126                 RUNTIME DESTINATION bin COMPONENT Runtime
0127                 BUNDLE  DESTINATION .   COMPONENT Runtime)
0128 endmacro()
0129 
0130 
0131 macro(kst_add_library type)
0132         set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${kst_build_dir}/bin)
0133         set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${kst_build_dir}/${kst_install_libdir})
0134         include_directories(${kst_${kst_name}_folder} ${CMAKE_CURRENT_BINARY_DIR})
0135         string(TOUPPER BUILD_kst${kst_name_base} _build_macro)
0136         add_definitions(-D${_build_macro})
0137         if(kst_pch)
0138                 set(pch kst${kst_name_base}_pch)
0139                 configure_file(${kst_${kst_name}_folder}/${pch} ${CMAKE_CURRENT_BINARY_DIR}/${pch}.h COPYONLY)
0140                 #add_definitions(-DKST_PCH_RECURSIVE) # only some percents faster
0141                 kst_add_pch_rule(${CMAKE_CURRENT_BINARY_DIR}/${pch}.h kst_${kst_name}_sources ${type})
0142         endif()
0143         if(kst_merge_files)
0144                 if(kst_merge_rebuild)
0145                         set(merged_files_rebuild 1)
0146                 endif()
0147                 kst_files_remove(kst_${kst_name}_sources ${kst_${kst_name}_dont_merge})
0148                 kst_files_remove(kst_${kst_name}_dont_merge ${kst_${kst_name}_ignore})
0149                 kst_files_remove(kst_${kst_name}_sources_not_generated ${kst_${kst_name}_dont_merge})
0150                 merged_files_build(merged kst_${kst_name}_sources)
0151                 set(depends_moc_uic ${kst_${kst_name}_headers} ${kst_${kst_name}_uis} ${kst_${kst_name}_ui_files} ${kst_${kst_name}_mocs})
0152                 set_source_files_properties(merged_const.cpp   PROPERTIES OBJECT_DEPENDS "${depends_moc_uic}")
0153                 set_source_files_properties(merged_touched.cpp PROPERTIES OBJECT_DEPENDS "${depends_moc_uic}")
0154                 add_library(${kst_name} ${type} ${merged_files} ${kst_${kst_name}_dont_merge} ${kst_${kst_name}_headers} ${kst_${kst_name}_uis} ${kst_${kst_name}_sources_not_generated} ${svnversion_h})
0155                 foreach(_it ${kst_${kst_name}_sources_not_generated})
0156                         set_source_files_properties(${_it} PROPERTIES HEADER_FILE_ONLY TRUE)
0157                 endforeach()
0158                 source_group("Source Files" Files)
0159                 source_group("Header Files" Files)
0160         else()
0161                 add_library(${kst_name} ${type} ${kst_${kst_name}_sources} ${kst_${kst_name}_headers} ${svnversion_h})
0162                 kst_flat_source_group(${kst_${kst_name}_headers} ${kst_${kst_name}_sources_not_generated})
0163         endif()
0164         set(lib${kst_name_base} ${kst_name} CACHE STRING "actual ${kst_name} name" FORCE)
0165         set_property(TARGET ${kst_name} PROPERTY DEBUG_POSTFIX ${kst_debug_postfix})
0166         set_target_properties(${kst_name} PROPERTIES VERSION ${kst_version} SOVERSION ${kst_version_major})
0167         kst_revision_add_dependency()
0168         if(WIN32)
0169                 if(NOT ${type} STREQUAL "STATIC")
0170                         install(TARGETS ${kst_name} RUNTIME DESTINATION bin)
0171                 endif()
0172         elseif(NOT APPLE)
0173                 install(TARGETS ${kst_name} DESTINATION ${kst_install_libdir})
0174         endif()
0175 endmacro()
0176 
0177 
0178 macro(kst_init_plugin dir)
0179         if(APPLE AND NOT CMAKE_GENERATOR STREQUAL Xcode)
0180                 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${kst_build_dir}/bin/${kst_binary_name}.app/Contents/plugins)
0181         else()
0182                 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${kst_build_dir}/${kst_install_plugins})
0183                 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${kst_build_dir}/${kst_install_plugins})
0184         endif()
0185         include_directories(${CMAKE_BINARY_DIR}/${dir})
0186         include_directories(${CMAKE_BINARY_DIR}/cmake/${dir})
0187         kst_include_directories(core math widgets)
0188         set(kst_plugin_dir ${dir})
0189         set(kst_plugin_prefix ${ARGN})
0190 endmacro()
0191 
0192 
0193 macro(kst_add_plugin_internal folder name libtype postfix)
0194         set(_name _${kst_plugin_prefix}_${folder}_${name})
0195         string(REPLACE . _  _name ${_name})
0196         string(REPLACE / _  _name ${_name})
0197         string(REPLACE __ _ _name ${_name})
0198         string(REPLACE __ _ _name ${_name})
0199         kst_init(${kst_binary_name} ${_name})
0200         kst_files_find(${kst_plugin_dir}/${folder}/${name})
0201         add_library(${kst_name}${postfix} ${libtype} ${kst_${kst_name}_sources} ${kst_${kst_name}_headers})
0202         add_dependencies(${kst_binary_name} ${kst_name})
0203         kst_flat_source_group(${kst_${kst_name}_headers} ${kst_${kst_name}_sources_not_generated})
0204         if(kst_verbose)
0205                 message(STATUS "Building plugin ${kst_name}")
0206         endif()
0207 endmacro()
0208 
0209 macro(kst_add_plugin folder name)
0210         kst_add_plugin_internal(${folder} ${name} MODULE "")
0211     kst_link(${libcore} ${libmath} ${libwidgets})
0212         if(NOT APPLE)
0213                 install(TARGETS ${kst_name} LIBRARY DESTINATION ${kst_install_plugins})
0214         endif()
0215 endmacro()
0216 
0217 macro(kst_add_plugin_lib folder name)
0218         kst_add_plugin_internal(${folder} ${name} STATIC _lib)
0219 endmacro()
0220 
0221 macro(kst_add_dependency name)
0222         add_dependencies(${kst_name} ${name})
0223 endmacro()
0224 
0225 macro(kst_include_directories)
0226         foreach(_it ${ARGV})
0227                 include_directories(${kst_${kst_binary_name}${_it}_includes})
0228         endforeach()
0229 endmacro()
0230 
0231 
0232 macro(kst_find_install_desktop_file folder)
0233         if(UNIX)
0234                 file(GLOB _desktop_file ${kst_dir}/${folder}/*.desktop)
0235                 install(FILES  ${_desktop_file} DESTINATION ${kst_install_plugin_desktop_file_path})
0236         endif()
0237 endmacro()
0238 
0239 
0240 macro(kst_link)
0241         target_link_libraries(${kst_name} ${ARGV})
0242         if(kst_qt5)
0243                 target_link_libraries(${kst_name} Qt5::Widgets Qt5::Xml Qt5::Network Qt5::PrintSupport Qt5::Svg)
0244         else()
0245                 target_link_libraries(${kst_name}
0246                 ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTSVG_LIBRARY} ${QT_QTNETWORK_LIBRARY})
0247         endif()
0248 endmacro()
0249 
0250 
0251 macro(kst_files_ignore)
0252         set(kst_${kst_name}_ignore ${kst_${kst_name}_ignore} ${ARGV})
0253 endmacro()
0254 
0255 
0256 macro(kst_files_remove list)
0257         foreach(_item ${ARGN})
0258                 set(_file ${kst_${kst_name}_folder}/${_item})
0259                 if(${list})
0260                         list(REMOVE_ITEM ${list} ${_item} ${_file} ${_file}.cpp ${_file}.c ${_file}.h)
0261                 endif()
0262         endforeach()
0263 endmacro()
0264 
0265 
0266 macro(kst_add_files)
0267         set(kst_${kst_name}_sources ${kst_${kst_name}_sources} ${ARGN})
0268 endmacro()
0269 
0270 
0271 macro(kst_add_resources filepath)
0272         if(kst_qt5)
0273                 qt5_add_resources(_rcc ${kst_dir}/${filepath})
0274         else()
0275                 qt4_add_resources(_rcc ${kst_dir}/${filepath})
0276         endif()
0277         kst_add_files(${_rcc})
0278 endmacro()
0279 
0280 
0281 macro(kst_option_init)
0282         set(kst_options)
0283 endmacro()
0284 
0285 
0286 macro(kst_option _type _default _sys _name _description)
0287         set(_msg OFF)
0288         if(${_sys} MATCHES "gcc")
0289                 set(_system CMAKE_COMPILER_IS_GNUCXX)
0290         elseif(${_sys} MATCHES "win")
0291                 set(_system WIN32)
0292         else()
0293                 set(_system ${_sys})
0294         endif()
0295         if(${_type} MATCHES "string")
0296                 if(DEFINED kst_${_name})
0297                         set(_value ${kst_${_name}})
0298                 else()
0299                         set(_value ${_default})
0300                 endif()
0301                 set(_msg ON)
0302                 set(kst_${_name} ${_value} CACHE STRING ${_description} FORCE)
0303         else()
0304                 if(${_system} MATCHES "all")
0305                         option(kst_${_name} ${_description} ${_default})
0306                         set(_msg ON)
0307                 else()
0308                         if(${${_system}})
0309                                 option(kst_${_name} ${_description} ${_default})
0310                                 set(_msg ON)
0311                         endif()
0312                 endif()
0313         endif()
0314         list(APPEND kst_options kst_${_name})
0315         set(kst_${_name}_description ${_description})
0316         set(kst_${_name}_show_message ${_msg})
0317         set(kst_${_name}_type ${_type})
0318 endmacro()
0319 
0320 
0321 macro(kst_option_list_all)
0322         foreach(_option ${kst_options})
0323                 if(${${_option}_show_message})
0324                         string(SUBSTRING "${_option}                            " 0 25 _var)
0325                         if(${_option}_type MATCHES "bool")
0326                                 if(${_option})
0327                                         set(_val  "ON ")
0328                                         set(_tval "0")
0329                                 else()
0330                                         set(_val  "OFF")
0331                                         set(_tval "1")
0332                                 endif()
0333                                 set(_toggle "Toggle with '-D${_option}=${_tval}'")
0334                         else()
0335                                 set(_val ${${_option}})
0336                                 set(_toggle)
0337                         endif()
0338                         message(STATUS "${_var}= ${_val}   : ${${_option}_description}. ${_toggle}")
0339                 endif()
0340         endforeach()
0341 endmacro()
0342 
0343 
0344 macro(kst_add_info_files group)
0345         foreach(_it ${ARGN})
0346                 if(NOT IS_DIRECTORY ${_it})
0347                         get_filename_component(name ${_it} NAME)
0348                         if(NOT ${_it} MATCHES "^/\\\\..*$;~$")
0349                                 set_source_files_properties(${_it} PROPERTIES HEADER_FILE_ONLY TRUE)
0350                                 set(kst_${group}_info_files ${kst_${group}_info_files} ${_it})
0351                         endif()
0352                 endif()
0353         endforeach()
0354         source_group(${group} FILES ${kst_${group}_info_files})
0355         set(kst_${kst_name}_info_files ${kst_${kst_name}_info_files} ${kst_${group}_info_files})
0356 endmacro()
0357 
0358 
0359 macro(kst_find_info_files group files)
0360         file(GLOB _filelist ${files})
0361         kst_add_info_files(${group} ${_filelist})
0362 endmacro()
0363 
0364 
0365 macro(kst_flat_source_group)
0366         source_group("Source Files" Files)
0367         source_group("Header Files" Files)
0368         source_group("CMakeLists" FILES CMakeLists.txt)
0369         source_group("Headers/Sources" FILES ${ARGN})
0370 endmacro()
0371 
0372