78 lines
2.2 KiB
CMake
78 lines
2.2 KiB
CMake
include_guard(GLOBAL)
|
|
|
|
function(myx_qt5_target_setup 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(type ${NAME} TYPE)
|
|
|
|
if(ARG_SOURCES OR ARG_CPP OR ARG_HPP OR ARG_MOD)
|
|
myx_message_fatal_error("MyxCMake: prohibited use")
|
|
endif()
|
|
|
|
if(ARG_COMPONENTS)
|
|
find_package(Qt5 COMPONENTS ${ARG_COMPONENTS} REQUIRED)
|
|
foreach(iter ${ARG_COMPONENTS})
|
|
target_include_directories(${NAME} PRIVATE ${Qt5${iter}_INCLUDE_DIRS})
|
|
if(type STREQUAL "EXECUTABLE" AND NOT iter STREQUAL "LinguistTools")
|
|
target_link_libraries(${NAME} PRIVATE "Qt5::${iter}")
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
|
|
if(ARG_PRIVATE)
|
|
foreach(iter ${ARG_PRIVATE})
|
|
find_package("Qt5${iter}" COMPONENTS Private REQUIRED)
|
|
endforeach()
|
|
endif()
|
|
|
|
if(type STREQUAL "EXECUTABLE")
|
|
target_compile_options(${NAME} PRIVATE ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
|
|
endif()
|
|
|
|
if(ARG_PUBLIC_MOC)
|
|
set_property(TARGET ${NAME} APPEND PROPERTY PUBLIC_HEADER_FILES "${ARG_PUBLIC_MOC}")
|
|
endif()
|
|
|
|
if(ARG_PRIVATE_MOC)
|
|
set_property(TARGET ${NAME} APPEND PROPERTY PRIVATE_HEADER_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})
|
|
endif()
|
|
|
|
if("LinguistTools" IN_LIST ARG_COMPONENTS)
|
|
foreach(iter ${ARG_LANGS})
|
|
qt5_create_translation(qm
|
|
"${PROJECT_SOURCE_DIR}/include"
|
|
"${PROJECT_SOURCE_DIR}/src"
|
|
"${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts")
|
|
target_sources(${NAME} PRIVATE ${qm})
|
|
endforeach()
|
|
unset(qm)
|
|
endif()
|
|
|
|
target_sources(${NAME} PRIVATE ${ARG_PUBLIC_MOC} ${ARG_PRIVATE_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
|
|
|
# Установка публичных заголовочных файлов
|
|
if(PROJECT_IS_TOP_LEVEL)
|
|
install_relative(${PROJECT_SOURCE_DIR}
|
|
FILES ${ARG_PUBLIC_MOC}
|
|
DESTINATION ${CMAKE_INSTALL_PREFIX}
|
|
COMPONENT dev
|
|
)
|
|
endif()
|
|
endfunction()
|