70 lines
1.9 KiB
CMake
70 lines
1.9 KiB
CMake
include_guard(GLOBAL)
|
|
|
|
function(myx_qt5_target_setup NAME)
|
|
set(options)
|
|
set(oneValueArgs)
|
|
set(multiValueArgs COMPONENTS PRIVATE CPP HPP MOC UI QRC LANGS SOURCES)
|
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
get_target_property(type ${NAME} TYPE)
|
|
|
|
if(ARG_SOURCES)
|
|
myx_message_deprecation("MyxCMake: Use CPP and HPP arguments instead of SOURCES")
|
|
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_CPP)
|
|
set_target_properties(${NAME} PROPERTIES CPP_FILES ${ARG_CPP})
|
|
endif()
|
|
|
|
if(ARG_HPP OR ARG_MOC)
|
|
set_target_properties(${NAME} PROPERTIES HPP_FILES ${ARG_HPP} ${ARG_MOC})
|
|
endif()
|
|
|
|
if(ARG_MOC)
|
|
qt5_wrap_cpp(moc_cpp ${ARG_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_HPP} ${ARG_CPP} ${ARG_SOURCES} ${ARG_MOC} ${moc_cpp} ${ui_h} ${qrc_cpp})
|
|
|
|
endfunction()
|