Warning, /education/marble/MarbleMacros.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2006-2010 Alexander Neundorf <neundorf@kde.org>
0002 # SPDX-License-Identifier: BSD-3-Clause
0003 
0004 include(FeatureSummary)
0005 if( COMMAND set_package_properties )
0006   macro( marble_set_package_properties )
0007   set_package_properties( ${ARGN} )
0008   endmacro()
0009 else()
0010   macro( marble_set_package_properties )
0011   # Just ignore it
0012   endmacro()
0013 endif()
0014 
0015 if ( COMMAND feature_summary )
0016   macro( marble_feature_summary )
0017   feature_summary( ${ARGN} )
0018   endmacro()
0019 else()
0020   macro( marble_feature_summary )
0021   # Just ignore it
0022   endmacro()
0023 endif()
0024 
0025 macro(qt_add_resources)
0026   qt5_add_resources(${ARGN})
0027 endmacro()
0028 
0029 macro(qt_wrap_ui)
0030   qt5_wrap_ui(${ARGN})
0031 endmacro()
0032 
0033 macro(qt_generate_moc)
0034   qt5_generate_moc(${ARGN})
0035 endmacro()
0036 
0037 # the place to put in common cmake macros
0038 # this is needed to minimize the amount of errors to do
0039 macro( marble_add_plugin _target_name )
0040 set( _src ${ARGN} )
0041 if (STATIC_BUILD)
0042     add_library(${_target_name} ${_src})
0043     target_compile_definitions(${_target_name} PRIVATE -DQT_STATICPLUGIN)
0044 else()
0045     add_library(${_target_name} MODULE ${_src})
0046 endif()
0047 target_link_libraries( ${_target_name} ${${_target_name}_LIBS}
0048                                        marblewidget )
0049 install( TARGETS ${_target_name} DESTINATION ${MARBLE_PLUGIN_INSTALL_PATH} )
0050 
0051 endmacro( marble_add_plugin _target_name )
0052 
0053 # these plugins are slightly different
0054 
0055 macro( marble_add_designer_plugin _target_name )
0056 set( _src ${ARGN} )
0057 
0058 qt_add_resources( _src ../../../apps/marble-ui/marble.qrc )
0059 
0060 add_library( ${_target_name} MODULE ${_src} )
0061 target_link_libraries( ${_target_name} ${${_target_name}_LIBS}
0062                                        marblewidget )
0063 install( TARGETS ${_target_name} DESTINATION ${QT_PLUGINS_DIR}/designer )
0064 
0065 endmacro( marble_add_designer_plugin _target_name )
0066 
0067 if( WIN32 )
0068     set( DATA_PATH ${CMAKE_INSTALL_PREFIX}/${MARBLE_DATA_PATH} )
0069     set( PLUGIN_PATH ${CMAKE_INSTALL_PREFIX}/${MARBLE_PLUGIN_PATH} )
0070 else( WIN32 )
0071     set( DATA_PATH ${MARBLE_DATA_PATH} )
0072     set( PLUGIN_PATH ${MARBLE_PLUGIN_PATH} )
0073 endif( WIN32 )
0074 
0075 macro( marble_add_test TEST_NAME )
0076     if( BUILD_MARBLE_TESTS )
0077         set( ${TEST_NAME}_SRCS ${TEST_NAME}.cpp ${ARGN} )
0078         qt_generate_moc( ${TEST_NAME}.cpp ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.moc )
0079         include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
0080         set( ${TEST_NAME}_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.moc ${${TEST_NAME}_SRCS} )
0081 
0082         add_executable( ${TEST_NAME} ${${TEST_NAME}_SRCS} )
0083         target_link_libraries(${TEST_NAME}
0084             marblewidget
0085             Qt5::Test
0086         )
0087 
0088         set_target_properties( ${TEST_NAME} PROPERTIES
0089                                COMPILE_FLAGS "-DDATA_PATH=\"\\\"${DATA_PATH}\\\"\" -DPLUGIN_PATH=\"\\\"${PLUGIN_PATH}\\\"\"" )
0090         add_test( ${TEST_NAME} ${TEST_NAME} )
0091     endif( BUILD_MARBLE_TESTS )
0092 endmacro( marble_add_test TEST_NAME )
0093 
0094 macro( marble_add_project_resources resources )
0095   add_custom_target( ${PROJECT_NAME}_Resources ALL SOURCES ${ARGN} )
0096 endmacro()
0097 
0098 # - MACRO_OPTIONAL_FIND_PACKAGE() combines FIND_PACKAGE() with an OPTION()
0099 # MACRO_OPTIONAL_FIND_PACKAGE( <name> [QUIT] )
0100 # This macro is a combination of OPTION() and FIND_PACKAGE(), it
0101 # works like FIND_PACKAGE(), but additionally it automatically creates
0102 # an option name WITH_<name>, which can be disabled via the cmake GUI.
0103 # or via -DWITH_<name>=OFF
0104 # The standard <name>_FOUND variables can be used in the same way
0105 # as when using the normal FIND_PACKAGE()
0106 
0107 # This is just a helper macro to set a bunch of variables empty.
0108 # We don't know whether the package uses UPPERCASENAME or CamelCaseName, so we try both:
0109 
0110 if(NOT COMMAND _MOFP_SET_EMPTY_IF_DEFINED)
0111 macro(_MOFP_SET_EMPTY_IF_DEFINED _name _var)
0112    if(DEFINED ${_name}_${_var})
0113       set(${_name}_${_var} "")
0114    endif(DEFINED ${_name}_${_var})
0115 
0116    string(TOUPPER ${_name} _nameUpper)
0117    if(DEFINED ${_nameUpper}_${_var})
0118       set(${_nameUpper}_${_var}  "")
0119    endif(DEFINED ${_nameUpper}_${_var})
0120 endmacro(_MOFP_SET_EMPTY_IF_DEFINED _package _var)
0121 endif()
0122 
0123 if(NOT COMMAND MACRO_OPTIONAL_FIND_PACKAGE)
0124 macro (MACRO_OPTIONAL_FIND_PACKAGE _name )
0125    option(WITH_${_name} "Search for ${_name} package" ON)
0126    if (WITH_${_name})
0127       find_package(${_name} ${ARGN})
0128    else (WITH_${_name})
0129       string(TOUPPER ${_name} _nameUpper)
0130       set(${_name}_FOUND FALSE)
0131       set(${_nameUpper}_FOUND FALSE)
0132 
0133       _mofp_set_empty_if_defined(${_name} INCLUDE_DIRS)
0134       _mofp_set_empty_if_defined(${_name} INCLUDE_DIR)
0135       _mofp_set_empty_if_defined(${_name} INCLUDES)
0136       _mofp_set_empty_if_defined(${_name} LIBRARY)
0137       _mofp_set_empty_if_defined(${_name} LIBRARIES)
0138       _mofp_set_empty_if_defined(${_name} LIBS)
0139       _mofp_set_empty_if_defined(${_name} FLAGS)
0140       _mofp_set_empty_if_defined(${_name} DEFINITIONS)
0141    endif (WITH_${_name})
0142 endmacro (MACRO_OPTIONAL_FIND_PACKAGE)
0143 endif()
0144 
0145 # older cmake version don't have the add_feature_info macro.
0146 # It's just informative, so we add our own that does
0147 # nothing in that case
0148 if(NOT COMMAND ADD_FEATURE_INFO)
0149 macro(ADD_FEATURE_INFO)
0150   # just ignore it
0151 endmacro()
0152 endif()
0153 
0154 
0155 # Find Qt translation tools
0156 find_package(Qt5LinguistTools CONFIG)
0157 
0158 if(NOT Qt5LinguistTools_FOUND)
0159 
0160 # dummy implementation
0161 function(marble_install_po_files_as_qm podir)
0162     set(options)
0163     set(oneValueArgs TARGET)
0164     set(multiValueArgs)
0165     cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
0166 
0167     if(ARGS_TARGET)
0168         if(NOT TARGET ${ARGS_TARGET})
0169             add_custom_target(${ARGS_TARGET})
0170         endif()
0171     endif()
0172     if (NOT IS_ABSOLUTE "${podir}")
0173         set(podir "${CMAKE_CURRENT_SOURCE_DIR}/${podir}")
0174     endif()
0175     if (IS_DIRECTORY "${podir}")
0176         message(STATUS "Will do nothing for po files in \"${podir}\", tools missing")
0177     endif()
0178 endfunction()
0179 
0180 else()
0181 
0182 if(TARGET Qt5::lconvert)
0183     set(lconvert_executable Qt5::lconvert)
0184 else()
0185     # Qt < 5.3.1 does not define Qt5::lconvert
0186     get_target_property(lrelease_location Qt5::lrelease LOCATION)
0187     get_filename_component(lrelease_path ${lrelease_location} PATH)
0188     find_program(lconvert_executable
0189         NAMES lconvert-qt5 lconvert
0190         PATHS ${lrelease_path}
0191         NO_DEFAULT_PATH
0192     )
0193 endif()
0194 
0195 function(marble_process_po_files_as_qm lang po_file)
0196     set(options)
0197     set(oneValueArgs TARGET)
0198     set(multiValueArgs)
0199     cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
0200 
0201     # Create commands to turn po files into qm files
0202     get_filename_component(po_file ${po_file} ABSOLUTE)
0203     get_filename_component(filename_base ${po_file} NAME_WE)
0204 
0205     # Include ${lang} in build dir because we might be called multiple times
0206     # with the same ${filename_base}
0207     set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/locale/${lang})
0208     set(ts_file ${build_dir}/${filename_base}.ts)
0209     set(qm_file ${build_dir}/${filename_base}.qm)
0210     if(ANDROID)
0211         set(qm_install_dir "${locale_dir}/${lang}")
0212     else()
0213         set(qm_install_dir "${locale_dir}/${lang}/LC_MESSAGES")
0214     endif()
0215 
0216     file(MAKE_DIRECTORY ${build_dir})
0217 
0218     # lconvert from .po to .ts, then lrelease from .ts to .qm.
0219     add_custom_command(OUTPUT ${qm_file}
0220         COMMAND ${lconvert_executable}
0221             ARGS -i ${po_file} -o ${ts_file} -target-language ${lang}
0222         COMMAND Qt5::lrelease
0223             ARGS -removeidentical -nounfinished -silent ${ts_file} -qm ${qm_file}
0224         DEPENDS ${po_file}
0225     )
0226     install(
0227         FILES ${qm_file}
0228         DESTINATION ${qm_install_dir}
0229         OPTIONAL # if not build, ignore it
0230     )
0231 
0232     if(ARGS_TARGET)
0233         set(target_name_prefix ${ARGS_TARGET})
0234     else()
0235         set(target_name_prefix translation)
0236     endif()
0237     string(REPLACE "@" "AT" _lang ${lang})
0238     set(target_name ${target_name_prefix}_${_lang}_${filename_base})
0239 
0240     if(ARGS_TARGET)
0241         add_custom_target(${target_name} DEPENDS ${qm_file})
0242         add_dependencies(${ARGS_TARGET} ${target_name})
0243     else()
0244         add_custom_target(${target_name} ALL DEPENDS ${qm_file})
0245     endif()
0246 endfunction()
0247 
0248 
0249 function(marble_install_po_files_as_qm podir)
0250     set(options)
0251     set(oneValueArgs TARGET)
0252     set(multiValueArgs)
0253     cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
0254 
0255     if(ARGS_TARGET)
0256         if(NOT TARGET ${ARGS_TARGET})
0257             add_custom_target(${ARGS_TARGET})
0258         endif()
0259 
0260         set(target_arg TARGET ${ARGS_TARGET})
0261     else()
0262         set(target_arg)
0263     endif()
0264 
0265     file(GLOB po_files "${podir}/*/*.po")
0266     foreach(po_file ${po_files})
0267         get_filename_component(po_dir ${po_file} DIRECTORY)
0268         get_filename_component(lang ${po_dir} NAME)
0269         marble_process_po_files_as_qm(${lang} ${po_file} ${target_arg})
0270     endforeach()
0271 endfunction()
0272 
0273 endif()