Рефакторинг! Нарушена совместимость!!! (пока есть ошибки)

This commit is contained in:
Andrei Astafev 2020-04-13 19:44:42 +03:00
parent 026655f712
commit 57173313ad
11 changed files with 105 additions and 117 deletions

View File

@ -11,10 +11,8 @@ if(CLANG_CHECK_EXE)
option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF) option(CLANG_ANALYZE_FIX "Perform fixes for Clang-Check" OFF)
endif() endif()
function(add_clang_analyze_check) function(add_clang_analyze_check target)
list(GET ARGN 0 _target)
set(_sources ${ARGN}) set(_sources ${ARGN})
list(REMOVE_AT _sources 0)
if(CLANG_CHECK_EXE) if(CLANG_CHECK_EXE)
if(CLANG_CHECK_FIX) if(CLANG_CHECK_FIX)
@ -24,11 +22,11 @@ function(add_clang_analyze_check)
add_custom_target(clang-analyze-check) add_custom_target(clang-analyze-check)
endif() endif()
add_custom_target( 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} COMMAND ${CLANG_CHECK_EXE} -analyze -extra-arg="-Wno-unknown-warning-option" -p ${CMAKE_BINARY_DIR}
${_sources}) ${_sources})
add_dependencies(clang-analyze-check-${_target} ${_target}) add_dependencies(clang-analyze-check-${target} ${target})
add_dependencies(clang-analyze-check clang-analyze-check-${_target}) add_dependencies(clang-analyze-check clang-analyze-check-${target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " Clang-Check analyzer is not found") message(STATUS " Clang-Check analyzer is not found")

View File

@ -14,20 +14,18 @@ if(CLANG_TIDY_EXE)
endif() endif()
endif() endif()
function(add_clang_tidy_check) function(add_clang_tidy_check target)
list(GET ARGN 0 _target)
set(_sources ${ARGN}) set(_sources ${ARGN})
list(REMOVE_AT _sources 0)
if(CLANG_TIDY_EXE) if(CLANG_TIDY_EXE)
if(NOT TARGET clang-tidy-check) if(NOT TARGET clang-tidy-check)
add_custom_target(clang-tidy-check) add_custom_target(clang-tidy-check)
endif() endif()
add_custom_target( 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}) 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-${target} ${target})
add_dependencies(clang-tidy-check clang-tidy-check-${_target}) add_dependencies(clang-tidy-check clang-tidy-check-${target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " ClangTidy analyzer is not found") message(STATUS " ClangTidy analyzer is not found")

View File

@ -2,10 +2,8 @@ set(clazy_checks
container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast container-inside-loop,heap-allocated-small-trivial-type,inefficient-qlist,isempty-vs-count,qt-keywords,unneeded-cast
) )
function(add_clazy_check) function(add_clazy_check target)
list(GET ARGN 0 _target)
set(_sources ${ARGN}) set(_sources ${ARGN})
list(REMOVE_AT _sources 0)
find_program(CLAZY_EXE NAMES clazy-standalone) find_program(CLAZY_EXE NAMES clazy-standalone)
if(CLAZY_EXE) if(CLAZY_EXE)
@ -13,11 +11,11 @@ function(add_clazy_check)
add_custom_target(clazy-check) add_custom_target(clazy-check)
endif() endif()
add_custom_target( 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 COMMAND ${CLAZY_EXE} -checks=level2,${clazy_checks} -extra-arg="-Wno-unknown-warning-option" -p
${CMAKE_BINARY_DIR} ${_sources}) ${CMAKE_BINARY_DIR} ${_sources})
add_dependencies(clazy-check-${_target} ${_target}) add_dependencies(clazy-check-${target} ${target})
add_dependencies(clazy-check clazy-check-${_target}) add_dependencies(clazy-check clazy-check-${target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " Clazy analyzer is not found") message(STATUS " Clazy analyzer is not found")

View File

@ -1,6 +1,4 @@
function(add_pvs_check) function(add_pvs_check target)
list(GET ARGN 0 _target)
if(CMAKE_EXPORT_COMPILE_COMMANDS) if(CMAKE_EXPORT_COMPILE_COMMANDS)
include(PVS-Studio) include(PVS-Studio)
find_program(PVS_STUDIO_ANALYZER_EXE NAMES pvs-studio-analyzer) find_program(PVS_STUDIO_ANALYZER_EXE NAMES pvs-studio-analyzer)
@ -9,14 +7,14 @@ function(add_pvs_check)
add_custom_target(pvs-check) add_custom_target(pvs-check)
endif() endif()
pvs_studio_add_target( pvs_studio_add_target(
TARGET pvs-check-${_target} TARGET pvs-check-${target}
DEPENDS ${_target} DEPENDS ${target}
COMPILE_COMMANDS HIDE_HELP OUTPUT COMPILE_COMMANDS HIDE_HELP OUTPUT
FORMAT errorfile FORMAT errorfile
CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${_target}.cfg" CONFIG "${CMAKE_BINARY_DIR}/PVS-Studio-${target}.cfg"
ARGS --analysis-mode 29 --exclude-path ${CMAKE_CURRENT_BINARY_DIR}/${_target}_autogen 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) 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() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " PVS-Studio analyzer is not found") message(STATUS " PVS-Studio analyzer is not found")

View File

@ -2,27 +2,26 @@ option(ENABLE_CODE_COVERAGE "Enable code coverage support" OFF)
find_program(LCOV_EXE NAMES lcov) find_program(LCOV_EXE NAMES lcov)
find_program(GENHTML_EXE NAMES genhtml) find_program(GENHTML_EXE NAMES genhtml)
function(add_code_coverage) function(add_code_coverage target)
list(GET ARGN 0 _target)
if(ENABLE_CODE_COVERAGE) if(ENABLE_CODE_COVERAGE)
if(CMAKE_CXX_COMPILER_IS_GCC) if(CMAKE_CXX_COMPILER_IS_GCC)
target_compile_options(${_target} PUBLIC "--coverage") target_compile_options(${target} PUBLIC "--coverage")
get_target_property(LF ${_target} LINK_FLAGS) get_target_property(LF ${target} LINK_FLAGS)
string(APPEND LF " --coverage") string(APPEND LF " --coverage")
set_target_properties(${_target} PROPERTIES LINK_FLAGS ${LF}) set_target_properties(${target} PROPERTIES LINK_FLAGS ${LF})
if(LCOV_EXE) if(LCOV_EXE)
add_custom_target( add_custom_target(
coverage-${_target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} coverage-${target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${LCOV_EXE} --test-name ${_target} --output "${_target}.lcov" --capture --directory COMMAND ${LCOV_EXE} --test-name ${target} --output "${target}.lcov" --capture --directory
${CMAKE_BINARY_DIR}) ${CMAKE_BINARY_DIR})
add_dependencies(coverage-${_target} ${_target}) add_dependencies(coverage-${target} ${target})
if(GENHTML_EXE) if(GENHTML_EXE)
add_custom_target(coverage-report-${_target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} add_custom_target(coverage-report-${target} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${GENHTML_EXE} --output-directory "report-${_target}" "${_target}.lcov") COMMAND ${GENHTML_EXE} --output-directory "report-${target}" "${target}.lcov")
add_dependencies(coverage-report-${_target} coverage-${_target}) add_dependencies(coverage-report-${target} coverage-${target})
endif() endif()
endif() endif()
else() else()

View File

@ -1,41 +1,40 @@
# Создание статической и динамической библиотеки из одинаковых объектных файлов # Создание статической и динамической библиотеки из одинаковых объектных файлов
function(add_common_library) function(add_common_library target)
set(options) set(options)
set(oneValueArgs TARGET OUTPUT_NAME) set(oneValueArgs OUTPUT_NAME)
set(multiValueArgs SOURCES) set(multiValueArgs SOURCES)
cmake_parse_arguments(_LOCAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_LOCAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(LIBNAME ${_LOCAL_TARGET})
set(SOURCES ${_LOCAL_SOURCES}) set(SOURCES ${_LOCAL_SOURCES})
if(_LOCAL_OUTPUT_NAME) if(_LOCAL_OUTPUT_NAME)
set(OUTNAME ${_LOCAL_OUTPUT_NAME}) set(OUTNAME ${_LOCAL_OUTPUT_NAME})
else() else()
set(OUTNAME ${LIBNAME}) set(OUTNAME ${target})
endif() endif()
add_library(${LIBNAME} OBJECT ${SOURCES}) add_library(${target} OBJECT ${SOURCES})
target_include_directories( target_include_directories(
${LIBNAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> ${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> $<INSTALL_INTERFACE:include/${LIBNAME}>) $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> $<INSTALL_INTERFACE:include/${target}>)
set_target_properties(${LIBNAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
add_library(${LIBNAME}_shared SHARED $<TARGET_OBJECTS:${LIBNAME}>) add_library(${target}_shared SHARED $<TARGET_OBJECTS:${target}>)
set_target_properties( set_target_properties(
${LIBNAME}_shared ${target}_shared
PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} OUTPUT_NAME ${OUTNAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} OUTPUT_NAME ${OUTNAME}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}) 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() endif()
if(NOT SKIP_STATIC_LIBS) if(NOT SKIP_STATIC_LIBS)
add_library(${LIBNAME}_static STATIC $<TARGET_OBJECTS:${LIBNAME}>) add_library(${target}_static STATIC $<TARGET_OBJECTS:${target}>)
set_target_properties(${LIBNAME}_static PROPERTIES OUTPUT_NAME ${OUTNAME} ARCHIVE_OUTPUT_DIRECTORY set_target_properties(${target}_static PROPERTIES OUTPUT_NAME ${OUTNAME} ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_INSTALL_LIBDIR}) ${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${LIBNAME}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(TARGETS ${target}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif() endif()
configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${LIBNAME}.pc) configure_file(${CMLIB_MODULE_DIR}/pc/lib.pc.in ${CMAKE_BINARY_DIR}/${target}.pc)
install(FILES ${CMAKE_BINARY_DIR}/${LIBNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${CMAKE_BINARY_DIR}/${target}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endfunction() endfunction()

View File

@ -1,48 +1,49 @@
set(COMMON_CXX_FEATURES cxx_alias_templates cxx_nullptr cxx_override) set(COMMON_CXX_FEATURES cxx_alias_templates cxx_nullptr cxx_override)
function(common_target_properties Name) function(common_target_properties target)
get_target_property(__type ${Name} TYPE) get_target_property(__type ${target} TYPE)
set(__visibility PUBLIC) set(__visibility PUBLIC)
if(__type STREQUAL INTERFACE_LIBRARY) if(__type STREQUAL INTERFACE_LIBRARY)
set(__interface 1) set(__interface 1)
set(__visibility INTERFACE) set(__visibility INTERFACE)
endif() endif()
target_compile_features(${Name} ${__visibility} ${COMMON_CXX_FEATURES}) target_compile_features(${target} ${__visibility} ${COMMON_CXX_FEATURES})
get_target_property(_targetType ${Name} TYPE) get_target_property(_targetType ${target} TYPE)
if(_targetType STREQUAL "EXECUTABLE" AND CMAKE_CXX_COMPILE_OPTIONS_PIE) 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() endif()
target_include_directories( target_include_directories(
${Name} ${target}
PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>) $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
if(APPLE) if(APPLE)
target_compile_definitions(${Name} ${__visibility} Darwin) target_compile_definitions(${target} ${__visibility} Darwin)
endif() endif()
if(NOT __interface) if(NOT __interface)
if(TARGET Qt5::Core) if(TARGET Qt5::Core)
if(_targetType STREQUAL "EXECUTABLE") if(_targetType STREQUAL "EXECUTABLE")
target_compile_options(${Name} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") target_compile_options(${target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
endif() 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() endif()
if(TARGET Qt5::Widgets) 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) # if(CMAKE_VERSION VERSION_LESS 3.7.99)
# target_include_directories( # target_include_directories(
# ${Name} # ${target}
# PUBLIC # PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${Name}_autogen/include> # $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen/include>
# ) # )
# endif() # endif()
endif() endif()
if(CMAKE_CXX_COMPILER_IS_GCC AND NOT APPLE) 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()
endif() endif()
# LTO only for executables (not libraries) in Release build type # 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") if(target_type STREQUAL "EXECUTABLE" AND CMAKE_BUILD_TYPE STREQUAL "Release")
check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG) check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG)
check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_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() endif()
if(CMAKE_BUILD_TYPE STREQUAL Profile) if(CMAKE_BUILD_TYPE STREQUAL Profile)
target_compile_definitions(${Name} ${__visibility} PROFILE) target_compile_definitions(${target} ${__visibility} PROFILE)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug) elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
target_compile_definitions(${Name} ${__visibility} DEBUG) target_compile_definitions(${target} ${__visibility} DEBUG)
elseif(CMAKE_BUILD_TYPE STREQUAL Release) elseif(CMAKE_BUILD_TYPE STREQUAL Release)
target_compile_definitions(${Name} ${__visibility} RELEASE) target_compile_definitions(${target} ${__visibility} RELEASE)
elseif(CMAKE_BUILD_TYPE STREQUAL None) elseif(CMAKE_BUILD_TYPE STREQUAL None)
target_compile_definitions(${Name} ${__visibility} ANALYSIS) target_compile_definitions(${target} ${__visibility} ANALYSIS)
endif() endif()
target_compile_definitions( target_compile_definitions(
${Name} ${target}
${__visibility} ${__visibility}
"TARGET_LSB_ID_${LSB_DISTRIBUTOR_ID}" "TARGET_LSB_ID_${LSB_DISTRIBUTOR_ID}"
"TARGET_LSB_CODENAME_${LSB_CODENAME}") "TARGET_LSB_CODENAME_${LSB_CODENAME}")

View File

@ -24,9 +24,9 @@ else()
set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE) set(BREATHE_FOUND OFF CACHE STRING "Breathe documentation generator disabled" FORCE)
endif() endif()
function(add_breathe_target) function(add_breathe target)
set(options) set(options)
set(oneValueArgs TARGET_NAME COMMENT) set(oneValueArgs COMMENT)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_BREATHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@ -36,7 +36,6 @@ function(add_breathe_target)
set(GENERATE_XML YES) set(GENERATE_XML YES)
set(GENERATE_HTML NO) set(GENERATE_HTML NO)
set(GENERATE_LATEX NO) set(GENERATE_LATEX NO)
set(GENERATE_SQLITE NO)
set(CONF_FILE ${CMAKE_SOURCE_DIR}/cmake/doc/breathe-conf.py.in) set(CONF_FILE ${CMAKE_SOURCE_DIR}/cmake/doc/breathe-conf.py.in)
set(DOXY_FILE ${CMAKE_SOURCE_DIR}/cmake/doc/Doxyfile.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) configure_file(${DOXY_FILE} ${WORK_DIR}/Doxyfile @ONLY)
add_custom_target( add_custom_target(
${_BREATHE_TARGET_NAME} ${target}
VERBATIM VERBATIM
COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${WORK_DIR} -d ${WORK_DIR}/cache ${WORK_DIR} COMMAND ${SPHINX_EXECUTABLE} -q -b html -c ${WORK_DIR} -d ${WORK_DIR}/cache ${WORK_DIR}
${CMAKE_BINARY_DIR}/doc/breathe ${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) set(INDEX_MD_FILE ${CMAKE_SOURCE_DIR}/doc/breathe/index.md.in)
if(EXISTS ${INDEX_MD_FILE}) if(EXISTS ${INDEX_MD_FILE})
configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY) configure_file(${INDEX_MD_FILE} ${WORK_DIR}/index.md @ONLY)
file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md) file(GLOB MD_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.md)
if(MD_FILES) 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}) COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MD_FILES} ${WORK_DIR})
endif() endif()
endif() endif()
@ -65,12 +64,13 @@ function(add_breathe_target)
configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY) configure_file(${INDEX_RST_FILE} ${WORK_DIR}/index.rst @ONLY)
file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst) file(GLOB RST_FILES ${CMAKE_SOURCE_DIR}/doc/breathe/*.rst)
if(RST_FILES) 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}) COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RST_FILES} ${WORK_DIR})
endif() endif()
endif() endif()
else() else()
add_custom_target(${_BREATHE_TARGET_NAME} VERBATIM message(STATUS "CMLIB warning:")
COMMENT "Breathe is not found. Skipping target ${_BREATHE_TARGET_NAME} build") add_custom_target(${target} VERBATIM
COMMENT " Breathe is not found. Skipping target ${target} build")
endif() endif()
endfunction() endfunction()

View File

@ -8,39 +8,36 @@ else()
set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE) set(DOXYGEN_FOUND OFF CACHE STRING "Doxygen documentation generator disabled" FORCE)
endif() endif()
function(add_doxygen_target) function(add_doxygen target)
set(options) set(options)
set(oneValueArgs TARGET_NAME SQLITE LATEX HTML) set(oneValueArgs SQLITE LATEX HTML)
set(multiValueArgs) set(multiValueArgs)
cmake_parse_arguments(_DOXYGEN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_DOXYGEN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(DOXYGEN_FOUND) if(DOXYGEN_FOUND)
set(GENERATE_XML NO) set(GENERATE_XML YES)
set(GENERATE_HTML NO) set(GENERATE_HTML NO)
set(GENERATE_LATEX NO) set(GENERATE_LATEX NO)
set(GENERATE_SQLITE YES)
if(_DOXYGEN_HTML) if(_DOXYGEN_HTML)
set(GENERATE_HTML YES) set(GENERATE_HTML YES)
endif() endif()
if(_DOXYGEN_LATEX) if(_DOXYGEN_LATEX)
set(GENERATE_LATEX YES) set(GENERATE_LATEX YES)
endif() endif()
if(_DOXYGEN_SQLITE)
set(GENERATE_SQLITE YES)
endif()
set(WORK_DIR ${CMAKE_BINARY_DIR}/doc/doxygen) set(WORK_DIR ${CMAKE_BINARY_DIR}/doc/doxygen)
configure_file(${CMAKE_SOURCE_DIR}/cmake/doc/Doxyfile.in ${WORK_DIR}/Doxyfile @ONLY) configure_file(${CMAKE_SOURCE_DIR}/cmake/doc/Doxyfile.in ${WORK_DIR}/Doxyfile @ONLY)
add_custom_target( add_custom_target(
${_DOXYGEN_TARGET_NAME} ${target}
VERBATIM VERBATIM
COMMAND "${CMAKE_COMMAND}" -E remove -f "${WORK_DIR}/doxygen_sqlite3.db" COMMAND "${CMAKE_COMMAND}" -E remove -f "${WORK_DIR}/doxygen_sqlite3.db"
COMMAND ${DOXYGEN_EXECUTABLE} ${WORK_DIR}/Doxyfile COMMAND ${DOXYGEN_EXECUTABLE} ${WORK_DIR}/Doxyfile
WORKING_DIRECTORY ${WORK_DIR} WORKING_DIRECTORY ${WORK_DIR}
COMMENT "Generating API documentation with Doxygen") COMMENT "Generating API documentation with Doxygen")
else() else()
add_custom_target(${_DOXYGEN_TARGET_NAME} VERBATIM message(STATUS "CMLIB warning:")
COMMENT "Doxygen is not found. Skipping target ${_DOXYGEN_TARGET_NAME} build") add_custom_target(${target} VERBATIM
COMMENT " Doxygen is not found. Skipping target ${target} build")
endif() endif()
endfunction() endfunction()

View File

@ -1,7 +1,5 @@
function(add_format_sources) function(add_format_sources target)
list(GET ARGN 0 _target)
set(_sources ${ARGN}) set(_sources ${ARGN})
list(REMOVE_AT _sources 0)
if(NOT TARGET format-sources) if(NOT TARGET format-sources)
add_custom_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) if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg) list(APPEND UNCRUSTIFY_OPTS -c ${CMAKE_SOURCE_DIR}/cmake/etc/uncrustify/default.cfg)
endif() 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}) ${_sources})
add_dependencies(format-sources format-sources-uncrustify-${_target}) add_dependencies(format-sources format-sources-uncrustify-${target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " uncrustify executable is not found") message(STATUS " uncrustify executable is not found")
@ -30,8 +28,8 @@ function(add_format_sources)
find_program(DOS2UNIX_EXE NAMES dos2unix) find_program(DOS2UNIX_EXE NAMES dos2unix)
if(DOS2UNIX_EXE) if(DOS2UNIX_EXE)
list(APPEND DOS2UNIX_OPTS -k -r) list(APPEND DOS2UNIX_OPTS -k -r)
add_custom_target(format-sources-dos2unix-${_target} COMMAND ${DOS2UNIX_EXE} ${DOS2UNIX_OPTS} ${_sources}) add_custom_target(format-sources-dos2unix-${target} COMMAND ${DOS2UNIX_EXE} ${DOS2UNIX_OPTS} ${_sources})
add_dependencies(format-sources format-sources-dos2unix-${_target}) add_dependencies(format-sources format-sources-dos2unix-${target})
else() else()
message(STATUS "CMLIB warning:") message(STATUS "CMLIB warning:")
message(STATUS " dos2unix executable is not found") message(STATUS " dos2unix executable is not found")

View File

@ -1,50 +1,52 @@
function(qt5_translation) function(qt5_translation outfiles)
find_package(Qt5 COMPONENTS LinguistTools REQUIRED) find_package(Qt5 COMPONENTS LinguistTools REQUIRED)
set(options) set(options)
set(oneValueArgs TARGET TS_DIR) set(oneValueArgs BASE_NAME OUTPUT_DIR)
set(multiValueArgs SOURCES LANGUAGES) set(multiValueArgs SOURCES LANGUAGES)
cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(_QTTR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(_target ${_QTTR_TARGET}) set(_base_name ${_QTTR_BASE_NAME})
set(_sources ${_QTTR_SOURCES}) set(_sources ${_QTTR_SOURCES})
set(_ts_dir ${_QTTR_TS_DIR}) set(_output_dir ${_QTTR_OUTPUT_DIR})
set(_languages ${_QTTR_LANGUAGES}) set(_languages ${_QTTR_LANGUAGES})
set(L10N_QRC_BODY "") set(L10N_QRC_BODY "")
make_directory(${_ts_dir}) make_directory(${_output_dir})
foreach(_lang ${_languages}) foreach(_lang ${_languages})
set(_ts "${_target}_${_lang}.ts") set(_ts "${_base_name}_${_lang}.ts")
set(_qm "${_target}_${_lang}.qm") set(_qm "${_base_name}_${_lang}.qm")
list(APPEND _ts_list ${_ts_dir}/${_ts}) list(APPEND _ts_list ${_output_dir}/${_ts})
list(APPEND _l10n_targets "${_target}_l10n_${_lang}") list(APPEND _l10n_names "${_base_name}_l10n_${_lang}")
string(APPEND L10N_QRC_BODY "<file alias=\"${_qm}\">${CMAKE_BINARY_DIR}/${_qm}</file>\n") string(APPEND L10N_QRC_BODY "<file alias=\"${_qm}\">${CMAKE_BINARY_DIR}/${_qm}</file>\n")
add_custom_target( 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}) -target-language ${_lang} DEPENDS ${_sources})
if(NOT EXISTS "${_ts_dir}/${_ts}") if(NOT EXISTS "${_output_dir}/${_ts}")
add_custom_target(${_ts} DEPENDS ${_target}_l10n_${_lang}) add_custom_target(${_ts} DEPENDS ${_base_name}_l10n_${_lang})
else() else()
add_custom_target(${_ts} COMMAND echo "Skipping lupdate for ${_ts}") add_custom_target(${_ts} COMMAND echo "Skipping lupdate for ${_ts}")
endif() endif()
add_custom_command( 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}) ${CMAKE_BINARY_DIR}/${_qm} DEPENDS ${_ts} ${_sources})
endforeach() endforeach()
configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc) configure_file(${CMLIB_MODULE_DIR}/qrc/l10n.qrc.in ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc)
qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_target}_l10n.qrc) # qt5_add_resources(_qrc ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc)
add_custom_target(${_target}_qrc DEPENDS ${_qrc}) list(APPEND ${outfiles} ${CMAKE_BINARY_DIR}/${_base_name}_l10n.qrc)
add_custom_target(${_target}_l10n DEPENDS ${_l10n_targets}) # add_custom_target(${_base_name}_qrc DEPENDS ${_qrc})
# add_custom_target(${_base_name}_l10n DEPENDS ${_l10n_targets})
if(NOT TARGET l10n) if(NOT TARGET l10n)
add_custom_target(l10n) add_custom_target(l10n)
endif() endif()
add_dependencies(l10n ${_target}_l10n) add_dependencies(l10n ${_target}_l10n)
add_dependencies(${_target} ${_target}_qrc) # add_dependencies(${_target} ${_target}_qrc)
target_sources(${_target} PUBLIC ${_qrc}) # target_sources(${_target} PUBLIC ${_qrc})
set(${outfiles} ${${outfiles}} PARENT_SCOPE)
endfunction() endfunction()