From 57173313ad42dd77a6bbc7312a0f43098c2c4f40 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 13 Apr 2020 19:44:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3!=20=D0=9D=D0=B0=D1=80=D1=83=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D1=8C!!!=20(=D0=BF=D0=BE=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B5=D1=81=D1=82=D1=8C=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BA=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMLibCodeAnalysisClangAnalyze.cmake | 10 +++----- CMLibCodeAnalysisClangTidy.cmake | 10 +++----- CMLibCodeAnalysisClazy.cmake | 10 +++----- CMLibCodeAnalysisPvsStudio.cmake | 14 +++++----- CMLibCodeCoverage.cmake | 21 ++++++++------- CMLibCommonLibraryTarget.cmake | 31 +++++++++++----------- CMLibCommonTargetProperties.cmake | 39 ++++++++++++++-------------- CMLibDocBreathe.cmake | 18 ++++++------- CMLibDocDoxygen.cmake | 17 +++++------- CMLibFormatSources.cmake | 12 ++++----- CMLibQtTranslation.cmake | 40 +++++++++++++++-------------- 11 files changed, 105 insertions(+), 117 deletions(-) diff --git a/CMLibCodeAnalysisClangAnalyze.cmake b/CMLibCodeAnalysisClangAnalyze.cmake index d374df0..8673cfb 100644 --- a/CMLibCodeAnalysisClangAnalyze.cmake +++ b/CMLibCodeAnalysisClangAnalyze.cmake @@ -11,10 +11,8 @@ if(CLANG_CHECK_EXE) option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF) endif() -function(add_clang_analyze_check) - list(GET ARGN 0 _target) +function(add_clang_analyze_check target) set(_sources ${ARGN}) - list(REMOVE_AT _sources 0) if(CLANG_CHECK_EXE) if(CLANG_CHECK_FIX) @@ -24,11 +22,11 @@ function(add_clang_analyze_check) add_custom_target(clang-analyze-check) endif() add_custom_target( - clang-analyze-check-${_target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + clang-analyze-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${CLANG_CHECK_EXE} -analyze -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources}) - add_dependencies(clang-analyze-check-${_target} ${_target}) - add_dependencies(clang-analyze-check clang-analyze-check-${_target}) + add_dependencies(clang-analyze-check-${target} ${target}) + add_dependencies(clang-analyze-check clang-analyze-check-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " Clang-Check analyzer is not found") diff --git a/CMLibCodeAnalysisClangTidy.cmake b/CMLibCodeAnalysisClangTidy.cmake index 5e23b9b..4071b25 100644 --- a/CMLibCodeAnalysisClangTidy.cmake +++ b/CMLibCodeAnalysisClangTidy.cmake @@ -14,20 +14,18 @@ if(CLANG_TIDY_EXE) endif() endif() -function(add_clang_tidy_check) - list(GET ARGN 0 _target) +function(add_clang_tidy_check target) set(_sources ${ARGN}) - list(REMOVE_AT _sources 0) if(CLANG_TIDY_EXE) if(NOT TARGET clang-tidy-check) add_custom_target(clang-tidy-check) endif() add_custom_target( - clang-tidy-check-${_target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + clang-tidy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${CLANG_TIDY_EXE} -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources}) - add_dependencies(clang-tidy-check-${_target} ${_target}) - add_dependencies(clang-tidy-check clang-tidy-check-${_target}) + add_dependencies(clang-tidy-check-${target} ${target}) + add_dependencies(clang-tidy-check clang-tidy-check-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " ClangTidy analyzer is not found") diff --git a/CMLibCodeAnalysisClazy.cmake b/CMLibCodeAnalysisClazy.cmake index d0ab30c..64abdce 100644 --- a/CMLibCodeAnalysisClazy.cmake +++ b/CMLibCodeAnalysisClazy.cmake @@ -2,10 +2,8 @@ set(clazy_checks container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast ) -function(add_clazy_check) - list(GET ARGN 0 _target) +function(add_clazy_check target) set(_sources ${ARGN}) - list(REMOVE_AT _sources 0) find_program(CLAZY_EXE NAMES clazy-standalone) if(CLAZY_EXE) @@ -13,11 +11,11 @@ function(add_clazy_check) add_custom_target(clazy-check) endif() add_custom_target( - clazy-check-${_target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + clazy-check-${target} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${CLAZY_EXE} -checks=level2,${clazy_checks} -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR} ${_sources}) - add_dependencies(clazy-check-${_target} ${_target}) - add_dependencies(clazy-check clazy-check-${_target}) + add_dependencies(clazy-check-${target} ${target}) + add_dependencies(clazy-check clazy-check-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " Clazy analyzer is not found") diff --git a/CMLibCodeAnalysisPvsStudio.cmake b/CMLibCodeAnalysisPvsStudio.cmake index 1ac7c77..fbec0f1 100644 --- a/CMLibCodeAnalysisPvsStudio.cmake +++ b/CMLibCodeAnalysisPvsStudio.cmake @@ -1,6 +1,4 @@ -function(add_pvs_check) - list(GET ARGN 0 _target) - +function(add_pvs_check target) if(CMAKE_EXPORT_COMPILE_COMMANDS) include(PVS-Studio) find_program(PVS_STUDIO_ANALYZER_EXE NAMES pvs-studio-analyzer) @@ -9,14 +7,14 @@ function(add_pvs_check) add_custom_target(pvs-check) endif() pvs_studio_add_target( - TARGET pvs-check-${_target} - DEPENDS ${_target} + TARGET pvs-check-${target} + DEPENDS ${target} COMPILE_COMMANDS HIDE_HELP OUTPUT FORMAT errorfile - CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${_target}.cfg" - ARGS --analysis-mode 29 --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${_target}_autogen + CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${target}.cfg" + ARGS --analysis-mode 29 --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen MODE GA:1,2,3;64:1;OP:1,2;CS:1,2) - add_dependencies(pvs-check pvs-check-${_target}) + add_dependencies(pvs-check pvs-check-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " PVS-Studio analyzer is not found") diff --git a/CMLibCodeCoverage.cmake b/CMLibCodeCoverage.cmake index b499f1e..e3d4a7d 100644 --- a/CMLibCodeCoverage.cmake +++ b/CMLibCodeCoverage.cmake @@ -2,27 +2,26 @@ option(ENABLE_CODE_COVERAGE "Enable code coverage support" OFF) find_program(LCOV_EXE NAMES lcov) find_program(GENHTML_EXE NAMES genhtml) -function(add_code_coverage) - list(GET ARGN 0 _target) +function(add_code_coverage target) if(ENABLE_CODE_COVERAGE) if(CMAKE_CXX_COMPILER_IS_GCC) - target_compile_options(${_target} PUBLIC "--coverage") - get_target_property(LF ${_target} LINK_FLAGS) + target_compile_options(${target} PUBLIC "--coverage") + get_target_property(LF ${target} LINK_FLAGS) string(APPEND LF " --coverage") - set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF}) + set_target_properties(${target} PROPERTIES LINK_FLAGS ${LF}) if(LCOV_EXE) add_custom_target( - coverage-${_target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND ${LCOV_EXE} --test-name ${_target} --output "${_target}.lcov" --capture --directory + coverage-${target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND ${LCOV_EXE} --test-name ${target} --output "${target}.lcov" --capture --directory ${CMAKE_BINARY_DIR}) - add_dependencies(coverage-${_target} ${_target}) + add_dependencies(coverage-${target} ${target}) if(GENHTML_EXE) - add_custom_target(coverage-report-${_target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND ${GENHTML_EXE} --output-directory "report-${_target}" "${_target}.lcov") - add_dependencies(coverage-report-${_target} coverage-${_target}) + add_custom_target(coverage-report-${target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND ${GENHTML_EXE} --output-directory "report-${target}" "${target}.lcov") + add_dependencies(coverage-report-${target} coverage-${target}) endif() endif() else() diff --git a/CMLibCommonLibraryTarget.cmake b/CMLibCommonLibraryTarget.cmake index 011e10f..0583068 100644 --- a/CMLibCommonLibraryTarget.cmake +++ b/CMLibCommonLibraryTarget.cmake @@ -1,41 +1,40 @@ # Создание статической и динамической библиотеки из одинаковых объектных файлов -function(add_common_library) +function(add_common_library target) set(options) - set(oneValueArgs TARGET OUTPUT_NAME) + set(oneValueArgs OUTPUT_NAME) set(multiValueArgs SOURCES) cmake_parse_arguments(_LOCAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(LIBNAME ${_LOCAL_TARGET}) set(SOURCES ${_LOCAL_SOURCES}) if(_LOCAL_OUTPUT_NAME) set(OUTNAME ${_LOCAL_OUTPUT_NAME}) else() - set(OUTNAME ${LIBNAME}) + set(OUTNAME ${target}) endif() - add_library(${LIBNAME} OBJECT ${SOURCES}) + add_library(${target} OBJECT ${SOURCES}) target_include_directories( - ${LIBNAME} PUBLIC $ - $ $) - set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) + ${target} PUBLIC $ + $ $) + set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON) if(BUILD_SHARED_LIBS) - add_library(${LIBNAME}_shared SHARED $) + add_library(${target}_shared SHARED $) set_target_properties( - ${LIBNAME}_shared + ${target}_shared PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} OUTPUT_NAME ${OUTNAME} LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) - install(TARGETS ${LIBNAME}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(TARGETS ${target}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() if(NOT SKIP_STATIC_LIBS) - add_library(${LIBNAME}_static STATIC $) - set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${OUTNAME} ARCHIVE_OUTPUT_DIRECTORY + add_library(${target}_static STATIC $) + set_target_properties(${target}_static PROPERTIES OUTPUT_NAME ${OUTNAME} ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) - install(TARGETS ${LIBNAME}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(TARGETS ${target}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() - configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${LIBNAME}.pc) - install(FILES ${CMAKE_BINARY_DIR}/${LIBNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${target}.pc) + install(FILES ${CMAKE_BINARY_DIR}/${target}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endfunction() diff --git a/CMLibCommonTargetProperties.cmake b/CMLibCommonTargetProperties.cmake index eea3dd5..3e5f1b5 100644 --- a/CMLibCommonTargetProperties.cmake +++ b/CMLibCommonTargetProperties.cmake @@ -1,48 +1,49 @@ set(COMMON_CXX_FEATURES cxx_alias_templates cxx_nullptr cxx_override) -function(common_target_properties Name) - get_target_property(__type ${Name} TYPE) +function(common_target_properties target) + get_target_property(__type ${target} TYPE) set(__visibility PUBLIC) if(__type STREQUAL INTERFACE_LIBRARY) set(__interface 1) set(__visibility INTERFACE) endif() - target_compile_features(${Name} ${__visibility} ${COMMON_CXX_FEATURES}) - get_target_property(_targetType ${Name} TYPE) + target_compile_features(${target} ${__visibility} ${COMMON_CXX_FEATURES}) + get_target_property(_targetType ${target} TYPE) if(_targetType STREQUAL "EXECUTABLE" AND CMAKE_CXX_COMPILE_OPTIONS_PIE) - target_compile_options(${Name} PUBLIC "${CMAKE_CXX_COMPILE_OPTIONS_PIE}") + target_compile_options(${target} PUBLIC "${CMAKE_CXX_COMPILE_OPTIONS_PIE}") endif() target_include_directories( - ${Name} + ${target} PUBLIC $ $ $ $) if(APPLE) - target_compile_definitions(${Name} ${__visibility} Darwin) + target_compile_definitions(${target} ${__visibility} Darwin) endif() if(NOT __interface) if(TARGET Qt5::Core) if(_targetType STREQUAL "EXECUTABLE") - target_compile_options(${Name} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") + target_compile_options(${target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") endif() - set_target_properties(${Name} PROPERTIES AUTOMOC TRUE AUTORCC TRUE) + # set_target_properties(${target} PROPERTIES AUTOMOC TRUE) + # set_target_properties(${target} PROPERTIES AUTORCC TRUE) endif() if(TARGET Qt5::Widgets) - set_target_properties(${Name} PROPERTIES AUTOUIC TRUE) + # set_target_properties(${target} PROPERTIES AUTOUIC TRUE) # if(CMAKE_VERSION VERSION_LESS 3.7.99) # target_include_directories( - # ${Name} + # ${target} # PUBLIC - # $ + # $ # ) # endif() endif() if(CMAKE_CXX_COMPILER_IS_GCC AND NOT APPLE) - set_target_properties(${Name} PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") + set_target_properties(${target} PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") endif() endif() # LTO only for executables (not libraries) in Release build type - get_target_property(target_type ${Name} TYPE) + get_target_property(target_type ${target} TYPE) if(target_type STREQUAL "EXECUTABLE" AND CMAKE_BUILD_TYPE STREQUAL "Release") check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG) check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_LTO_FLAG) @@ -72,16 +73,16 @@ function(common_target_properties Name) endif() if(CMAKE_BUILD_TYPE STREQUAL Profile) - target_compile_definitions(${Name} ${__visibility} PROFILE) + target_compile_definitions(${target} ${__visibility} PROFILE) elseif(CMAKE_BUILD_TYPE STREQUAL Debug) - target_compile_definitions(${Name} ${__visibility} DEBUG) + target_compile_definitions(${target} ${__visibility} DEBUG) elseif(CMAKE_BUILD_TYPE STREQUAL Release) - target_compile_definitions(${Name} ${__visibility} RELEASE) + target_compile_definitions(${target} ${__visibility} RELEASE) elseif(CMAKE_BUILD_TYPE STREQUAL None) - target_compile_definitions(${Name} ${__visibility} ANALYSIS) + target_compile_definitions(${target} ${__visibility} ANALYSIS) endif() target_compile_definitions( - ${Name} + ${target} ${__visibility} "TARGET_LSB_ID_${LSB_DISTRIBUTOR_ID}" "TARGET_LSB_CODENAME_${LSB_CODENAME}") diff --git a/CMLibDocBreathe.cmake b/CMLibDocBreathe.cmake index 813b31f..7dc256e 100644 --- a/CMLibDocBreathe.cmake +++ b/CMLibDocBreathe.cmake @@ -24,9 +24,9 @@ else() set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) endif() -function(add_breathe_target) +function(add_breathe target) set(options) - set(oneValueArgs TARGET_NAME COMMENT) + set(oneValueArgs COMMENT) set(multiValueArgs) cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -36,7 +36,6 @@ function(add_breathe_target) set(GENERATE_XML YES) set(GENERATE_HTML NO) set(GENERATE_LATEX NO) - set(GENERATE_SQLITE NO) set(CONF_FILE ${CMAKE_SOURCE_DIR}/cmake/doc/breathe-conf.py.in) set(DOXY_FILE ${CMAKE_SOURCE_DIR}/cmake/doc/Doxyfile.in) @@ -44,18 +43,18 @@ function(add_breathe_target) configure_file(${DOXY_FILE} ${WORK_DIR}/Doxyfile @ONLY) add_custom_target( - ${_BREATHE_TARGET_NAME} + ${target} VERBATIM COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${WORK_DIR} -d ${WORK_DIR}/cache ${WORK_DIR} ${CMAKE_BINARY_DIR}/doc/breathe - COMMENT "Building ${_BREATHE_TARGET_NAME} documentation with Breathe") + COMMENT "Building ${target} documentation with Breathe") set(INDEX_MD_FILE ${CMAKE_SOURCE_DIR}/doc/breathe/index.md.in) if(EXISTS ${INDEX_MD_FILE}) configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY) file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md) if(MD_FILES) - add_custom_command(TARGET ${_BREATHE_TARGET_NAME} PRE_BUILD + add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MD_FILES} ${WORK_DIR}) endif() endif() @@ -65,12 +64,13 @@ function(add_breathe_target) configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY) file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst) if(RST_FILES) - add_custom_command(TARGET ${_BREATHE_TARGET_NAME} PRE_BUILD + add_custom_command(TARGET ${target} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RST_FILES} ${WORK_DIR}) endif() endif() else() - add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM - COMMENT "Breathe is not found. Skipping target ${_BREATHE_TARGET_NAME} build") + message(STATUS "CMLIB warning:") + add_custom_target(${target} VERBATIM + COMMENT " Breathe is not found. Skipping target ${target} build") endif() endfunction() diff --git a/CMLibDocDoxygen.cmake b/CMLibDocDoxygen.cmake index ffcc9bb..8599161 100644 --- a/CMLibDocDoxygen.cmake +++ b/CMLibDocDoxygen.cmake @@ -8,39 +8,36 @@ else() set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE) endif() -function(add_doxygen_target) +function(add_doxygen target) set(options) - set(oneValueArgs TARGET_NAME SQLITE LATEX HTML) + set(oneValueArgs SQLITE LATEX HTML) set(multiValueArgs) cmake_parse_arguments(_DOXYGEN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if(DOXYGEN_FOUND) - set(GENERATE_XML NO) + set(GENERATE_XML YES) set(GENERATE_HTML NO) set(GENERATE_LATEX NO) - set(GENERATE_SQLITE YES) if(_DOXYGEN_HTML) set(GENERATE_HTML YES) endif() if(_DOXYGEN_LATEX) set(GENERATE_LATEX YES) endif() - if(_DOXYGEN_SQLITE) - set(GENERATE_SQLITE YES) - endif() set(WORK_DIR ${CMAKE_BINARY_DIR}/doc/doxygen) configure_file(${CMAKE_SOURCE_DIR}/cmake/doc/Doxyfile.in ${WORK_DIR}/Doxyfile @ONLY) add_custom_target( - ${_DOXYGEN_TARGET_NAME} + ${target} VERBATIM COMMAND "${CMAKE_COMMAND}" -E remove -f "${WORK_DIR}/doxygen_sqlite3.db" COMMAND ${DOXYGEN_EXECUTABLE} ${WORK_DIR}/Doxyfile WORKING_DIRECTORY ${WORK_DIR} COMMENT "Generating API documentation with Doxygen") else() - add_custom_target(${_DOXYGEN_TARGET_NAME} VERBATIM - COMMENT "Doxygen is not found. Skipping target ${_DOXYGEN_TARGET_NAME} build") + message(STATUS "CMLIB warning:") + add_custom_target(${target} VERBATIM + COMMENT " Doxygen is not found. Skipping target ${target} build") endif() endfunction() diff --git a/CMLibFormatSources.cmake b/CMLibFormatSources.cmake index a53d396..afb211d 100644 --- a/CMLibFormatSources.cmake +++ b/CMLibFormatSources.cmake @@ -1,7 +1,5 @@ -function(add_format_sources) - list(GET ARGN 0 _target) +function(add_format_sources target) set(_sources ${ARGN}) - list(REMOVE_AT _sources 0) if(NOT TARGET format-sources) add_custom_target(format-sources) @@ -19,9 +17,9 @@ function(add_format_sources) if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) endif() - add_custom_target(format-sources-uncrustify-${_target} COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} + add_custom_target(format-sources-uncrustify-${target} COMMAND ${UNCRUSTIFY_EXE} ${UNCRUSTIFY_OPTS} ${_sources}) - add_dependencies(format-sources format-sources-uncrustify-${_target}) + add_dependencies(format-sources format-sources-uncrustify-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " uncrustify executable is not found") @@ -30,8 +28,8 @@ function(add_format_sources) find_program(DOS2UNIX_EXE NAMES dos2unix) if(DOS2UNIX_EXE) list(APPEND DOS2UNIX_OPTS -k -r) - add_custom_target(format-sources-dos2unix-${_target} COMMAND ${DOS2UNIX_EXE} ${DOS2UNIX_OPTS} ${_sources}) - add_dependencies(format-sources format-sources-dos2unix-${_target}) + add_custom_target(format-sources-dos2unix-${target} COMMAND ${DOS2UNIX_EXE} ${DOS2UNIX_OPTS} ${_sources}) + add_dependencies(format-sources format-sources-dos2unix-${target}) else() message(STATUS "CMLIB warning:") message(STATUS " dos2unix executable is not found") diff --git a/CMLibQtTranslation.cmake b/CMLibQtTranslation.cmake index 5ca8858..54a7169 100644 --- a/CMLibQtTranslation.cmake +++ b/CMLibQtTranslation.cmake @@ -1,50 +1,52 @@ -function(qt5_translation) +function(qt5_translation outfiles) find_package(Qt5 COMPONENTS LinguistTools REQUIRED) set(options) - set(oneValueArgs TARGET TS_DIR) + set(oneValueArgs BASE_NAME OUTPUT_DIR) set(multiValueArgs SOURCES LANGUAGES) cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(_target ${_QTTR_TARGET}) + set(_base_name ${_QTTR_BASE_NAME}) set(_sources ${_QTTR_SOURCES}) - set(_ts_dir ${_QTTR_TS_DIR}) + set(_output_dir ${_QTTR_OUTPUT_DIR}) set(_languages ${_QTTR_LANGUAGES}) set(L10N_QRC_BODY "") - make_directory(${_ts_dir}) + make_directory(${_output_dir}) foreach(_lang ${_languages}) - set(_ts "${_target}_${_lang}.ts") - set(_qm "${_target}_${_lang}.qm") - list(APPEND _ts_list ${_ts_dir}/${_ts}) - list(APPEND _l10n_targets "${_target}_l10n_${_lang}") + set(_ts "${_base_name}_${_lang}.ts") + set(_qm "${_base_name}_${_lang}.qm") + list(APPEND _ts_list ${_output_dir}/${_ts}) + list(APPEND _l10n_names "${_base_name}_l10n_${_lang}") string(APPEND L10N_QRC_BODY "${CMAKE_BINARY_DIR}/${_qm}\n") add_custom_target( - ${_target}_l10n_${_lang} COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_sources} -ts ${_ts_dir}/${_ts} + ${_base_name}_l10n_${_lang} COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${_sources} -ts ${_output_dir}/${_ts} -target-language ${_lang} DEPENDS ${_sources}) - if(NOT EXISTS "${_ts_dir}/${_ts}") - add_custom_target(${_ts} DEPENDS ${_target}_l10n_${_lang}) + if(NOT EXISTS "${_output_dir}/${_ts}") + add_custom_target(${_ts} DEPENDS ${_base_name}_l10n_${_lang}) else() add_custom_target(${_ts} COMMAND echo "Skipping lupdate for ${_ts}") endif() add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/${_qm} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${_ts_dir}/${_ts} -qm + OUTPUT ${CMAKE_BINARY_DIR}/${_qm} COMMAND ${Qt5_LRELEASE_EXECUTABLE} ARGS ${_output_dir}/${_ts} -qm ${CMAKE_BINARY_DIR}/${_qm} DEPENDS ${_ts} ${_sources}) endforeach() - configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc) - qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc) - add_custom_target(${_target}_qrc DEPENDS ${_qrc}) - add_custom_target(${_target}_l10n DEPENDS ${_l10n_targets}) + configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc) + # qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc) + list(APPEND ${outfiles} ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc) + # add_custom_target(${_base_name}_qrc DEPENDS ${_qrc}) + # add_custom_target(${_base_name}_l10n DEPENDS ${_l10n_targets}) if(NOT TARGET l10n) add_custom_target(l10n) endif() add_dependencies(l10n ${_target}_l10n) - add_dependencies(${_target} ${_target}_qrc) - target_sources(${_target} PUBLIC ${_qrc}) + # add_dependencies(${_target} ${_target}_qrc) + # target_sources(${_target} PUBLIC ${_qrc}) + set(${outfiles} ${${outfiles}} PARENT_SCOPE) endfunction()