54 lines
1.4 KiB
CMake
54 lines
1.4 KiB
CMake
include_guard(GLOBAL)
|
|
|
|
function(myx_qt5_target_setup NAME)
|
|
set(options)
|
|
set(oneValueArgs)
|
|
set(multiValueArgs COMPONENTS PRIVATE SOURCES MOC UI QRC LANGS)
|
|
|
|
cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
get_target_property(type ${NAME} TYPE)
|
|
|
|
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")
|
|
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()
|
|
|
|
qt5_wrap_cpp(moc_cpp ${ARG_MOC})
|
|
qt5_add_resources(qrc_cpp ${ARG_QRC})
|
|
if("Widgets" IN_LIST ARG_COMPONENTS)
|
|
qt5_wrap_ui(ui_h ${ARG_UI})
|
|
endif()
|
|
|
|
if("LinguistTools" IN_LIST ARG_COMPONENTS)
|
|
set(ts)
|
|
foreach(iter ${ARG_LANGS})
|
|
list(APPEND ts ${PROJECT_SOURCE_DIR}/l10n/${NAME}_${iter}.ts)
|
|
endforeach()
|
|
|
|
qt5_create_translation(qm
|
|
${PROJECT_SOURCE_DIR}/include
|
|
${PROJECT_SOURCE_DIR}/src
|
|
${ts}
|
|
)
|
|
endif()
|
|
|
|
target_sources(${NAME} PRIVATE ${ARG_SOURCES} ${ARG_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp} ${qm})
|
|
|
|
endfunction()
|