[CMake] control order of custom target as a sub-part of a customized KDE build

Michael Hertling mhertling at online.de
Fri Jan 7 06:26:16 EST 2011


On 01/04/2011 09:16 PM, Shawn Rutledge wrote:
> I am building a KDE control panel plugin, and there is a requirement
> to use a different translation mechanism rather than the default Qt
> "tr" macros.  So I want to post-process my ui_*.h files to replace
> lines like this
> 
>         ClearSiteDataDialog->setWindowTitle(tr2i18n("foo", 0));
> 
>  with the replacement code like this
> 
>         ClearSiteDataDialog->setWindowTitle(Translator::instance().lookupString(CSD_DIALOG_TITLE));
> 
> I wrote a python script to do that, and I'm calling it like this from
> cmakelists.txt:
> 
> cmake_minimum_required (VERSION 2.6.0)
> set (CMAKE_VERBOSE_MAKEFILE true)
> find_package(KDE4 REQUIRED)
> file(GLOB SRC_FILES *.cpp)
> set(kcm_my_plugin_PART_SRCS ${SRC_FILES})
> message(STATUS "build type ${CMAKE_BUILD_TYPE}")
> file(GLOB UI_FILES *.ui)
> message(STATUS "ui files ${UI_FILES}")
> kde4_add_ui_files(kcm_my_plugin_PART_SRCS ${UI_FILES})
> kde4_add_plugin(kcm_my_plugin ${kcm_my_plugin_PART_SRCS}
> ${LINUX_COMMON_SOURCE} ${COMMON_SOURCE} ${COMMON_SOURCE_IMPL})
> target_link_libraries(kcm_my_plugin  ${KDE4_KDEUI_LIBS}
> ${KDE4_KCMUTILS_LIBS} ${X11_LIBRARIES} kutils)
> # post-process the ui_*.h header files AFTER they have been generated
> but BEFORE compiling anything
> add_custom_target(ui_translate
> 	COMMAND ${CMAKE_SOURCE_DIR}/tools/convert-tr2-all.py
> 	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
> ADD_DEPENDENCIES(kcm_my_plugin ui_translate)
> ADD_DEPENDENCIES(kcm_my_plugin_automoc ui_translate)
> 
> 
> The only trouble is, it tries to call the script at the beginning of
> the build process, so the first time I run "make" it fails, and the
> second time after the ui_*.h files have been generated it succeeds.
> So, I need to control the order somehow, and I haven't dug deep enough
> into the KDE4 package to understand how the existing steps are done in
> the right order.  I need to append my extra step after the point where
> it generates the ui header files from the UI files.  I'm looking for
> ideas on what the dependency should be - which target do I depend on
> to get it done at the right time?

AFAICS, you need a dependency of ui_translate on the ui_*.h files:

add_custom_target(ui_translate
	COMMAND ${CMAKE_SOURCE_DIR}/tools/convert-tr2-all.py
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        DEPENDS ${kcm_my_plugin_PART_SRCS})
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note that this only works within the same directory, i.e.
kde4_add_ui_files() and add_custom_target() must be
mentioned in the same CMakeLists.txt.

Regards,

Michael


More information about the CMake mailing list