Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2010, 11:58:25 PM (15 years ago)
Author:
rgrieder
Message:

Changed source file handling procedure, especially for Qt moc files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/forks/sandbox_qt/cmake/tools/TargetUtilities.cmake

    r7421 r7805  
    4848 #      PCH_EXCLUDE:       Source files to be excluded from PCH support
    4949 #      OUTPUT_NAME:       If you want a different name than the target name
    50  #      QT_MOC_FILES:      List of files to be processed by Qt MOC
    51  #      QT_UIC_FILES:      List of files to be processed by Qt UIC
    5250 #  Note:
    5351 #    This function also installs the target!
     
    8583  SET(_list_names LINK_LIBRARIES     VERSION           SOURCE_FILES
    8684                  DEFINE_SYMBOL      PCH_FILE          PCH_EXCLUDE
    87                   OUTPUT_NAME        QT_MOC_FILES      QT_UIC_FILES)
     85                  OUTPUT_NAME)
    8886
    8987  PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
    9088
    9189
    92   # Workaround: Source file properties get lost when leaving a subdirectory
    93   # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY
     90  # Process source files with support for compilations and QT special files
     91  # Note: All file paths are relative to the root source directory, even the
     92  #       name of the compilation file.
     93  SET(_${_target_name}_source_files)
     94  SET(_get_compilation_file FALSE)
     95  SET(_add_to_compilation FALSE)
     96  SET(_compile_qt_next FALSE)
    9497  FOREACH(_file ${_arg_SOURCE_FILES})
    95     IF(_file STREQUAL "H")
    96       SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE)
     98    IF(_file STREQUAL "COMPILATION_BEGIN")
     99      # Next file is the name of the compilation
     100      SET(_get_compilation_file TRUE)
     101    ELSEIF(_file STREQUAL "COMPILATION_END")
     102      IF(NOT _compilation_file)
     103        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
     104      ENDIF()
     105      IF(NOT _compilation_include_string)
     106        MESSAGE(STATUS "Warning: Empty source file compilation!")
     107      ENDIF()
     108      IF(NOT DISABLE_COMPILATIONS)
     109        IF(EXISTS ${_compilation_file})
     110          FILE(READ ${_compilation_file} _include_string_file)
     111        ENDIF()
     112        IF(NOT _compilation_include_string STREQUAL "${_include_string_file}")
     113          FILE(WRITE ${_compilation_file} "${_compilation_include_string}")
     114        ENDIF()
     115        LIST(APPEND _${_target_name}_source_files ${_compilation_file})
     116      ENDIF()
     117      SET(_add_to_compilation FALSE)
     118    ELSEIF(_get_compilation_file)
     119      SET(_compilation_file ${CMAKE_BINARY_DIR}/${_file})
     120      SET(_get_compilation_file FALSE)
     121      SET(_add_to_compilation TRUE)
     122      SET(_compilation_include_string)
     123    ELSEIF(_file STREQUAL "QT")
     124      SET(_compile_qt_next TRUE)
    97125    ELSE()
    98       SET(_last_file ${_file})
     126      # Default, add source file
     127      SET(_file ${CMAKE_SOURCE_DIR}/${_file})
    99128      LIST(APPEND _${_target_name}_source_files ${_file})
     129
     130      # Handle compilations
     131      IF(_add_to_compilation AND NOT DISABLE_COMPILATIONS)
     132        IF(_file MATCHES "\\.(c|cc|cpp|cxx)$")
     133          SET(_compilation_include_string "${_compilation_include_string}#include \"${_file}\"\n")
     134        ENDIF()
     135        # Don't compile these files, even if they are source files
     136        SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
     137      ENDIF()
     138
     139      # Handle Qt MOC and UI files
     140      IF(_compile_qt_next)
     141        GET_FILENAME_COMPONENT(_ext ${_file} EXT)
     142        IF(_ext STREQUAL ".ui")
     143          QT4_WRAP_UI(_${_target_name}_source_files ${_file})
     144        ELSEIF(_ext STREQUAL ".qrc")
     145          QT4_ADD_RESOURCES(_${_target_name}_source_files ${_file})
     146        ELSEIF(_ext MATCHES "^\\.(h|hpp|hxx)$")
     147          QT4_WRAP_CPP(_${_target_name}_source_files ${_file})
     148        ENDIF()
     149        SET(_compile_qt_next FALSE)
     150      ENDIF()
    100151    ENDIF()
    101152  ENDFOREACH(_file)
     
    106157  ENDIF()
    107158
    108   # Combine source, header and QT designer files
     159  # Combine source and header files
    109160  SET(_${_target_name}_files
    110161    ${_${_target_name}_header_files}
    111162    ${_${_target_name}_source_files}
    112     ${_arg_QT_UIC_FILES}
    113163  )
    114164  # Remove potential duplicates
    115165  LIST(REMOVE_DUPLICATES _${_target_name}_files)
    116 
    117   # QT MOC and UIC preprocessing
    118   IF(_arg_QT_MOC_FILES)
    119       QT4_WRAP_CPP(_${_target_name}_files ${_arg_QT_MOC_FILES})
    120   ENDIF()
    121   IF(_arg_QT_UIC_FILES)
    122       QT4_WRAP_UI(_${_target_name}_files ${_arg_QT_UIC_FILES})
    123   ENDIF()
    124166
    125167  # First part (pre target) of precompiled header files
     
    174216  # Don't compile header files
    175217  FOREACH(_file ${_${_target_name}_files})
    176     IF(NOT _file MATCHES "\\.(c|cc|cpp)")
     218    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx)$")
    177219      SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
    178220    ENDIF()
Note: See TracChangeset for help on using the changeset viewer.