Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2009, 2:07:17 PM (15 years ago)
Author:
rgrieder
Message:

Added new build system feature: Combining multiple source files into one. All you have to do is group a few source files with "COMPILATION_BEGIN compilation_name" and COMPILATION_END.
This could also help reducing the compile time because 10 small files with the same includes compile combined just a bit slower than one of them.

Location:
code/branches/core5/cmake
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/cmake/SourceFileUtilities.cmake

    r2710 r5870  
    2424 #    [ADD/SET]_SOURCE_FILES - Writes source files to the cache by force and
    2525 #                             adds the current directory.
    26  #    GET_ALL_HEADER_FILES - Finds all header files recursively.
     26 #                             Also compiles multiple source files into a single
     27 #                             one by including them
     28 #                             Use COMPILATION_[BEGIN|END] in
     29 #                             [ADD|SET]_SOURCE_FILES and specify the name of
     30 #                             the new source file after COMPILATION_BEGIN
     31 #    GET_ALL_HEADER_FILES   - Finds all header files recursively.
    2732 #    GENERATE_SOURCE_GROUPS - Set Visual Studio source groups.
    2833 #
    2934
     35FUNCTION(PREPARE_SOURCE_FILES)
     36  SET(_fullpath_sources)
     37  FOREACH(_file ${ARGN})
     38    IF(_file STREQUAL "COMPILATION_BEGIN")
     39      SET(_compile TRUE)
     40      # Next file is the name of the compilation
     41      SET(_get_name TRUE)
     42    ELSEIF(_get_name)
     43      SET(_get_name FALSE)
     44      SET(_compilation_name ${_file})
     45    ELSEIF(_file STREQUAL "COMPILATION_END")
     46      IF(NOT _compilation_name)
     47        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
     48      ENDIF()
     49      FOREACH(_file2 ${_compilation})
     50        SET(_include_string "${_include_string}\n#include \"${_file2}\"")
     51      ENDFOREACH(_file2)
     52      IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
     53        FILE(READ ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name} _include_string_file)
     54      ENDIF()
     55      IF(NOT _include_string STREQUAL "${_include_string_file}")
     56        FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name} "${_include_string}")
     57      ENDIF()
     58      LIST(APPEND _fullpath_sources ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
     59      SET(_compilation_name)
     60      SET(_compilation)
     61      SET(_compile FALSE)
     62    ELSE()
     63      # Prefix the full path
     64      GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
     65      LIST(APPEND _fullpath_sources ${_filepath})
     66      IF(_compile)
     67        LIST(APPEND _compilation ${_filepath})
     68        LIST(APPEND _fullpath_sources "H")
     69      ENDIF()
     70    ENDIF()
     71  ENDFOREACH(_file)
     72  SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
     73ENDFUNCTION(PREPARE_SOURCE_FILES)
     74
     75
    3076# Adds source files with the full path to a list
    3177FUNCTION(ADD_SOURCE_FILES _varname)
    32   # Prefix the full path
    33   SET(_fullpath_sources)
    34   FOREACH(_file ${ARGN})
    35     GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
    36     LIST(APPEND _fullpath_sources ${_filepath})
    37   ENDFOREACH(_file)
     78  PREPARE_SOURCE_FILES(${ARGN})
    3879  # Write into the cache to avoid variable scoping in subdirs
    3980  SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
     
    4384# Sets source files with the full path
    4485FUNCTION(SET_SOURCE_FILES _varname)
    45   # Prefix the full path
    46   SET(_fullpath_sources)
    47   FOREACH(_file ${ARGN})
    48     GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
    49     LIST(APPEND _fullpath_sources ${_filepath})
    50   ENDFOREACH(_file)
     86  PREPARE_SOURCE_FILES(${ARGN})
    5187  # Write into the cache to avoid variable scoping in subdirs
    5288  SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
     
    66102    GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
    67103    FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
    68     GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
    69     STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
    70     SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
     104    IF(NOT _relative_path MATCHES "^\\.\\.")
     105      GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
     106      STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
     107      SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
     108    ELSE()
     109      # Has to be a compilation
     110      SOURCE_GROUP("Compilations" FILES ${_file})
     111    ENDIF()
    71112  ENDFOREACH(_file)
    72113
  • code/branches/core5/cmake/TargetUtilities.cmake

    r5809 r5870  
    8888
    8989
    90   # GET_HEADER_FILES
     90  # Workaround: Source file properties get lost when leaving a subdirectory
     91  # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY
     92  FOREACH(_file ${_arg_SOURCE_FILES})
     93    IF(_file STREQUAL "H")
     94      SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE)
     95    ELSE()
     96      SET(_last_file ${_file})
     97      LIST(APPEND _${_target_name}_source_files ${_file})
     98    ENDIF()
     99  ENDFOREACH(_file)
     100
     101  # Assemble all header files of the library
    91102  IF(_arg_FIND_HEADER_FILES)
    92     GET_ALL_HEADER_FILES(_${target_name}_header_files)
     103    GET_ALL_HEADER_FILES(_${_target_name}_header_files)
    93104  ENDIF()
    94105
    95106  # Remove potential duplicates
    96   SET(_${_target_name}_files ${_${target_name}_header_files} ${_arg_SOURCE_FILES})
     107  SET(_${_target_name}_files ${_${_target_name}_header_files} ${_${_target_name}_source_files})
    97108  LIST(REMOVE_DUPLICATES _${_target_name}_files)
    98109
Note: See TracChangeset for help on using the changeset viewer.