diff options
author | Matthias Kretz <kretz@kde.org> | 2007-07-04 11:03:11 +0000 |
---|---|---|
committer | Matthias Kretz <kretz@kde.org> | 2007-07-04 11:03:11 +0000 |
commit | 9dcedc87a745df564bee5ffddeba7071dc6bc884 (patch) | |
tree | ae95f17969a8dc5323485669196de49d7a2a50bb /modules/kde4automoc.cmake | |
parent | 588e081f8919c561170793d20b048db7f286dd7d (diff) | |
download | extra-cmake-modules-9dcedc87a745df564bee5ffddeba7071dc6bc884.tar.gz extra-cmake-modules-9dcedc87a745df564bee5ffddeba7071dc6bc884.tar.bz2 |
- make automoc implicit (no kde4_automoc needed in CMakeLists.txt anymore, the macro now expands to nothing)
- delay the automoc to make time
- add KDE4_MOC_HEADERS macro that you can use to create moc_foo.cpp files that get compiled into the target, without you having to include the moc file in the .cpp file
- automoc finds Q_OBJECT macros in .cpp files creates the .moc file from the .cpp file then
- automoc allows both .moc and moc_foo.cpp style includes for qmake compatibility
svn path=/trunk/KDE/kdelibs/; revision=683192
Diffstat (limited to 'modules/kde4automoc.cmake')
-rw-r--r-- | modules/kde4automoc.cmake | 145 |
1 files changed, 76 insertions, 69 deletions
diff --git a/modules/kde4automoc.cmake b/modules/kde4automoc.cmake index 0b37f54d..35da4496 100644 --- a/modules/kde4automoc.cmake +++ b/modules/kde4automoc.cmake @@ -1,76 +1,83 @@ # do the automoc handling # Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org> +# Copyright (c) 2007, Matthias Kretz, <kretz@kde.org> # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. -include(${KDE4_AUTOMOC_FILE}) - -macro(PARSE_ONE_FILE _filename _moc_mark_FILE) - if ("${_filename}" IS_NEWER_THAN "${_moc_mark_FILE}") - file(WRITE "${_moc_mark_FILE}" "#file is autogenerated, do not edit\n") - - file(READ "${_filename}" _contents) - - get_filename_component(_abs_PATH "${_filename}" PATH) - message(STATUS "Automoc: Parsing ${_filename}") - - set(_mocs_PER_FILE) - - string(REGEX MATCHALL "#include +([\"<]moc_[^ ]+\\.cpp|[^ ]+\\.moc)[\">]" _match "${_contents}") - if (_match) - foreach (_current_MOC_INC ${_match}) - string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") - if(_current_MOC) - get_filename_component(_basename ${_current_MOC} NAME_WE) - else(_current_MOC) - string(REGEX MATCH "moc_[^ <\"]+\\.cpp" _current_MOC "${_current_MOC_INC}") - get_filename_component(_basename ${_current_MOC} NAME_WE) - string(REPLACE "moc_" "" _basename "${_basename}") - endif(_current_MOC) - - set(_header ${_abs_PATH}/${_basename}.h) - set(_moc ${KDE4_CURRENT_BINARY_DIR}/${_current_MOC}) - - if (NOT EXISTS ${_header}) - message(FATAL_ERROR "In the file \"${_filename}\" the moc file \"${_current_MOC}\" is included, but \"${_header}\" doesn't exist.") - endif (NOT EXISTS ${_header}) - - list(APPEND _mocs_PER_FILE ${_basename}) - file(APPEND ${_moc_mark_FILE} "set( ${_basename}_MOC ${_moc})\n") - file(APPEND ${_moc_mark_FILE} "set( ${_basename}_HEADER ${_header})\n") - endforeach (_current_MOC_INC) - endif (_match) - file(APPEND ${_moc_mark_FILE} "set(mocs ${_mocs_PER_FILE})\n") - endif ("${_filename}" IS_NEWER_THAN "${_moc_mark_FILE}") - -endmacro(PARSE_ONE_FILE) - -foreach( _current_FILE ${MOC_FILES}) -# message(STATUS "Automoc: Checking ${_current_FILE}...") - - get_filename_component(_basename ${_current_FILE} NAME) - set(_moc_mark_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}_automoc.mark) - - if(EXISTS ${_moc_mark_FILE}) - set(_force_MOC FALSE) - else(EXISTS ${_moc_mark_FILE}) - set(_force_MOC TRUE) - endif(EXISTS ${_moc_mark_FILE}) - - parse_one_file(${_current_FILE} ${_moc_mark_FILE}) - - include(${_moc_mark_FILE}) - - foreach(_current_MOC ${mocs}) - if ("${${_current_MOC}_HEADER}" IS_NEWER_THAN "${${_current_MOC}_MOC}" OR _force_MOC) - message(STATUS "Automoc: Generating ${${_current_MOC}_MOC} from ${${_current_MOC}_HEADER}") - execute_process(COMMAND ${QT_MOC_EXECUTABLE} ${QT_MOC_INCS} ${${_current_MOC}_HEADER} -o ${${_current_MOC}_MOC}) - - endif ("${${_current_MOC}_HEADER}" IS_NEWER_THAN "${${_current_MOC}_MOC}" OR _force_MOC) - endforeach(_current_MOC) - - -endforeach( _current_FILE) - +macro (generate_moc _moc_source _current_MOC) + set(_moc ${KDE4_CURRENT_BINARY_DIR}/${_current_MOC}) + + if ("${_moc_source}" IS_NEWER_THAN "${_moc}" OR _force_moc) + message(STATUS "Automoc: Generating ${_moc} from ${_moc_source}") + execute_process(COMMAND ${QT_MOC_EXECUTABLE} ${QT_MOC_INCS} "${_moc_source}" -o "${_moc}") + endif ("${_moc_source}" IS_NEWER_THAN "${_moc}" OR _force_moc) +endmacro (generate_moc) + +STRING(REPLACE "\\ " " " MARK_FILE "${MARK_FILE}") +STRING(REPLACE "\\ " " " MOC_FILES "${MOC_FILES}") +STRING(REPLACE "\\ " " " QT_MOC_INCS "${QT_MOC_INCS}") +if (EXISTS "${MARK_FILE}") + set(_force_moc FALSE) +else (EXISTS "${MARK_FILE}") + set(_force_moc TRUE) +endif (EXISTS "${MARK_FILE}") +foreach(_filename ${MOC_FILES}) + get_filename_component(_name "${_filename}" NAME) + + get_filename_component(_abs_PATH "${_filename}" PATH) + get_filename_component(_basename "${_filename}" NAME_WE) + set(_moc_source ${_abs_PATH}/${_basename}.h) + if ("${_filename}" IS_NEWER_THAN "${MARK_FILE}" OR "${_moc_source}" IS_NEWER_THAN "${MARK_FILE}") + get_filename_component(_suffix "${_filename}" EXT) + if (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}") + #message(STATUS "Automoc: Looking for outdated moc includes in ${_filename}") + + # read the whole file + file(READ ${_filename} _contents) + + string(REGEX MATCHALL "#include +([\"<]moc_[^ ]+\\.cpp|[^ ]+\\.moc)[\">]" _match "${_contents}") + if (_match) + foreach (_current_MOC_INC ${_match}) + string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") + if(_current_MOC) + get_filename_component(_basename ${_current_MOC} NAME_WE) + + # if the .cpp file contains the Q_OBJECT macro we create the .moc file from the .cpp file + if (_contents MATCHES "[\n\r][\t ]*Q_OBJECT") + set(_moc_source ${_filename}) + else (_contents MATCHES "[\n\r][\t ]*Q_OBJECT") + set(_moc_source ${_abs_PATH}/${_basename}.h) + endif (_contents MATCHES "[\n\r][\t ]*Q_OBJECT") + else(_current_MOC) + string(REGEX MATCH "moc_[^ <\"]+\\.cpp" _current_MOC "${_current_MOC_INC}") + get_filename_component(_basename ${_current_MOC} NAME_WE) + string(REPLACE "moc_" "" _basename "${_basename}") + + # always create moc_foo.cpp from the .h + set(_moc_source ${_abs_PATH}/${_basename}.h) + endif(_current_MOC) + + if (NOT EXISTS ${_moc_source}) + message(FATAL_ERROR "In the file \"${_filename}\" the moc file \"${_current_MOC}\" is included, but \"${_moc_source}\" doesn't exist.") + endif (NOT EXISTS ${_moc_source}) + + generate_moc(${_moc_source} ${_current_MOC}) + endforeach (_current_MOC_INC) + endif (_match) + else (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}") + if (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}") + get_filename_component(_basename ${_filename} NAME_WE) + set(_current_MOC "moc_${_basename}.cpp") + generate_moc(${_filename} ${_current_MOC}) + else (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}") + message(STATUS "Automoc: ignoring file '${_filename}' with unknown suffix '${_suffix}'") + endif (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}") + endif (".cpp" STREQUAL "${_suffix}" OR ".cc" STREQUAL "${_suffix}" OR ".cxx" STREQUAL "${_suffix}" OR ".C" STREQUAL "${_suffix}") + endif ("${_filename}" IS_NEWER_THAN "${MARK_FILE}" OR "${_moc_source}" IS_NEWER_THAN "${MARK_FILE}") +endforeach(_filename) + +# touch .mark file +#message(STATUS "touch ${MARK_FILE}") +file(WRITE "${MARK_FILE}" "") |