From 366902c0a36e9136b9f5f65fdc3b8868cebf60bb Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 7 Apr 2022 14:17:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=200.5.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- .../MyxCMakeCommonTargetProperties.cmake | 87 ++++++++++--------- MyxCMake/modules/MyxCMakeFormatSources.cmake | 10 +-- 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6630af1..8e72919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(myx-cmake VERSION 0.5.2 LANGUAGES) +project(myx-cmake VERSION 0.5.3 LANGUAGES) include(GNUInstallDirs) file(WRITE ${CMAKE_SOURCE_DIR}/MyxCMake/MyxCMakeConfigVersion.cmake diff --git a/MyxCMake/modules/MyxCMakeCommonTargetProperties.cmake b/MyxCMake/modules/MyxCMakeCommonTargetProperties.cmake index eae8a71..96d2e3d 100644 --- a/MyxCMake/modules/MyxCMakeCommonTargetProperties.cmake +++ b/MyxCMake/modules/MyxCMakeCommonTargetProperties.cmake @@ -1,4 +1,5 @@ -function(myx_cmake_common_target_properties target) +function(myx_cmake_compile_target_properties target) + if(NOT TARGET ${target}) myx_cmake_message_error("MyxCMake: Target ${target} does not exists.") endif() @@ -11,8 +12,7 @@ function(myx_cmake_common_target_properties target) # if(TARGET Qt5::Core) if(_target_type STREQUAL EXECUTABLE) - target_compile_options(${target} - PUBLIC ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}) + target_compile_options(${target} PUBLIC ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}) endif() if(NOT MYX_CMAKE_DEBUG_OUTPUT) target_compile_definitions(${target} PUBLIC QT_NO_DEBUG_OUTPUT) @@ -49,10 +49,7 @@ function(myx_cmake_common_target_properties target) $ $) - endif() - - target_compile_features(${target} ${__visibility} cxx_alias_templates - cxx_nullptr cxx_override) + target_compile_features(${target} ${__visibility} cxx_alias_templates cxx_nullptr cxx_override) if(_target_type STREQUAL EXECUTABLE) set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON @@ -71,11 +68,6 @@ function(myx_cmake_common_target_properties target) set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() - if(_target_type MATCHES "_LIBRARY$" AND NOT ${target}-install-headers) - # Цель, используемая только для установки заголовочных файлов без компиляции проекта - add_custom_target(${target}-install-headers - COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=dev - -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") endif() # LTO only for executables (not libraries) in Release build type @@ -113,6 +105,12 @@ function(myx_cmake_common_target_properties target) target_compile_definitions( ${target} ${__visibility} "MYX_CMAKE_LSB_CODENAME_${MYX_CMAKE_LSB_CODENAME}") +endfunction() + + +function(myx_cmake_common_target_properties target) + + myx_cmake_compile_target_properties(${target}) myx_cmake_analyze_clang_tidy(${target}) myx_cmake_analyze_clang_check(${target}) @@ -120,6 +118,13 @@ function(myx_cmake_common_target_properties target) myx_cmake_analyze_pvs_studio(${target}) myx_cmake_format_sources(${target}) + if(_target_type MATCHES "_LIBRARY$" AND NOT ${target}-install-headers) + # Цель, используемая только для установки заголовочных файлов без компиляции проекта + add_custom_target(${target}-install-headers + COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=dev + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") + endif() + # Создание в каталоге ${CMAKE_BINARY_DIR} стандартных каталогов bin,include,lib if(NOT TARGET ${target}-default-directories) add_custom_target( @@ -152,6 +157,35 @@ function(myx_cmake_common_target_properties target) endif() endfunction() + +function(myx_cmake_qt_autogen_target_properties target) + + myx_cmake_compile_target_properties(${target}) + + get_target_property(_target_type ${target} TYPE) + if(NOT _target_type STREQUAL OBJECT_LIBRARY) + myx_cmake_message_error("MyxCMake: Target ${target} must have type OBJECT ${_target_type}.") + endif() + + get_target_property(__sources ${target} SOURCES) + foreach(src IN LISTS __sources) + string(REGEX MATCH ".*/ui_.*\\.h$" __ui ${src}) + if(__ui) + target_include_directories(${target} SYSTEM PUBLIC ${Qt5Widgets_INCLUDE_DIRS}) + endif() + endforeach() + + foreach(src IN LISTS __sources) + string(REGEX MATCH ".*/moc_.*\\.cpp$" __moc ${src}) + if(__moc) + target_include_directories(${target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) + endif() + endforeach() + + set_target_properties(${target} PROPERTIES CXX_CLANG_TIDY "") +endfunction() + + function(myx_cmake_common_target_properties_post_link target) if(NOT TARGET ${target}) myx_cmake_message_error("MyxCMake: Target ${target} does not exists.") @@ -175,32 +209,3 @@ function(myx_cmake_common_target_properties_post_link target) endif() endfunction() -function(myx_cmake_qt_autogen_target_properties target) - if(NOT TARGET ${target}) - myx_cmake_message_error("MyxCMake: Target ${target} does not exists.") - endif() - - get_target_property(_target_type ${target} TYPE) - if(NOT _target_type STREQUAL OBJECT_LIBRARY) - myx_cmake_message_error("MyxCMake: Target ${target} must have type OBJECT ${_target_type}.") - endif() - - myx_cmake_common_target_properties(${target}) - get_target_property(__sources ${target} SOURCES) - foreach(src IN LISTS __sources) - string(REGEX MATCH ".*/ui_.*\\.h$" __ui ${src}) - if(__ui) - target_include_directories(${target} SYSTEM PUBLIC ${Qt5Widgets_INCLUDE_DIRS}) - endif() - endforeach() - - foreach(src IN LISTS __sources) - string(REGEX MATCH ".*/moc_.*\\.cpp$" __moc ${src}) - if(__moc) - target_include_directories(${target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - endif() - endforeach() - - set_target_properties(${target} PROPERTIES CXX_CLANG_TIDY "") -endfunction() - diff --git a/MyxCMake/modules/MyxCMakeFormatSources.cmake b/MyxCMake/modules/MyxCMakeFormatSources.cmake index 92de281..a5a6165 100644 --- a/MyxCMake/modules/MyxCMakeFormatSources.cmake +++ b/MyxCMake/modules/MyxCMakeFormatSources.cmake @@ -41,12 +41,12 @@ function(myx_cmake_format_sources target) add_custom_target(myx-cmake-format-sources) endif() - if(UNCRUSTIFY_EXE) - get_target_property(__sources ${target} SOURCES) - list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$") - list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$") - list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$") + get_target_property(__sources ${target} SOURCES) + list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$") + list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$") + list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$") + if(UNCRUSTIFY_EXE) if(NOT TARGET myx-cmake-format-sources-check) add_custom_target(myx-cmake-format-sources-check) endif()