Skip to content
Snippets Groups Projects
Commit d7954bc8 authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Add armarx_gui_plugin macro to make gui plugin code cleaner

parent c24ef58b
No related branches found
No related tags found
No related merge requests found
......@@ -42,12 +42,13 @@ function(armarx_gui_library PLUGIN_NAME SOURCES QT_MOC_HDRS QT_UIS QT_RESOURCES
list(APPEND HEADERS ${QT_MOC_HDRS})
list(APPEND HEADERS ${QT_UIS})
set(GENERATE_BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_NAME}_autogen/include")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_NAME}_autogen/include/" DESTINATION "include" COMPONENT headers)
install(DIRECTORY "${GENERATE_BASE_DIR}" DESTINATION "include" COMPONENT headers)
printtarget("${HEADERS}" "${SOURCES}" "${QT_RESOURCES}" "${COMPONENT_LIBS}")
armarx_add_library("${PLUGIN_NAME}" "${SOURCES}" "${HEADERS}" "${COMPONENT_LIBS}")
target_include_directories("${PLUGIN_NAME}" PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_NAME}_autogen/include> )
target_include_directories("${PLUGIN_NAME}" PUBLIC $<BUILD_INTERFACE:${GENERATE_BASE_DIR}> )
target_compile_definitions("${PLUGIN_NAME}" PUBLIC -DQ_COMPILER_INITIALIZER_LISTS)
set_target_properties("${PLUGIN_NAME}" PROPERTIES AUTOMOC ON)
......@@ -73,3 +74,59 @@ function(armarx_gui_library PLUGIN_NAME SOURCES QT_MOC_HDRS QT_UIS QT_RESOURCES
printlist(" " "${INCLUDE_DIRECTORIES}")
endif()
endfunction()
function(armarx_gui_plugin PLUGIN_NAME SOURCES QT_MOC_HDRS QT_UIS QT_RESOURCES COMPONENT_LIBS)
list(APPEND SOURCES ${QT_RESOURCES})
list(APPEND HEADERS ${QT_MOC_HDRS})
list(APPEND HEADERS ${QT_UIS})
set(GENERATE_BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_NAME}_autogen/include")
#gui plugin name
string(REPLACE "GuiPlugin" "" ARMARX_GUI_PLUGIN_PREFIX "${ARMARX_TARGET_NAME}")
#autogen header if none was supplied
set(tmp_headers ${HEADERS})
set(tmp_regex "(^|\\.*/)${ARMARX_GUI_PLUGIN_PREFIX}GuiPlugin\\.h")
list(FILTER tmp_headers INCLUDE REGEX "${tmp_regex}")
list(REMOVE_DUPLICATES tmp_headers)
list(LENGTH tmp_headers tmp_headers_len)
if("0" STREQUAL "${tmp_headers_len}")
########################################################################
#get rel path for subdir
file(RELATIVE_PATH subdir "${PROJECT_SOURCECODE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
########################################################################
#get the widget controller header
set(tmp_headers ${HEADERS})
set(tmp_regex "(^|\\.*/)${ARMARX_GUI_PLUGIN_PREFIX}WidgetController\\.h")
list(FILTER tmp_headers INCLUDE REGEX "${tmp_regex}")
list(REMOVE_DUPLICATES tmp_headers)
list(LENGTH tmp_headers tmp_headers_len)
if(NOT "1" STREQUAL "${tmp_headers_len}")
message(FATAL_ERROR "Failed to auto generate the GuiPlugin headers! Error: Can't find the widget controller")
endif()
list(POP_BACK tmp_headers tmp_hdr)
set(ARMARX_GUI_PLUGIN_WIDGET_CONTROLLER_HEDER "${subdir}/${tmp_hdr}")
########################################################################
#generate and add files
set(outfile "${GENERATE_BASE_DIR}/${subdir}/${ARMARX_TARGET_NAME}")
foreach(suff h cpp)
configure_file(
"${ArmarXCore_TEMPLATES_DIR}/GuiPluginTemplate/GuiPlugin.tmp.${suff}"
"${outfile}.${suff}"
@ONLY
)
endforeach()
list(APPEND SOURCES "${outfile}.cpp")
list(APPEND HEADERS "${outfile}.h")
endif()
armarx_gui_library(
"${PLUGIN_NAME}"
"${SOURCES}"
"${HEADERS}"
""
"${QT_RESOURCES}"
"${COMPONENT_LIBS}")
endfunction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment