Compare commits
2 Commits
cb54741867
...
718d90ed07
Author | SHA1 | Date | |
---|---|---|---|
718d90ed07 | |||
85d550a147 |
@ -11,14 +11,12 @@ project(myx-example-base VERSION 0.4.0 LANGUAGES CXX)
|
||||
include(cmake/myx_setup.cmake)
|
||||
|
||||
# Поиск пакетов
|
||||
myx_find_required_packages(
|
||||
PACKAGES Git CURL PkgConfig Quadmath
|
||||
Qt5 Core
|
||||
Qt5Private Core)
|
||||
|
||||
# Поиск библиотек с помощью pkgconfig
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(UDEV udev)
|
||||
myx_find_packages(
|
||||
REQUIRED Git
|
||||
OPTIONAL CURL Quadmath
|
||||
PKG_REQUIRED udev
|
||||
PKG_OPTIONAL glib-2.0
|
||||
)
|
||||
|
||||
# Поиск с помощью функции find_package
|
||||
find_package(Boost 1.55.0 COMPONENTS system REQUIRED)
|
||||
|
@ -38,6 +38,7 @@ include(CMakeDependentOption)
|
||||
# Полезные макросы
|
||||
include(${MYX_CMAKE_LIB_DIR}/macro/CreateSymlink.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/CheckEnableCxxCompilerFlag.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/macro/GTest.cmake)
|
||||
@ -50,8 +51,7 @@ include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWarning.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/DirectoriesGuards.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/SemanticProjectVersion.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/NinjaGeneratorWrapper.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddExternalTarget.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/FetchContentAdd.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/DownloadContent.cmake)
|
||||
|
||||
set(MYX_CMAKE_TOOLCHAINS_DIR "${MYX_CMAKE_LIB_DIR}/toolchains")
|
||||
include(${MYX_CMAKE_LIB_DIR}/Toolchains.cmake)
|
||||
@ -61,7 +61,7 @@ include(${MYX_CMAKE_LIB_DIR}/AddExecutable.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddInterfaceLibrary.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/AddObjectLibrary.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/TargetSetup.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/Qt5TargetSetup.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/TargetSetupQt.cmake)
|
||||
|
||||
include(${MYX_CMAKE_LIB_DIR}/uncrustify/Uncrustify.cmake)
|
||||
include(${MYX_CMAKE_LIB_DIR}/doc/Doxygen.cmake)
|
||||
|
@ -1,4 +1,4 @@
|
||||
set(MYX_CMAKE_PACKAGE_VERSION "2.3.8")
|
||||
set(MYX_CMAKE_PACKAGE_VERSION "2.4.10")
|
||||
if(MYX_CMAKE_PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
||||
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
||||
else()
|
||||
|
@ -1,79 +0,0 @@
|
||||
#[=======================================================================[.rst:
|
||||
myx_add_external_target
|
||||
-----------------------
|
||||
|
||||
Функция для подключения целей из внешних проектов::
|
||||
|
||||
myx_add_external_target(TARGET_NAME
|
||||
[ MODULES_PATH modules_path ] |
|
||||
[ GIT_REPOSITORY url ] |
|
||||
[ GIT_TAG tag ] |
|
||||
[ LOCAL_PATH local_path ] )
|
||||
|
||||
Обязательный параметр: `TARGET_NAME` - имя цели, содержащейся во внешнем проекте.
|
||||
Параметр `MODULES_PATH` содержит имя каталога, в который будут загружаться
|
||||
внешние проекты (по умолчанию `modules`). Параметр `GIT_REPOSITORY` содержит
|
||||
адрес внешнего проекта, который нужно загрузить с помощью git. Параметр `GIT_TAG`
|
||||
содержит используемые метку, идентификатор коммита или ветку в репозитории.
|
||||
Параметр `LOCAL_PATH` используется для указания пути к подкаталогу, находящемуся
|
||||
вне текущего проекта. Его следует указывать только при вызове функции из
|
||||
вспомогательного файла `external_targets.cmake`.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
|
||||
find_package(Git)
|
||||
|
||||
function(myx_add_external_target TARGET_NAME)
|
||||
set(options)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs MODULES_PATH GIT_REPOSITORY GIT_TAG LOCAL_PATH)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(TARGET ${TARGET_NAME})
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(ARG_LOCAL_PATH)
|
||||
myx_message_notice("Using directory ${ARG_LOCAL_PATH} to build target ${TARGET_NAME}")
|
||||
add_subdirectory(${ARG_LOCAL_PATH} ${CMAKE_BINARY_DIR}/${TARGET_NAME} EXCLUDE_FROM_ALL)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT ARG_MODULES_PATH)
|
||||
set(ARG_MODULES_PATH modules)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SCRIPT_MODE_FILE)
|
||||
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR})
|
||||
endif()
|
||||
set(ARG_MODULES_PATH ${PROJECT_SOURCE_DIR}/${ARG_MODULES_PATH})
|
||||
|
||||
if(NOT IS_DIRECTORY ${ARG_MODULES_PATH})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_MODULES_PATH})
|
||||
endif()
|
||||
|
||||
if(GIT_EXECUTABLE)
|
||||
if(NOT IS_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME})
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${TARGET_NAME}
|
||||
WORKING_DIRECTORY ${ARG_MODULES_PATH})
|
||||
else()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} fetch
|
||||
WORKING_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME})
|
||||
endif()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG}
|
||||
WORKING_DIRECTORY ${ARG_MODULES_PATH}/${TARGET_NAME})
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SCRIPT_MODE_FILE)
|
||||
add_subdirectory(${ARG_MODULES_PATH}/${TARGET_NAME} EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ${TARGET_NAME})
|
||||
myx_message_fatal_error("Target ${TARGET_NAME} is not found.")
|
||||
endif()
|
||||
|
||||
endfunction(myx_add_external_target)
|
||||
|
||||
include("${PROJECT_SOURCE_DIR}/external_targets.cmake" OPTIONAL)
|
||||
|
@ -50,6 +50,7 @@ function(myx_add_interface_library TARGET_NAME)
|
||||
add_library(${TARGET_NAME} INTERFACE ${ARG_HEADERS})
|
||||
endif()
|
||||
|
||||
|
||||
foreach(__iter ${ARG_PACKAGES})
|
||||
target_include_directories(${TARGET_NAME} INTERFACE ${${__iter}_INCLUDE_DIRS})
|
||||
target_compile_definitions(${TARGET_NAME} INTERFACE ${${__iter}_COMPILE_DEFINITIONS})
|
||||
@ -71,7 +72,10 @@ function(myx_add_interface_library TARGET_NAME)
|
||||
|
||||
# Библиотека, состоящая только из заголовочных файлов не требует сборки.
|
||||
# Стандартные пути к заголовочным файлам
|
||||
target_include_directories(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
target_include_directories(${TARGET_NAME} INTERFACE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
# Если вызов был выполнен не из проекта верхнего уровня,
|
||||
# то созданная цель исключается из цели `all`.
|
||||
|
77
cmake/myx/lib/DownloadContent.cmake
Normal file
77
cmake/myx/lib/DownloadContent.cmake
Normal file
@ -0,0 +1,77 @@
|
||||
#[=======================================================================[.rst:
|
||||
myx_download_content
|
||||
-----------------------
|
||||
|
||||
Функция для загрузки дополнительных репозиториев::
|
||||
|
||||
myx_download_content(NAME
|
||||
[ DOWNLOAD_DIR dir ] |
|
||||
[ GIT_REPOSITORY url ] |
|
||||
[ GIT_TAG tag ] )
|
||||
|
||||
Обязательный параметр: `NAME` - имя целевого каталога.
|
||||
Параметр `DOWNLOAD_DIR` содержит имя каталога, в который будет загружаться
|
||||
содержимое (по умолчанию `downloads`).
|
||||
Параметр `GIT_REPOSITORY` содержит адрес внешнего проекта, который нужно
|
||||
загрузить с помощью git.
|
||||
Параметр `GIT_TAG` содержит используемые метку, идентификатор коммита или
|
||||
ветку в загружаемом репозитории.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
find_package(Git QUIET)
|
||||
|
||||
option(ENABLE_DOWNLOAD_CONTENT "Enable download content" ON)
|
||||
|
||||
function(myx_download_content NAME)
|
||||
set(options)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs DOWNLOAD_DIR GIT_REPOSITORY GIT_TAG)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(NOT CMAKE_SCRIPT_MODE_FILE)
|
||||
if(TARGET myx-download-${NAME})
|
||||
return()
|
||||
else()
|
||||
add_custom_target(myx-download-${NAME})
|
||||
endif()
|
||||
if(NOT TARGET myx-download-content)
|
||||
add_custom_target(myx-download-content)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT ARG_DOWNLOAD_DIR)
|
||||
set(ARG_DOWNLOAD_DIR "_downloads")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SCRIPT_MODE_FILE)
|
||||
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
endif()
|
||||
set(ARG_DOWNLOAD_DIR ${PROJECT_SOURCE_DIR}/${ARG_DOWNLOAD_DIR})
|
||||
|
||||
if(NOT IS_DIRECTORY ${ARG_DOWNLOAD_DIR})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_DOWNLOAD_DIR})
|
||||
endif()
|
||||
|
||||
if(ENABLE_DOWNLOAD_CONTENT AND GIT_EXECUTABLE AND ARG_GIT_REPOSITORY)
|
||||
if(NOT IS_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME})
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${ARG_GIT_REPOSITORY} ${NAME}
|
||||
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR})
|
||||
else()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} fetch
|
||||
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME})
|
||||
endif()
|
||||
if(ARG_GIT_TAG)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} checkout ${ARG_GIT_TAG}
|
||||
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME})
|
||||
else()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} pull
|
||||
WORKING_DIRECTORY ${ARG_DOWNLOAD_DIR}/${NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SCRIPT_MODE_FILE)
|
||||
add_subdirectory(${ARG_DOWNLOAD_DIR}/${NAME} EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
endfunction()
|
||||
|
@ -1,56 +0,0 @@
|
||||
#[=======================================================================[.rst:
|
||||
FetchContent_Add
|
||||
----------------
|
||||
|
||||
Вспомогательная функция для `FetchContent_Declare()`::
|
||||
|
||||
FetchContent_Add(NAME
|
||||
[ GIT_REPOSITORY repo ] |
|
||||
[ GIT_REMOTE remote ] |
|
||||
[ GIT_PATH path ])
|
||||
|
||||
Обязательные параметры: `NAME` - идентификатор загружаемого ресурса.
|
||||
Параметр `GIT_REPOSITORY` определяет имя репозитория по умолчанию.
|
||||
Если указана пара параметров `GIT_REMOTE` и `GIT_PATH` и у git-репозитория
|
||||
основного проекта указан удалённый репозиторий с именем, определяемым
|
||||
переменной `GIT_REMOTE`, то адрес репозитория для получения проекта
|
||||
изменяется. В этом случае загрузка будет производиться с сервера,
|
||||
определяемого из адреса с меткой `GIT_REMOTE`, и по пути `GIT_PATH`.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
# Обязательно в глобальной области
|
||||
find_package(Git)
|
||||
|
||||
function(FetchContent_Add TARGET_NAME)
|
||||
set(options "")
|
||||
set(oneValueArgs GIT_REPOSITORY GIT_REMOTE GIT_PATH)
|
||||
set(multiValueArgs "")
|
||||
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
if(GIT_FOUND AND ARG_GIT_REMOTE AND ARG_GIT_PATH)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} config --get remote.${ARG_GIT_REMOTE}.url OUTPUT_VARIABLE REMOTE_URL ERROR_QUIET)
|
||||
if(REMOTE_URL)
|
||||
string(REGEX REPLACE ":.*" "" SERVER ${REMOTE_URL})
|
||||
string(FIND ${SERVER} "http" POS)
|
||||
if(NOT POS EQUAL 0)
|
||||
if(NOT SERVER STREQUAL REMOTE_URL)
|
||||
set(ARG_GIT_REPOSITORY "${SERVER}:${ARG_GIT_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
FetchContent_Declare(
|
||||
${TARGET_NAME}
|
||||
${ARG_UNPARSED_ARGUMENTS}
|
||||
GIT_REPOSITORY ${ARG_GIT_REPOSITORY}
|
||||
GIT_SHALLOW 1
|
||||
)
|
||||
|
||||
set(FETCHCONTENT_QUIET off)
|
||||
FetchContent_MakeAvailable(${TARGET_NAME})
|
||||
endfunction()
|
@ -1,112 +0,0 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
function(myx_qt5_target_setup 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})
|
||||
|
||||
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 "Qt5::${iter}")
|
||||
endif()
|
||||
if(__target_type STREQUAL "SHARED_LIBRARY")
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC "Qt5::${iter}")
|
||||
endif()
|
||||
if((${CMAKE_VERSION} VERSION_GREATER "3.8.0") AND (__target_type STREQUAL "OBJECT_LIBRARY"))
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC "Qt5::${iter}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(iter ${ARG_PRIVATE})
|
||||
if(__target_type STREQUAL "INTERFACE_LIBRARY")
|
||||
target_include_directories(${TARGET_NAME} INTERFACE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||
else()
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${Qt5${iter}_PRIVATE_INCLUDE_DIRS})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(__target_type STREQUAL "EXECUTABLE")
|
||||
target_compile_options(${TARGET_NAME} PRIVATE ${Qt5Core_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)
|
||||
qt5_wrap_cpp(moc_cpp ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC})
|
||||
endif()
|
||||
|
||||
if(ARG_QRC)
|
||||
qt5_add_resources(qrc_cpp ${ARG_QRC})
|
||||
endif()
|
||||
|
||||
if(ARG_UI AND "Widgets" IN_LIST ARG_COMPONENTS)
|
||||
qt5_wrap_ui(ui_h ${ARG_UI})
|
||||
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}
|
||||
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})
|
||||
# Добавление записи для скомпилированного файла переводов в ресурсный файл
|
||||
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")
|
||||
# Компиляция файла ресурсов с переводами
|
||||
qt5_add_resources(qrc_l10n ${PROJECT_BINARY_DIR}/${TARGET_NAME}_l10n.qrc)
|
||||
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()
|
153
cmake/myx/lib/TargetSetupQt.cmake
Normal file
153
cmake/myx/lib/TargetSetupQt.cmake
Normal 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_ver_qt}_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_ver_qt}_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()
|
@ -2,6 +2,8 @@ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(MYX_CMAKE_LIB_DOC_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
|
||||
endif()
|
||||
|
||||
find_package(Doxygen QUIET)
|
||||
|
||||
function(myx_doc_doxygen TARGET_NAME)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_DOC_DIR_BACKPORT})
|
||||
@ -11,7 +13,6 @@ function(myx_doc_doxygen TARGET_NAME)
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_package(Doxygen)
|
||||
if(DOXYGEN_FOUND)
|
||||
set(DOXYGEN_FOUND ON CACHE STRING "Doxygen documentation generator enabled" FORCE)
|
||||
set(DOXYGEN_EXECUTABLE "${DOXYGEN_EXECUTABLE}" CACHE STRING "Path to Doxygen executable")
|
||||
|
@ -7,7 +7,7 @@ set(GIT_DIFF "")
|
||||
set(GIT_TAG "N/A")
|
||||
set(GIT_BRANCH "N/A")
|
||||
|
||||
find_package(Git)
|
||||
find_package(Git QUIET)
|
||||
|
||||
if(GIT_EXECUTABLE)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} log --pretty=format:'%h' -n 1 OUTPUT_VARIABLE GIT_REV ERROR_QUIET)
|
||||
|
@ -1,36 +1,54 @@
|
||||
#[=======================================================================[.rst:
|
||||
myx_find_packages
|
||||
-----------------
|
||||
|
||||
Вспомогательная функция для поиска зависимостей::
|
||||
|
||||
myx_find_packages()
|
||||
|
||||
Упрощённый способ поиска необходимых и опциональных зависимостей.
|
||||
Для поиска зависимостей с учётом особенных требований (например, номер версии)
|
||||
следует использовать функции `find_package` и `pkg_check_modules`.
|
||||
Параметр `REQUIRED` содержит перечисление необходимых зависимостей
|
||||
для поиска с помощью функции `find_package`.
|
||||
Параметр `OPTIONAL` содержит перечисление опциональных зависимостей
|
||||
для поиска с помощью функции `find_package`.
|
||||
Параметр `PKG_REQUIRED` содержит перечисление необходимых зависимостей
|
||||
для поиска с помощью функции `pkg_check_modules`.
|
||||
Параметр `PKG_OPTIONAL` содержит перечисление опциональных зависимостей
|
||||
для поиска с помощью функции `pkg_check_modules`.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
macro(myx_find_required_packages)
|
||||
macro(myx_find_packages)
|
||||
set(options)
|
||||
set(oneValueArgs)
|
||||
set(multiValueArgs PACKAGES Boost Qt5 Qt5Private Qt6 Qt6Private)
|
||||
set(multiValueArgs REQUIRED OPTIONAL PKG_REQUIRED PKG_OPTIONAL)
|
||||
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
foreach(iter ${ARG_PACKAGES})
|
||||
foreach(iter ${ARG_REQUIRED})
|
||||
find_package(${iter} REQUIRED)
|
||||
endforeach()
|
||||
|
||||
if(ARG_Boost)
|
||||
find_package(Boost COMPONENTS ${ARG_Boost} REQUIRED)
|
||||
endif()
|
||||
foreach(iter ${ARG_OPTIONAL})
|
||||
find_package(${iter})
|
||||
endforeach()
|
||||
|
||||
if(ARG_Qt5)
|
||||
find_package(Qt5 COMPONENTS ${ARG_Qt5} REQUIRED)
|
||||
endif()
|
||||
|
||||
if(ARG_Qt5Private)
|
||||
foreach(iter ${ARG_Qt5Private})
|
||||
find_package("Qt5${iter}" COMPONENTS Private REQUIRED)
|
||||
if(ARG_PKG_REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
foreach(iter ${ARG_PKG_REQUIRED})
|
||||
string(TOUPPER ${iter} iu)
|
||||
pkg_check_modules(${iu} REQUIRED ${iter})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(ARG_Qt6)
|
||||
find_package(Qt6 COMPONENTS ${ARG_Qt6} REQUIRED)
|
||||
endif()
|
||||
|
||||
if(ARG_Qt6Private)
|
||||
foreach(iter ${ARG_Qt6Private})
|
||||
find_package("Qt6${iter}" COMPONENTS Private REQUIRED)
|
||||
if(ARG_PKG_OPTIONAL)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
foreach(iter ${ARG_PKG_OPTIONAL})
|
||||
string(TOUPPER ${iter} iu)
|
||||
pkg_check_modules(${iu} ${iter})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@ -41,4 +59,4 @@ macro(myx_find_required_packages)
|
||||
unset(multiValueArgs)
|
||||
unset(oneValueArgs)
|
||||
unset(options)
|
||||
endmacro(myx_find_required_packages)
|
||||
endmacro(myx_find_packages)
|
||||
|
40
cmake/myx/lib/macro/FindQt.cmake
Normal file
40
cmake/myx/lib/macro/FindQt.cmake
Normal 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()
|
@ -21,7 +21,7 @@ macro(myx_add_qtest TARGET_NAME)
|
||||
endforeach()
|
||||
|
||||
add_executable(${TARGET_NAME} ${mocs} ${cpps} ${hpps})
|
||||
target_link_libraries(${TARGET_NAME} Qt5::Core Qt5::Test)
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE Qt5::Core Qt5::Test)
|
||||
|
||||
add_test(NAME ${TARGET_NAME} COMMAND ${TARGET_NAME})
|
||||
|
||||
|
@ -9,10 +9,6 @@ function(myx_uncrustify TARGET_NAME)
|
||||
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_UNCRUSTIFY_DIR_BACKPORT})
|
||||
endif()
|
||||
|
||||
if(NOT ${PROJECT_BINARY_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(options)
|
||||
set(oneValueArgs CONFIG)
|
||||
set(multiValueArgs)
|
||||
@ -32,6 +28,12 @@ function(myx_uncrustify TARGET_NAME)
|
||||
return()
|
||||
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)
|
||||
add_custom_target(myx-uncrustify)
|
||||
endif()
|
||||
|
@ -20,11 +20,11 @@ if(ENV{MYX_CMAKE_DIR})
|
||||
set(MYX_CMAKE_DIR $ENV{MYX_CMAKE_DIR})
|
||||
endif()
|
||||
if(MYX_CMAKE_DIR)
|
||||
find_package(MyxCMake 2.3.8 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
|
||||
find_package(MyxCMake 2.4.10 REQUIRED CONFIG PATHS ${MYX_CMAKE_DIR} NO_DEFAULT_PATH)
|
||||
myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==")
|
||||
else()
|
||||
if(MYX_CMAKE_USE_SYSTEM)
|
||||
find_package(MyxCMake 2.3.8 REQUIRED)
|
||||
find_package(MyxCMake 2.4.10 REQUIRED)
|
||||
myx_message_notice("== MyxCMake directory: ${MyxCMake_CONFIG} ==")
|
||||
else()
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/myx/MyxCMakeConfig.cmake)
|
||||
|
Loading…
Reference in New Issue
Block a user