[Orxonox-commit 1149] r5870 - code/branches/core5/cmake
rgrieder at orxonox.net
rgrieder at orxonox.net
Sun Oct 4 14:07:17 CEST 2009
Author: rgrieder
Date: 2009-10-04 14:07:17 +0200 (Sun, 04 Oct 2009)
New Revision: 5870
Modified:
code/branches/core5/cmake/SourceFileUtilities.cmake
code/branches/core5/cmake/TargetUtilities.cmake
Log:
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.
Modified: code/branches/core5/cmake/SourceFileUtilities.cmake
===================================================================
--- code/branches/core5/cmake/SourceFileUtilities.cmake 2009-10-03 22:26:05 UTC (rev 5869)
+++ code/branches/core5/cmake/SourceFileUtilities.cmake 2009-10-04 12:07:17 UTC (rev 5870)
@@ -23,18 +23,59 @@
# Several functions that help organising the source tree.
# [ADD/SET]_SOURCE_FILES - Writes source files to the cache by force and
# adds the current directory.
- # GET_ALL_HEADER_FILES - Finds all header files recursively.
+ # Also compiles multiple source files into a single
+ # one by including them
+ # Use COMPILATION_[BEGIN|END] in
+ # [ADD|SET]_SOURCE_FILES and specify the name of
+ # the new source file after COMPILATION_BEGIN
+ # GET_ALL_HEADER_FILES - Finds all header files recursively.
# GENERATE_SOURCE_GROUPS - Set Visual Studio source groups.
#
-# Adds source files with the full path to a list
-FUNCTION(ADD_SOURCE_FILES _varname)
- # Prefix the full path
+FUNCTION(PREPARE_SOURCE_FILES)
SET(_fullpath_sources)
FOREACH(_file ${ARGN})
- GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
- LIST(APPEND _fullpath_sources ${_filepath})
+ IF(_file STREQUAL "COMPILATION_BEGIN")
+ SET(_compile TRUE)
+ # Next file is the name of the compilation
+ SET(_get_name TRUE)
+ ELSEIF(_get_name)
+ SET(_get_name FALSE)
+ SET(_compilation_name ${_file})
+ ELSEIF(_file STREQUAL "COMPILATION_END")
+ IF(NOT _compilation_name)
+ MESSAGE(FATAL_ERROR "No name provided for source file compilation")
+ ENDIF()
+ FOREACH(_file2 ${_compilation})
+ SET(_include_string "${_include_string}\n#include \"${_file2}\"")
+ ENDFOREACH(_file2)
+ IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
+ FILE(READ ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name} _include_string_file)
+ ENDIF()
+ IF(NOT _include_string STREQUAL "${_include_string_file}")
+ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name} "${_include_string}")
+ ENDIF()
+ LIST(APPEND _fullpath_sources ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
+ SET(_compilation_name)
+ SET(_compilation)
+ SET(_compile FALSE)
+ ELSE()
+ # Prefix the full path
+ GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
+ LIST(APPEND _fullpath_sources ${_filepath})
+ IF(_compile)
+ LIST(APPEND _compilation ${_filepath})
+ LIST(APPEND _fullpath_sources "H")
+ ENDIF()
+ ENDIF()
ENDFOREACH(_file)
+ SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
+ENDFUNCTION(PREPARE_SOURCE_FILES)
+
+
+# Adds source files with the full path to a list
+FUNCTION(ADD_SOURCE_FILES _varname)
+ PREPARE_SOURCE_FILES(${ARGN})
# Write into the cache to avoid variable scoping in subdirs
SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
ENDFUNCTION(ADD_SOURCE_FILES)
@@ -42,12 +83,7 @@
# Sets source files with the full path
FUNCTION(SET_SOURCE_FILES _varname)
- # Prefix the full path
- SET(_fullpath_sources)
- FOREACH(_file ${ARGN})
- GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
- LIST(APPEND _fullpath_sources ${_filepath})
- ENDFOREACH(_file)
+ PREPARE_SOURCE_FILES(${ARGN})
# Write into the cache to avoid variable scoping in subdirs
SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
ENDFUNCTION(SET_SOURCE_FILES)
@@ -65,9 +101,14 @@
FOREACH(_file ${ARGN})
GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
- GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
- STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
- SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
+ IF(NOT _relative_path MATCHES "^\\.\\.")
+ GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
+ STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
+ SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
+ ELSE()
+ # Has to be a compilation
+ SOURCE_GROUP("Compilations" FILES ${_file})
+ ENDIF()
ENDFOREACH(_file)
ENDFUNCTION(GENERATE_SOURCE_GROUPS)
Modified: code/branches/core5/cmake/TargetUtilities.cmake
===================================================================
--- code/branches/core5/cmake/TargetUtilities.cmake 2009-10-03 22:26:05 UTC (rev 5869)
+++ code/branches/core5/cmake/TargetUtilities.cmake 2009-10-04 12:07:17 UTC (rev 5870)
@@ -87,13 +87,24 @@
PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
- # GET_HEADER_FILES
+ # Workaround: Source file properties get lost when leaving a subdirectory
+ # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY
+ FOREACH(_file ${_arg_SOURCE_FILES})
+ IF(_file STREQUAL "H")
+ SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+ ELSE()
+ SET(_last_file ${_file})
+ LIST(APPEND _${_target_name}_source_files ${_file})
+ ENDIF()
+ ENDFOREACH(_file)
+
+ # Assemble all header files of the library
IF(_arg_FIND_HEADER_FILES)
- GET_ALL_HEADER_FILES(_${target_name}_header_files)
+ GET_ALL_HEADER_FILES(_${_target_name}_header_files)
ENDIF()
# Remove potential duplicates
- SET(_${_target_name}_files ${_${target_name}_header_files} ${_arg_SOURCE_FILES})
+ SET(_${_target_name}_files ${_${_target_name}_header_files} ${_${_target_name}_source_files})
LIST(REMOVE_DUPLICATES _${_target_name}_files)
# Generate the source groups
More information about the Orxonox-commit
mailing list