CMake question: ki18n_wrap_ui adds .h files as source files to a CMake target, what will happen?
David Hurka
david.hurka at mailbox.org
Tue Nov 3 15:45:49 GMT 2020
Hi CMake fans:
(Skip to the last paragraph for my question.)
KI18N provides the CMake macro “ki18n_wrap_ui()”, which is used like this:
> ki18n_wrap_ui( myApp_SRCS myApp_dialog.ui )
or like this (since KF 5.62):
> ki18n_wrap_ui( myApp myApp_dialog.ui )
In both cases it creates “ui_myApp_dialog.h” using `uic`, which contains a C++
class for this dialog. This header file is added to the list “myApp_SRCS” or
to the target “myApp”.
Internally, it works roughly as follows:
1. Generate the ui_....h filename (in the build/ directory):
> get_filename_component(_basename ${_tmp_FILE} NAME_WE)
> set(_header ${CMAKE_CURRENT_BINARY_DIR}/ui_${_basename}.h)
2. Create this C++ .h file [...]
3. Add this filename as source file to the target / SRCS list:
> if(TARGET ${_sources})
> target_sources(${_sources} PRIVATE ${_header})
> else()
> list(APPEND ${_sources} ${_header})
> endif()
Now I wonder why this *header file* is added as a *source file* to the target.
Other source files will include <ui_myApp_dialog.h>, so it should be enough
when this header file is found somewhere in the include search paths.
Is this how source file lists of a CMake target work? .cpp source files are
compiled to .o files, and .h source files are only used as #include search
path?
Cheers, David
More information about the kde-devel
mailing list