Обновление MyxCMake

This commit is contained in:
Andrei Astafev 2023-08-17 12:19:02 +03:00
parent c92c854035
commit 99104087fb
8 changed files with 229 additions and 194 deletions

View File

@ -38,6 +38,7 @@ include(CMakeDependentOption)
# Полезные макросы # Полезные макросы
include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/FindPackages.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/FindQt.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/InstallRelative.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/CheckEnableCxxCompilerFlag.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/CheckEnableCxxCompilerFlag.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/GTest.cmake) include(${MYX_CMAKE_LIB_DIR}/macro/GTest.cmake)
@ -60,7 +61,7 @@ include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddInterfaceLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/AddInterfaceLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/AddObjectLibrary.cmake) include(${MYX_CMAKE_LIB_DIR}/AddObjectLibrary.cmake)
include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake) include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake)
include(${MYX_CMAKE_LIB_DIR}/macro/QtTargetSetup.cmake) include(${MYX_CMAKE_LIB_DIR}/TargetSetupQt.cmake)
include(${MYX_CMAKE_LIB_DIR}/uncrustify/Uncrustify.cmake) include(${MYX_CMAKE_LIB_DIR}/uncrustify/Uncrustify.cmake)
include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake) include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake)

View File

@ -1,4 +1,4 @@
set(MYX_CMAKE_PACKAGE_VERSION "2.4.5") set(MYX_CMAKE_PACKAGE_VERSION "2.4.12")
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE) set(PACKAGE_VERSION_COMPATIBLE FALSE)
else() else()

View File

@ -7,15 +7,20 @@ myx_download_content
myx_download_content(NAME myx_download_content(NAME
[ DOWNLOAD_DIR dir ] | [ DOWNLOAD_DIR dir ] |
[ GIT_REPOSITORY url ] | [ GIT_REPOSITORY url ] |
[ GIT_TAG tag ] ) [ GIT_TAG tag ] |
[ AUTOFETCH ] | [ AUTOPULL ] )
Обязательный параметр: `NAME` - имя целевого каталога. Обязательный параметр: `NAME` - имя целевого каталога.
Параметр `DOWNLOAD_DIR` содержит имя каталога, в который будет загружаться Параметр `DOWNLOAD_DIR` содержит имя каталога, в который будет загружаться
содержимое (по умолчанию `downloads`). содержимое (по умолчанию `_downloads`).
Параметр `GIT_REPOSITORY` содержит адрес внешнего проекта, который нужно Параметр `GIT_REPOSITORY` содержит адрес внешнего проекта, который нужно
загрузить с помощью git. загрузить с помощью git.
Параметр `GIT_TAG` содержит используемые метку, идентификатор коммита или Параметр `GIT_TAG` содержит используемые метку, идентификатор коммита или
ветку в загружаемом репозитории. ветку в загружаемом репозитории.
Если указана опция `AUTOFETCH`, то на этапе конфигурирования для загруженного
репозитория будут скачиваться изменения.
Если указана опция `AUTOPULL`, то на этапе конфигурирования из загруженного
репозитория будет изменяться рабочий каталог.
#]=======================================================================] #]=======================================================================]
@ -24,7 +29,7 @@ find_package(Git QUIET)
option(ENABLE_DOWNLOAD_CONTENT "Enable download content" ON) option(ENABLE_DOWNLOAD_CONTENT "Enable download content" ON)
function(myx_download_content NAME) function(myx_download_content NAME)
set(options) set(options AUTOFETCH AUTOPULL)
set(oneValueArgs) set(oneValueArgs)
set(multiValueArgs DOWNLOAD_DIR GIT_REPOSITORY GIT_TAG) set(multiValueArgs DOWNLOAD_DIR GIT_REPOSITORY GIT_TAG)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@ -53,20 +58,30 @@ function(myx_download_content NAME)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_DOWNLOAD_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_DOWNLOAD_DIR})
endif() endif()
set(WORK_DIR "${ARG_DOWNLOAD_DIR}/${NAME}")
if(ENABLE_DOWNLOAD_CONTENT AND GIT_EXECUTABLE AND ARG_GIT_REPOSITORY) if(ENABLE_DOWNLOAD_CONTENT AND GIT_EXECUTABLE AND ARG_GIT_REPOSITORY)
if(NOT IS_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME}) if(NOT IS_DIRECTORY ${WORK_DIR})
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${NAME} execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${NAME}
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}) WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR})
else() else()
if(ARG_AUTOFETCH)
execute_process(COMMAND ${GIT_EXECUTABLE} fetch execute_process(COMMAND ${GIT_EXECUTABLE} fetch
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME}) WORKING_DIRECTORY ${WORK_DIR})
endif() endif()
endif()
if(ARG_GIT_TAG)
execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG} execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG}
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME}) WORKING_DIRECTORY ${WORK_DIR})
else()
if(ARG_AUTOPULL)
execute_process(COMMAND ${GIT_EXECUTABLE} pull
WORKING_DIRECTORY ${WORK_DIR})
endif()
endif()
endif() endif()
if(NOT CMAKE_SCRIPT_MODE_FILE) if(NOT CMAKE_SCRIPT_MODE_FILE AND EXISTS "${WORK_DIR}/CMakeLists.txt")
add_subdirectory(${ARG_DOWNLOAD_DIR}/${NAME} EXCLUDE_FROM_ALL) add_subdirectory(${WORK_DIR} EXCLUDE_FROM_ALL)
endif() endif()
endfunction() endfunction()

View File

@ -0,0 +1,153 @@
include_guard(GLOBAL)
function(myx_target_setup_qt TARGET_NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(myx_qt_ver "5")
if(QT_DEFAULT_MAJOR_VERSION)
set(myx_qt_ver "${QT_DEFAULT_MAJOR_VERSION}")
endif()
if(NOT (myx_qt_ver STREQUAL "5" OR myx_qt_ver STREQUAL "6"))
myx_message_fatal_error("Supported Qt versions are 5 and 6")
endif()
get_target_property(__target_type ${TARGET_NAME} TYPE)
foreach(iter ${ARG_COMPONENTS})
if(__target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_INCLUDE_DIRS})
else()
target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
endif()
if(NOT iter STREQUAL "LinguistTools")
if(__target_type STREQUAL "EXECUTABLE")
target_link_libraries(${TARGET_NAME} PRIVATE Qt${myx_qt_ver}::${iter})
endif()
if(__target_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(${TARGET_NAME} PUBLIC Qt${myx_qt_ver}::${iter})
endif()
if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (__target_type STREQUAL "OBJECT_LIBRARY"))
target_link_libraries(${TARGET_NAME} PUBLIC Qt${myx_qt_ver}::${iter})
endif()
endif()
endforeach()
foreach(iter ${ARG_PRIVATE})
if(__target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${TARGET_NAME} INTERFACE ${Qt${myx_qt_ver}${iter}_PRIVATE_INCLUDE_DIRS})
else()
target_include_directories(${TARGET_NAME} PRIVATE ${Qt${myx_qt_ver}${iter}_PRIVATE_INCLUDE_DIRS})
endif()
endforeach()
if(__target_type STREQUAL "EXECUTABLE")
target_compile_options(${TARGET_NAME} PRIVATE ${Qt${myx_qt_ver}Core_EXECUTABLE_COMPILE_FLAGS})
endif()
if(ARG_PUBLIC_MOC)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
endif()
if(ARG_PRIVATE_MOC)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
endif()
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
if(myx_qt_ver EQUAL 5)
qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC})
elseif(myx_qt_ver EQUAL 6)
qt6_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC})
endif()
endif()
if(ARG_QRC)
if(myx_qt_ver EQUAL 5)
qt5_add_resources(qrc_cpp ${ARG_QRC})
elseif(myx_qt_ver EQUAL 6)
qt6_add_resources(qrc_cpp ${ARG_QRC})
endif()
endif()
if(ARG_UI)
if(NOT COMMAND qt${myx_qt_ver}_wrap_ui)
message(WARNING "MyxCMake: Widgets is required to process UI")
else()
if(myx_qt_ver EQUAL 5)
qt5_wrap_ui(ui_h ${ARG_UI})
elseif(myx_qt_ver EQUAL 6)
qt6_wrap_ui(ui_h ${ARG_UI})
endif()
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
target_link_libraries(${TARGET_NAME} PRIVATE Qt${myx_qt_ver}::Widgets)
# TODO
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
endif()
endif()
# Перечень файлов, подлежащих переводу
if(__target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(tr ${TARGET_NAME} INTERFACE_TR_FILES)
else()
get_target_property(tr ${TARGET_NAME} TR_FILES)
endif()
# Формирование файла ресурсов с переводами
if(tr AND ARG_LANGS)
if(NOT COMMAND qt${myx_qt_ver}_create_translation)
message(WARNING "MyxCMake: LinguistTools is required to process LANGS")
else()
# Заглавие файла ресурсов
file(WRITE ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "<RCC><qresource prefix=\"/l10n\">\n")
# Для каждого языка, указанное в параметре LANGS
foreach(iter ${ARG_LANGS})
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
# и его компиляция в каталог ${PROJECT_BINARY_DIR}
if(myx_qt_ver EQUAL 5)
qt5_create_translation(qm ${tr}
"${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts"
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
elseif(myx_qt_ver EQUAL 6)
qt6_create_translation(qm ${tr}
"${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts"
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
endif()
# Добавление записи для скомпилированного файла переводов в ресурсный файл
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc
"<file alias=\"${TARGET_NAME}_${iter}.qm\">${TARGET_NAME}_${iter}.qm</file>\n")
# Добавление скомпилированного файла переводов к списку зависимостей для цели
target_sources(${TARGET_NAME} PRIVATE ${qm})
endforeach()
# Окончание файла ресурсов
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "</qresource></RCC>\n")
# Компиляция файла ресурсов с переводами
if(myx_qt_ver EQUAL 5)
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
elseif(myx_qt_ver EQUAL 6)
qt6_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
endif()
target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n})
endif()
endif()
unset(tr)
if(__target_type STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
else()
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
endif()
# Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL)
myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_MOC}
DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT DEV
)
endif()
endfunction()

View File

@ -0,0 +1,40 @@
include_guard(GLOBAL)
macro(myx_find_qt)
set(options REQUIRED)
set(oneValueArgs VERSION)
set(multiValueArgs COMPONENTS PRIVATE)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_VERSION)
set(ARG_VERSION "5")
if(QT_DEFAULT_MAJOR_VERSION)
set(ARG_VERSION "${QT_DEFAULT_MAJOR_VERSION}")
endif()
endif()
if(ARG_REQUIRED)
set(ARG_REQUIRED "REQUIRED")
endif()
if(NOT (ARG_VERSION STREQUAL "5" OR ARG_VERSION STREQUAL "6"))
message(FATAL_ERROR "Supported Qt versions are 5 and 6")
endif()
foreach(iter ${ARG_COMPONENTS})
find_package(Qt${ARG_VERSION} COMPONENTS ${iter} ${ARG_REQUIRED})
endforeach()
foreach(iter ${ARG_PRIVATE})
find_package("Qt${ARG_VERSION}${iter}" COMPONENTS Private ${ARG_REQUIRED})
endforeach()
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()

View File

@ -1,176 +0,0 @@
include_guard(GLOBAL)
macro(myx_qt_target_setup TARGET_NAME)
set(options)
set(oneValueArgs VERSION)
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_VERSION)
set(ARG_VERSION "5")
endif()
if(NOT (ARG_VERSION STREQUAL "5" OR ARG_VERSION STREQUAL "6"))
myx_message_fatal_error("Supported Qt versions are 5 and 6")
endif()
foreach(iter ${ARG_COMPONENTS})
find_package(Qt${ARG_VERSION} COMPONENTS ${iter} REQUIRED)
endforeach()
foreach(iter ${ARG_PRIVATE})
find_package("Qt${ARG_VERSION}${iter}" COMPONENTS Private REQUIRED)
endforeach()
myx_qt_target_setup_post(${ARGV})
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()
function(myx_qt_target_setup_post TARGET_NAME)
set(options)
set(oneValueArgs VERSION)
set(multiValueArgs COMPONENTS PRIVATE PUBLIC_MOC PRIVATE_MOC UI QRC LANGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT ARG_VERSION)
set(ARG_VERSION "5")
endif()
if(NOT (ARG_VERSION STREQUAL "5" OR ARG_VERSION STREQUAL "6"))
myx_message_fatal_error("Supported Qt versions are 5 and 6")
endif()
get_target_property(__target_type ${TARGET_NAME} TYPE)
foreach(iter ${ARG_COMPONENTS})
if(__target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${TARGET_NAME} INTERFACE ${Qt${ARG_VERSION}${iter}_INCLUDE_DIRS})
else()
target_include_directories(${TARGET_NAME} PRIVATE ${Qt${ARG_VERSION}${iter}_INCLUDE_DIRS})
endif()
if(NOT iter STREQUAL "LinguistTools")
if(__target_type STREQUAL "EXECUTABLE")
target_link_libraries(${TARGET_NAME} PRIVATE "Qt${ARG_VERSION}::${iter}")
endif()
if(__target_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(${TARGET_NAME} PUBLIC "Qt${ARG_VERSION}::${iter}")
endif()
if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (__target_type STREQUAL "OBJECT_LIBRARY"))
target_link_libraries(${TARGET_NAME} PUBLIC "Qt${ARG_VERSION}::${iter}")
endif()
endif()
endforeach()
foreach(iter ${ARG_PRIVATE})
if(__target_type STREQUAL "INTERFACE_LIBRARY")
target_include_directories(${TARGET_NAME} INTERFACE ${Qt${ARG_VERSION}${iter}_PRIVATE_INCLUDE_DIRS})
else()
target_include_directories(${TARGET_NAME} PRIVATE ${Qt${ARG_VERSION}${iter}_PRIVATE_INCLUDE_DIRS})
endif()
endforeach()
if(__target_type STREQUAL "EXECUTABLE")
target_compile_options(${TARGET_NAME} PRIVATE ${Qt${ARG_VERSION}Core_EXECUTABLE_COMPILE_FLAGS})
endif()
if(ARG_PUBLIC_MOC)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PUBLIC_MOC})
endif()
if(ARG_PRIVATE_MOC)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES "${ARG_PRIVATE_MOC}")
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_PRIVATE_MOC})
endif()
if(ARG_PUBLIC_MOC OR ARG_PRIVATE_MOC)
if(ARG_VERSION STREQUAL "5")
qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC})
else()
qt6_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC})
endif()
endif()
if(ARG_QRC)
if(ARG_VERSION STREQUAL "5")
qt5_add_resources(qrc_cpp ${ARG_QRC})
else()
qt6_add_resources(qrc_cpp ${ARG_QRC})
endif()
endif()
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
if(ARG_VERSION STREQUAL "5")
qt5_wrap_ui(ui_h ${ARG_UI})
else()
qt6_wrap_ui(ui_h ${ARG_UI})
endif()
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY TR_FILES ${ARG_UI})
# TODO
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
endif()
# Перечень файлов, подлежащих переводу
if(__target_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(tr ${TARGET_NAME} INTERFACE_TR_FILES)
else()
get_target_property(tr ${TARGET_NAME} TR_FILES)
endif()
# Формирование файла ресурсов с переводами
if("LinguistTools" IN_LIST ARG_COMPONENTS AND tr)
# Заглавие файла ресурсов
file(WRITE ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "<RCC><qresource prefix=\"/qm\">\n")
# Для каждого языка, указанное в параметре LANGS
foreach(iter ${ARG_LANGS})
# Создание или обновление файла переводов в каталоге ${PROJECT_SOURCE_DIR}/l10n
# и его компиляция в каталог ${PROJECT_BINARY_DIR}
if(ARG_VERSION STREQUAL "5")
qt5_create_translation(qm ${tr}
"${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts"
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
else()
qt6_create_translation(qm ${tr}
"${PROJECT_SOURCE_DIR}/l10n/${TARGET_NAME}_${iter}.ts"
OPTIONS -I ${PROJECT_SOURCE_DIR}/include -I ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME})
endif()
# Добавление записи для скомпилированного файла переводов в ресурсный файл
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc
"<file alias=\"${TARGET_NAME}_${iter}\">${TARGET_NAME}_${iter}.qm</file>\n")
# Добавление скомпилированного файла переводов к списку зависимостей для цели
target_sources(${TARGET_NAME} PRIVATE ${qm})
endforeach()
# Окончание файла ресурсов
file(APPEND ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc "</qresource></RCC>\n")
# Компиляция файла ресурсов с переводами
if(ARG_VERSION STREQUAL "5")
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
else()
qt6_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
endif()
target_sources(${TARGET_NAME} PRIVATE ${qrc_l10n})
endif()
unset(tr)
if(__target_type STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
else()
target_sources(${TARGET_NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
endif()
# Установка публичных заголовочных файлов
if(PROJECT_IS_TOP_LEVEL)
myx_install_relative(${PROJECT_SOURCE_DIR}
FILES ${ARG_PUBLIC_MOC}
DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT DEV
)
endif()
endfunction()

View File

@ -9,10 +9,6 @@ function(myx_uncrustify TARGET_NAME)
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT}) set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
endif() endif()
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
return()
endif()
set(options) set(options)
set(oneValueArgs CONFIG) set(oneValueArgs CONFIG)
set(multiValueArgs) set(multiValueArgs)
@ -32,6 +28,12 @@ function(myx_uncrustify TARGET_NAME)
return() return()
endif() endif()
get_filename_component(CONFIG_DIR ${ARG_CONFIG} DIRECTORY)
if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CONFIG_DIR}")
myx_message("MyxCMake: skip uncrustify for project ${PROJECT_NAME}")
return()
endif()
if(NOT TARGET myx-uncrustify) if(NOT TARGET myx-uncrustify)
add_custom_target(myx-uncrustify) add_custom_target(myx-uncrustify)
endif() endif()

View File

@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR})
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR}) set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
endif() endif()
if(MYX_CMAKE_DIR) if(MYX_CMAKE_DIR)
find_package(MyxCMake 2.4.5 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH) find_package(MyxCMake 2.4.12 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==") myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==")
else() else()
if(MYX_CMAKE_USE_SYSTEM) if(MYX_CMAKE_USE_SYSTEM)
find_package(MyxCMake 2.4.5 REQUIRED) find_package(MyxCMake 2.4.12 REQUIRED)
myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==") myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==")
else() else()
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake) include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)