Automoc4Config.cmake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. get_filename_component(_AUTOMOC4_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
  2. # set the automoc version number
  3. include(${_AUTOMOC4_CURRENT_DIR}/Automoc4Version.cmake)
  4. # are we in the source tree or already installed ?
  5. if(EXISTS ${_AUTOMOC4_CURRENT_DIR}/kde4automoc.cpp)
  6. get_target_property(AUTOMOC4_EXECUTABLE automoc4 LOCATION)
  7. # this dependency is required to make parallel builds of kdesupport work:
  8. set(_AUTOMOC4_EXECUTABLE_DEP automoc4)
  9. else(EXISTS ${_AUTOMOC4_CURRENT_DIR}/kde4automoc.cpp)
  10. get_filename_component(_AUTOMOC4_BIN_DIR "${_AUTOMOC4_CURRENT_DIR}" PATH)
  11. get_filename_component(_AUTOMOC4_BIN_DIR "${_AUTOMOC4_BIN_DIR}" PATH)
  12. find_program(AUTOMOC4_EXECUTABLE automoc4 PATHS "${_AUTOMOC4_BIN_DIR}/bin" NO_DEFAULT_PATH)
  13. set(_AUTOMOC4_EXECUTABLE_DEP)
  14. endif(EXISTS ${_AUTOMOC4_CURRENT_DIR}/kde4automoc.cpp)
  15. macro (AUTOMOC4_MOC_HEADERS _target_NAME)
  16. set (_headers_to_moc)
  17. foreach (_current_FILE ${ARGN})
  18. get_filename_component(_suffix "${_current_FILE}" EXT)
  19. if (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
  20. list(APPEND _headers_to_moc ${_current_FILE})
  21. else (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
  22. message(STATUS "AUTOMOC4_MOC_HEADERS: ignoring non-header file ${_current_FILE}")
  23. endif (".h" STREQUAL "${_suffix}" OR ".hpp" STREQUAL "${_suffix}" OR ".hxx" STREQUAL "${_suffix}" OR ".H" STREQUAL "${_suffix}")
  24. endforeach (_current_FILE)
  25. # need to create moc_<filename>.cpp file using automoc4
  26. # and add it to the target
  27. if(_headers_to_moc)
  28. set(_automoc4_headers_${_target_NAME} "${_headers_to_moc}")
  29. endif(_headers_to_moc)
  30. endmacro (AUTOMOC4_MOC_HEADERS)
  31. macro(AUTOMOC4 _target_NAME _SRCS)
  32. set(_moc_files)
  33. # first list all explicitly set headers
  34. foreach(_header_to_moc ${_automoc4_headers_${_target_NAME}} )
  35. get_filename_component(_abs_header ${_header_to_moc} ABSOLUTE)
  36. list(APPEND _moc_files ${_abs_header})
  37. endforeach(_header_to_moc)
  38. # now add all the sources for the automoc
  39. foreach (_current_FILE ${${_SRCS}})
  40. get_filename_component(_abs_current_FILE "${_current_FILE}" ABSOLUTE)
  41. get_source_file_property(_skip "${_abs_current_FILE}" SKIP_AUTOMOC)
  42. get_source_file_property(_generated "${_abs_current_FILE}" GENERATED)
  43. if(NOT _generated AND NOT _skip)
  44. get_filename_component(_suffix "${_current_FILE}" EXT)
  45. # skip every source file that's not C++
  46. if(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  47. list(APPEND _moc_files ${_abs_current_FILE})
  48. endif(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  49. endif(NOT _generated AND NOT _skip)
  50. endforeach (_current_FILE)
  51. if(_moc_files)
  52. set(_automoc_source "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_automoc.cpp")
  53. get_directory_property(_moc_incs INCLUDE_DIRECTORIES)
  54. get_directory_property(_moc_defs DEFINITIONS)
  55. get_directory_property(_moc_cdefs COMPILE_DEFINITIONS)
  56. # configure_file replaces _moc_files, _moc_incs, _moc_cdefs and _moc_defs
  57. configure_file(${_AUTOMOC4_CURRENT_DIR}/automoc4.files.in ${_automoc_source}.files)
  58. add_custom_command(OUTPUT ${_automoc_source}
  59. COMMAND ${AUTOMOC4_EXECUTABLE}
  60. ${_automoc_source}
  61. ${CMAKE_CURRENT_SOURCE_DIR}
  62. ${CMAKE_CURRENT_BINARY_DIR}
  63. ${QT_MOC_EXECUTABLE}
  64. ${CMAKE_COMMAND}
  65. --touch
  66. DEPENDS ${_automoc_source}.files ${_AUTOMOC4_EXECUTABLE_DEP}
  67. COMMENT ""
  68. VERBATIM
  69. )
  70. set(${_SRCS} ${_automoc_source} ${${_SRCS}})
  71. endif(_moc_files)
  72. endmacro(AUTOMOC4)
  73. macro(ADD_AUTOMOC4_TARGET _target_NAME _SRCS)
  74. set(_moc_files)
  75. set(_moc_headers)
  76. # first list all explicitly set headers
  77. foreach(_header_to_moc ${ARGN} )
  78. get_filename_component(_abs_header ${_header_to_moc} ABSOLUTE)
  79. list(APPEND _moc_files ${_abs_header})
  80. list(APPEND _moc_headers ${_abs_header})
  81. endforeach(_header_to_moc)
  82. # now add all the sources for the automoc
  83. foreach (_current_FILE ${${_SRCS}})
  84. get_filename_component(_abs_current_FILE "${_current_FILE}" ABSOLUTE)
  85. get_source_file_property(_skip "${_abs_current_FILE}" SKIP_AUTOMOC)
  86. get_source_file_property(_generated "${_abs_current_FILE}" GENERATED)
  87. if(NOT _generated AND NOT _skip)
  88. get_filename_component(_suffix "${_current_FILE}" EXT)
  89. # skip every source file that's not C++
  90. if(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  91. get_filename_component(_basename "${_current_FILE}" NAME_WE)
  92. get_filename_component(_abs_path "${_abs_current_FILE}" PATH)
  93. set(_header "${_abs_path}/${_basename}.h")
  94. if(EXISTS "${_header}")
  95. list(APPEND _moc_headers ${_header})
  96. endif(EXISTS "${_header}")
  97. set(_pheader "${_abs_path}/${_basename}_p.h")
  98. if(EXISTS "${_pheader}")
  99. list(APPEND _moc_headers ${_pheader})
  100. endif(EXISTS "${_pheader}")
  101. list(APPEND _moc_files ${_abs_current_FILE})
  102. endif(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  103. endif(NOT _generated AND NOT _skip)
  104. endforeach (_current_FILE)
  105. if(_moc_files)
  106. set(_automoc_source "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}.cpp")
  107. set(_automoc_dotFiles "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}.cpp.files")
  108. get_directory_property(_moc_incs INCLUDE_DIRECTORIES)
  109. get_directory_property(_moc_defs DEFINITIONS)
  110. get_directory_property(_moc_cdefs COMPILE_DEFINITIONS)
  111. # configure_file replaces _moc_files, _moc_incs, _moc_cdefs and _moc_defs
  112. configure_file(${_AUTOMOC4_CURRENT_DIR}/automoc4.files.in ${_automoc_dotFiles})
  113. add_custom_target(${_target_NAME}
  114. ALL
  115. COMMAND ${AUTOMOC4_EXECUTABLE}
  116. ${_automoc_source}
  117. ${CMAKE_CURRENT_SOURCE_DIR}
  118. ${CMAKE_CURRENT_BINARY_DIR}
  119. ${QT_MOC_EXECUTABLE}
  120. ${CMAKE_COMMAND}
  121. DEPENDS ${_automoc_dotFiles} ${_AUTOMOC4_EXECUTABLE_DEP} ${_moc_headers} ${${_SRCS}}
  122. COMMENT ""
  123. VERBATIM
  124. )
  125. set_source_files_properties(${_automoc_source} PROPERTIES GENERATED TRUE)
  126. set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${_automoc_source})
  127. set(${_SRCS} ${_automoc_source} ${${_SRCS}})
  128. endif(_moc_files)
  129. endmacro(ADD_AUTOMOC4_TARGET)