17 апреля 2010

CMake+Qt assistant

In this post I write how install/register *.qch files of your project in assitant.In your CMakeLists.txt create 2 variables, which contains qch directory and file names.

set(QCH_DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/doc/qch)
set(QCH_DOC_NAMES myproject.qch)


Create loop for register files.

# remove old regestered doc file
install(CODE "file(REMOVE \"registered_doc.txt\")")

foreach(QCH_DOC_NAME ${QCH_DOC_NAMES})
# INSTALLATION INSTRUCTIONS
# install qch file
install(FILES ${QCH_DOC_DIR}/${QCH_DOC_NAME} DESTINATION ${QT_DOC_DIR}/qch COMPONENT Doc)

# package qch documentation
# if assistant exists
set(QUIET_ASSISTANT )#-quiet)

# find qt assistant
find_program(QT_ASSISTANT_EXECUTABLE
NAMES assistant assistant_adp
PATHS ${QT_BINARY_DIR}
NO_DEFAULT_PATH)

if(QT_ASSISTANT_EXECUTABLE)
if(WIN32)
# MINI HACK because assitant call messagebox
set(QUIET_ASSISTANT -quiet)
endif(WIN32)

# execute assistan -register filename
install(CODE "execute_process(COMMAND ${QT_ASSISTANT_EXECUTABLE} -register ${QUIET_ASSISTANT} ${QT_DOC_DIR}/qch/${QCH_DOC_NAME})")
# print message on console
install(CODE "message(\"Registering doc ${QT_DOC_DIR}/qch/${QCH_DOC_NAME}\")")

# add registered help file path into file
install(CODE "file(APPEND \"registered_doc.txt\" \"${QT_DOC_DIR}/qch/${QCH_DOC_NAME}\")")
endif(QT_ASSISTANT_EXECUTABLE)
endforeach(QCH_DOC_NAME)


Create file cmake_unregister_doc.cmake.in with following code:

# open file with list of registered doc assistant (*.qch) files
IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/registered_doc.txt")
MESSAGE("Cannot find registered doc: \"@CMAKE_CURRENT_BINARY_DIR@/registered_doc.txt\"")
ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/registered_doc.txt")

FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/registered_doc.txt" files)
STRING(REGEX REPLACE "\n" ";" files "${files}")
FOREACH(file ${files})
MESSAGE(STATUS "Unregistering \"$ENV{DESTDIR}${file}\"")
# IF(EXISTS "$ENV{DESTDIR}${file}")
execute_process(COMMAND @QT_BINARY_DIR@/assistant -unregister @QUIET_ASSISTANT@ "$ENV{DESTDIR}${file}"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval)
IF(NOT "${rm_retval}" STREQUAL 0)
MESSAGE("Problem when unregistering \"$ENV{DESTDIR}${file}\"")
ENDIF(NOT "${rm_retval}" STREQUAL 0)
# ELSE(EXISTS "$ENV{DESTDIR}${file}")
# MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
# ENDIF(EXISTS "$ENV{DESTDIR}${file}")
ENDFOREACH(file)


In your CMakeLists.txt configure cmake script file:

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_unregister_doc.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_unregister_doc.cmake"
IMMEDIATE @ONLY)


Create uninstall target:
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_unregister_doc.cmake")

Комментариев нет:

Отправить комментарий