Automoc4Config.cmake 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. set(_automoc4_headers_${_target_NAME}_automoc "${_headers_to_moc}")
  30. endif(_headers_to_moc)
  31. endmacro (AUTOMOC4_MOC_HEADERS)
  32. macro(AUTOMOC4 _target_NAME _SRCS)
  33. set(_moc_files)
  34. # first list all explicitly set headers
  35. foreach(_header_to_moc ${_automoc4_headers_${_target_NAME}} )
  36. get_filename_component(_abs_header ${_header_to_moc} ABSOLUTE)
  37. list(APPEND _moc_files ${_abs_header})
  38. endforeach(_header_to_moc)
  39. # now add all the sources for the automoc
  40. foreach (_current_FILE ${${_SRCS}})
  41. get_filename_component(_abs_current_FILE "${_current_FILE}" ABSOLUTE)
  42. get_source_file_property(_skip "${_abs_current_FILE}" SKIP_AUTOMOC)
  43. get_source_file_property(_generated "${_abs_current_FILE}" GENERATED)
  44. if(NOT _generated AND NOT _skip)
  45. get_filename_component(_suffix "${_current_FILE}" EXT)
  46. # skip every source file that's not C++
  47. if(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  48. list(APPEND _moc_files ${_abs_current_FILE})
  49. endif(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  50. endif(NOT _generated AND NOT _skip)
  51. endforeach (_current_FILE)
  52. if(_moc_files)
  53. set(_automoc_source "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_automoc.cpp")
  54. get_directory_property(_moc_incs INCLUDE_DIRECTORIES)
  55. get_directory_property(_moc_defs DEFINITIONS)
  56. get_directory_property(_moc_cdefs COMPILE_DEFINITIONS)
  57. # configure_file replaces _moc_files, _moc_incs, _moc_cdefs and _moc_defs
  58. configure_file(${_AUTOMOC4_CURRENT_DIR}/automoc4.files.in ${_automoc_source}.files)
  59. add_custom_command(OUTPUT ${_automoc_source}
  60. COMMAND ${AUTOMOC4_EXECUTABLE}
  61. ${_automoc_source}
  62. ${CMAKE_CURRENT_SOURCE_DIR}
  63. ${CMAKE_CURRENT_BINARY_DIR}
  64. ${QT_MOC_EXECUTABLE}
  65. ${CMAKE_COMMAND}
  66. --touch
  67. DEPENDS ${_automoc_source}.files ${_AUTOMOC4_EXECUTABLE_DEP}
  68. COMMENT ""
  69. VERBATIM
  70. )
  71. set(${_SRCS} ${_automoc_source} ${${_SRCS}})
  72. endif(_moc_files)
  73. endmacro(AUTOMOC4)
  74. macro(ADD_AUTOMOC4_TARGET _target_NAME _SRCS)
  75. set(_moc_files)
  76. set(_moc_headers)
  77. # first list all explicitly set headers
  78. foreach(_header_to_moc ${_automoc4_headers_${_target_NAME}} )
  79. get_filename_component(_abs_header ${_header_to_moc} ABSOLUTE)
  80. list(APPEND _moc_files ${_abs_header})
  81. list(APPEND _moc_headers ${_abs_header})
  82. endforeach(_header_to_moc)
  83. # now add all the sources for the automoc
  84. foreach (_current_FILE ${${_SRCS}})
  85. get_filename_component(_abs_current_FILE "${_current_FILE}" ABSOLUTE)
  86. get_source_file_property(_skip "${_abs_current_FILE}" SKIP_AUTOMOC)
  87. get_source_file_property(_generated "${_abs_current_FILE}" GENERATED)
  88. if(NOT _generated AND NOT _skip)
  89. get_filename_component(_suffix "${_current_FILE}" EXT)
  90. # skip every source file that's not C++
  91. if(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  92. get_filename_component(_basename "${_current_FILE}" NAME_WE)
  93. get_filename_component(_abs_path "${_abs_current_FILE}" PATH)
  94. set(_header "${_abs_path}/${_basename}.h")
  95. if(EXISTS "${_header}")
  96. list(APPEND _moc_headers ${_header})
  97. endif(EXISTS "${_header}")
  98. set(_pheader "${_abs_path}/${_basename}_p.h")
  99. if(EXISTS "${_pheader}")
  100. list(APPEND _moc_headers ${_pheader})
  101. endif(EXISTS "${_pheader}")
  102. list(APPEND _moc_files ${_abs_current_FILE})
  103. endif(_suffix STREQUAL ".cpp" OR _suffix STREQUAL ".cc" OR _suffix STREQUAL ".cxx" OR _suffix STREQUAL ".C")
  104. endif(NOT _generated AND NOT _skip)
  105. endforeach (_current_FILE)
  106. if(_moc_files)
  107. set(_automoc_source "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}.cpp")
  108. set(_automoc_dotFiles "${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}.cpp.files")
  109. get_directory_property(_moc_incs INCLUDE_DIRECTORIES)
  110. get_directory_property(_moc_defs DEFINITIONS)
  111. get_directory_property(_moc_cdefs COMPILE_DEFINITIONS)
  112. # configure_file replaces _moc_files, _moc_incs, _moc_cdefs and _moc_defs
  113. configure_file(${_AUTOMOC4_CURRENT_DIR}/automoc4.files.in ${_automoc_dotFiles})
  114. add_custom_target(${_target_NAME}
  115. ALL
  116. COMMAND ${AUTOMOC4_EXECUTABLE}
  117. ${_automoc_source}
  118. ${CMAKE_CURRENT_SOURCE_DIR}
  119. ${CMAKE_CURRENT_BINARY_DIR}
  120. ${QT_MOC_EXECUTABLE}
  121. ${CMAKE_COMMAND}
  122. DEPENDS ${_automoc_dotFiles} ${_AUTOMOC4_EXECUTABLE_DEP} ${_moc_headers} ${${_SRCS}}
  123. COMMENT ""
  124. VERBATIM
  125. )
  126. set_source_files_properties(${_automoc_source} PROPERTIES GENERATED TRUE)
  127. set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${_automoc_source})
  128. set(${_SRCS} ${_automoc_source} ${${_SRCS}})
  129. endif(_moc_files)
  130. endmacro(ADD_AUTOMOC4_TARGET)
  131. macro(AUTOMOC4_ADD_EXECUTABLE _target_NAME)
  132. set(_SRCS ${ARGN})
  133. set(_add_executable_param)
  134. foreach(_argName "WIN32" "MACOSX_BUNDLE" "EXCLUDE_FROM_ALL")
  135. list(FIND _SRCS ${_argName} _index)
  136. if(_index GREATER -1)
  137. list(APPEND _add_executable_param ${_argName})
  138. list(REMOVE_AT _SRCS ${_index})
  139. endif(_index GREATER -1)
  140. endforeach(_argName)
  141. if(MSVC)
  142. add_automoc4_target("${_target_NAME}_automoc" _SRCS)
  143. else(MSVC)
  144. automoc4(${_target_NAME} _SRCS)
  145. endif(MSVC)
  146. add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
  147. if(MSVC)
  148. add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
  149. endif(MSVC)
  150. endmacro(AUTOMOC4_ADD_EXECUTABLE)
  151. macro(AUTOMOC4_ADD_LIBRARY _target_NAME)
  152. set(_SRCS ${ARGN})
  153. set(_add_executable_param)
  154. foreach(_argName "STATIC" "SHARED" "MODULE" "EXCLUDE_FROM_ALL")
  155. list(FIND _SRCS ${_argName} _index)
  156. if(_index GREATER -1)
  157. list(APPEND _add_executable_param ${_argName})
  158. list(REMOVE_AT _SRCS ${_index})
  159. endif(_index GREATER -1)
  160. endforeach(_argName)
  161. if(MSVC)
  162. add_automoc4_target("${_target_NAME}_automoc" _SRCS)
  163. else(MSVC)
  164. automoc4(${_target_NAME} _SRCS)
  165. endif(MSVC)
  166. add_library(${_target_NAME} ${_add_executable_param} ${_SRCS})
  167. if(MSVC)
  168. add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
  169. endif(MSVC)
  170. endmacro(AUTOMOC4_ADD_LIBRARY)