cmake: rework tqt_automoc to process only headers for selected sources

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
feat/cmakeConv-r1
Alexander Golubev 2 months ago
parent f696b7c31f
commit e9c26fe785

@ -302,11 +302,14 @@ endif()
##### set build for modules
if( BUILD_TMOC )
set( TMOC_EXECUTABLE $<TARGET_FILE:tmoc> CACHE FILEPATH "" )
set( MOC_EXECUTABLE $<TARGET_FILE:tmoc> CACHE FILEPATH "" )
set( TMOC_EXECUTABLE $<TARGET_FILE:tmoc> CACHE INTERNAL "" )
set( MOC_EXECUTABLE $<TARGET_FILE:tmoc> CACHE INTERNAL "" )
else()
find_program( TMOC_EXECUTABLE NAMES tmoc tqmoc REQUIRED )
endif()
if( BUILD_TOOLS )
set( UIC_EXECUTABLE $<TARGET_FILE:tquic> CACHE FILEPATH "" )
set( UIC_EXECUTABLE $<TARGET_FILE:tquic> CACHE INTERNAL "" )
endif()
if( WITH_MODULE_STYLES )

@ -104,6 +104,48 @@ macro( tqt_install_includes )
endmacro( tqt_install_includes )
#################################################
#####
##### tqt_header_for_source
#####
##### The macro search appropriate header files for the given list of sources and
##### append them to the list specified by _include_out
#####
##### Syntax:
##### tqt_header_for_source ( header_list source [source ...] )
macro( tqt_header_for_source _include_out )
foreach( _src ${ARGN} )
# As for now tqt has an "nt" prefix before filenames, so in order to handle all the casses
# we will have to do some pattern matching
get_filename_component( _src_path "${_src}" ABSOLUTE )
get_filename_component( _src_path "${_src_path}" PATH )
get_filename_component( _src_filename "${_src}" NAME_WE )
file( GLOB _header_candidates RELATIVE "${_src_path}/" "${_src_path}/*${_src_filename}*.h*" )
# filter out headers without TQ_OBJECT
unset( _filtered_header_candidates )
foreach( _header IN LISTS _header_candidates )
if( NOT _header MATCHES "^(n?t)?${_src_filename}(_p)?\\.(h|hpp)$" )
continue()
endif()
file( STRINGS "${_src_path}/${_header}" _has_tq_object REGEX "T?Q_OBJECT" )
if( _has_tq_object )
list( APPEND _filtered_header_candidates "${_header}" )
endif( _has_tq_object )
endforeach( )
set( _header_candidates "${_filtered_header_candidates}" )
list( LENGTH _header_candidates _header_candidates_num )
if( ${_header_candidates_num} EQUAL 1 )
list( APPEND "${_include_out}" "${_src_path}/${_header_candidates}" )
elseif( "${_header_candidates_num}" GREATER 1 )
tde_message_fatal( "More than one candidates to automoc for ${_src_file}:"
" ${_header_candidates}" )
else( )
# do nothing, skip the file
endif( )
endforeach( _src )
endmacro( tqt_header_for_source )
#################################################
#####
@ -113,15 +155,15 @@ endmacro( tqt_install_includes )
##### and adding them to an existing target.
#####
##### Syntax:
##### tqt_moc(
##### tqt_automoc(
##### [TARGET] target
##### [INCLUDES include_name [include_name]]
##### [INCLUDES (AUTO|include_name) [include_name ...]]
##### )
macro( tqt_automoc )
unset( _target )
set( _includes AUTO )
unset( _includes )
unset( _auto_includes )
set( _var _target )
foreach( _arg ${ARGN} )
@ -149,118 +191,77 @@ macro( tqt_automoc )
endforeach( )
# handle AUTO includes
if( NOT _includes )
set( _auto_includes 1 )
elseif( AUTO IN_LIST _includes )
set( _auto_includes 1 )
list( REMOVE_ITEM _includes AUTO )
endif()
# target must already exist
if( NOT TARGET ${_target} )
tde_message_fatal( "The specified target does not exists." )
endif()
# search include files suitable for processing
if( _includes STREQUAL "AUTO" )
file( GLOB _includes RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/*.h )
foreach( _include IN LISTS _includes )
file( READ "${CMAKE_CURRENT_SOURCE_DIR}/${_include}" _src_content )
string( REGEX REPLACE "(^|\n)[\t ]*#[^\n]*" "" _src_content "${_src_content}" )
string( REGEX REPLACE "(//|/\\*)[^\n]*T?Q_OBJECT[^\n]*" "" _src_content "${_src_content}" )
if( NOT _src_content MATCHES "[\n\t ]+T?Q_OBJECT[\n\t ]+" )
list( REMOVE_ITEM _includes "${_include}" )
endif()
endforeach()
elseif( _includes STREQUAL "-" )
set( _includes "" )
endif()
# check tmoc executable
if( NOT DEFINED TMOC_EXECUTABLE )
find_program( TMOC_EXECUTABLE
NAMES tmoc
HINT ${QT_INSTALL_BINS}
)
if( "${TMOC_EXECUTABLE}" STREQUAL "TMOC_EXECUTABLE-NOTFOUND" )
tde_message_fatal( "tmoc is required but not found" )
endif( )
if( NOT TMOC_EXECUTABLE )
tde_message_fatal( "tmoc is required but not found" )
endif()
# processing sources of specified target
get_property( _sources TARGET ${_target} PROPERTY SOURCES )
foreach( _src_file IN LISTS _sources )
# get list of sources of specified target
get_target_property( _sources "${_target}" SOURCES )
# automoc source files
foreach( _src_file IN LISTS _sources )
get_filename_component( _src_file "${_src_file}" ABSOLUTE )
if( EXISTS "${_src_file}" )
# get some essential variables
get_filename_component( _src_path "${_src_file}" ABSOLUTE )
get_filename_component( _src_path "${_src_path}" PATH )
get_filename_component( _src_filename "${_src_file}" NAME_WE )
file( RELATIVE_PATH _src_path_relative "${CMAKE_SOURCE_DIR}" "${_src_path}" )
# read source file and check if have moc include
file( READ "${_src_file}" _src_content )
string( REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _moc_includes "${_src_content}" )
# read source file and check if it has a moc include
file( STRINGS "${_src_file}" _moc_includes REGEX
"^#[ \t]*include[ \t]*[\"<]${_src_filename}\\.moc[\">]" )
# found included moc(s)?
if( _moc_includes )
foreach( _moc_file ${_moc_includes} )
# extracting moc filename
string( REGEX MATCH "[^ <\"]+\\.moc" _moc_file "${_moc_file}" )
set( _moc_file "${CMAKE_CURRENT_BINARY_DIR}/${_moc_file}" )
# create source filename
get_filename_component( _src_path "${_src_file}" ABSOLUTE )
get_filename_component( _src_path "${_src_path}" PATH )
get_filename_component( _src_header "${_moc_file}" NAME_WE )
if( NOT TQT_FOUND )
set( _moc_source "${_src_path}/${_src_header}.cpp" )
else()
set( _moc_source "${_src_path}/${_src_header}.h" )
endif()
# if header doesn't exists, check in META_INCLUDES
if( NOT EXISTS "${_moc_source}" )
unset( _found )
foreach( _src_path ${_meta_includes} )
set( _moc_source "${_src_path}/${_src_header}.h" )
if( EXISTS "${_moc_source}" )
set( _found 1 )
break( )
endif( )
endforeach( )
if( NOT _found )
get_filename_component( _moc_file "${_moc_file}" NAME )
tde_message_fatal( "AUTOMOC error: '${_moc_file}' cannot be generated.\n Reason: '${_src_file}.h' not found." )
endif( )
endif( )
# moc-ing source
add_custom_command( OUTPUT ${_moc_file}
COMMAND ${TMOC_EXECUTABLE} ${_moc_source} -o ${_moc_file}
DEPENDS ${_moc_source}
)
# create dependency between source file and moc file
set_property( SOURCE ${_src_file} APPEND PROPERTY OBJECT_DEPENDS ${_moc_file} )
# remove from includes for processing
file( RELATIVE_PATH _moc_source ${CMAKE_CURRENT_SOURCE_DIR} ${_moc_source} )
list( REMOVE_ITEM _includes "${_moc_source}" )
endforeach( _moc_file )
endif( _moc_includes )
endif( EXISTS "${_src_file}" )
if( _moc_includes ) # file has a moc include; we should moc src file itself
set( _moc_file_relative "${_src_path_relative}/${_src_filename}.moc" )
set( _moc_file "${CMAKE_BINARY_DIR}/${_moc_file_relative}" )
add_custom_command( OUTPUT "${_moc_file}"
COMMAND "${TMOC_EXECUTABLE}" "${_src_file}" -o "${_moc_file}"
COMMENT "Generating ${_moc_file_relative}"
DEPENDS "${_src_file}" )
set_property( SOURCE "${_src_file}" APPEND PROPERTY OBJECT_DEPENDS "${_moc_file}" )
endif( )
endif( )
endforeach( _src_file )
# Get list of headers associated with sources
if( _auto_includes )
tqt_header_for_source( _includes ${_sources} )
endif( )
# processing headers
foreach( _include_file IN LISTS _includes )
get_filename_component( _include_name "${_include_file}" NAME_WE )
set( _moc_file ${CMAKE_CURRENT_BINARY_DIR}/moc_${_include_name}.cpp )
foreach( _inc IN LISTS _includes )
get_filename_component( _inc "${_inc}" ABSOLUTE )
get_filename_component( _inc_name "${_inc}" NAME_WE )
file( RELATIVE_PATH _inc_path_relative "${CMAKE_SOURCE_DIR}" "${_inc}" )
get_filename_component( _inc_path_relative "${_inc_path}" PATH )
set( _moc_file_relative "${_inc_path_relative}/moc_${_inc_name}.cpp" )
set( _moc_file "${CMAKE_CURRENT_BINARY_DIR}/${_moc_file_relative}" )
# moc-ing source
add_custom_command( OUTPUT ${_moc_file}
COMMAND ${TMOC_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${_include_file} -o ${_moc_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_include_file}
COMMAND "${TMOC_EXECUTABLE}" "${_inc}" -o "${_moc_file}"
COMMENT "Generating ${_moc_file_relative}"
DEPENDS "${_inc}"
)
set_property( TARGET ${_target} APPEND PROPERTY SOURCES ${_moc_file} )
endforeach( _include_file )
endforeach( _inc )
endmacro( tqt_automoc )

@ -34,7 +34,7 @@ if( BUILD_LIB )
# subdirectories
set( tqtlib_embed "" )
unset( tqtlib_embed )
add_subdirectory( tools )
add_subdirectory( kernel )

@ -143,6 +143,10 @@ if( WITH_XFT )
list( APPEND _SRC_ ../3rdparty/opentype/ftxopentype.c )
endif()
set( _EXTRA_HEADERS_
ntqdesktopwidget.h
ntqsessionmanager.h
)
tde_add_library( ${target} STATIC_PIC
@ -171,7 +175,8 @@ tde_add_library( ${target} STATIC_PIC
tqt-includes
)
tqt_automoc( ${target}-static )
tqt_automoc( ${target}-static
INCLUDES ${_EXTRA_HEADERS_} AUTO )
list( APPEND tqtlib_embed ${target}-static )
set( tqtlib_embed ${tqtlib_embed} PARENT_SCOPE )

Loading…
Cancel
Save