Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/cmake/SourceFileUtilities.cmake @ 6060

Last change on this file since 6060 was 5915, checked in by rgrieder, 15 years ago

Added CMake switch to disable multi-file compilations: DISABLE_COMPILATIONS

  • Property svn:eol-style set to native
File size: 4.7 KB
RevLine 
[2626]1 #
2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
4 #
5 #        This program is free software; you can redistribute it and/or
6 #         modify it under the terms of the GNU General Public License
7 #        as published by the Free Software Foundation; either version 2
8 #            of the License, or (at your option) any later version.
9 #
10 #       This program is distributed in the hope that it will be useful,
11 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #                 GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License along
16 #      with this program; if not, write to the Free Software Foundation,
17 #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #
19 #
20 #  Author:
21 #    Reto Grieder
22 #  Description:
23 #    Several functions that help organising the source tree.
24 #    [ADD/SET]_SOURCE_FILES - Writes source files to the cache by force and
25 #                             adds the current directory.
[5870]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.
[2626]32 #    GENERATE_SOURCE_GROUPS - Set Visual Studio source groups.
33 #
[2620]34
[5870]35FUNCTION(PREPARE_SOURCE_FILES)
[2620]36  SET(_fullpath_sources)
37  FOREACH(_file ${ARGN})
[5870]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()
[5915]49      IF(NOT DISABLE_COMPILATIONS)
50        SET(_include_string)
51        FOREACH(_file2 ${_compilation})
52          SET(_include_string "${_include_string}#include \"${_file2}\"\n")
53        ENDFOREACH(_file2)
54        IF(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
55          FILE(READ ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name} _include_string_file)
56        ENDIF()
57        IF(NOT _include_string STREQUAL "${_include_string_file}")
58          FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name} "${_include_string}")
59        ENDIF()
60        LIST(APPEND _fullpath_sources ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
[5870]61      ENDIF()
62      SET(_compilation_name)
63      SET(_compilation)
64      SET(_compile FALSE)
65    ELSE()
66      # Prefix the full path
67      GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
68      LIST(APPEND _fullpath_sources ${_filepath})
[5915]69      IF(_compile AND NOT DISABLE_COMPILATIONS)
[5870]70        LIST(APPEND _compilation ${_filepath})
71        LIST(APPEND _fullpath_sources "H")
72      ENDIF()
73    ENDIF()
[2620]74  ENDFOREACH(_file)
[5870]75  SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
76ENDFUNCTION(PREPARE_SOURCE_FILES)
77
78
79# Adds source files with the full path to a list
80FUNCTION(ADD_SOURCE_FILES _varname)
81  PREPARE_SOURCE_FILES(${ARGN})
[2620]82  # Write into the cache to avoid variable scoping in subdirs
83  SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
84ENDFUNCTION(ADD_SOURCE_FILES)
85
86
87# Sets source files with the full path
88FUNCTION(SET_SOURCE_FILES _varname)
[5870]89  PREPARE_SOURCE_FILES(${ARGN})
[2620]90  # Write into the cache to avoid variable scoping in subdirs
91  SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
92ENDFUNCTION(SET_SOURCE_FILES)
93
94
95# Search the entire directory tree for header files and add them to a variable
96MACRO(GET_ALL_HEADER_FILES _target_varname)
97  FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
98ENDMACRO(GET_ALL_HEADER_FILES)
99
100
101# Generate source groups according to the directory structure
102FUNCTION(GENERATE_SOURCE_GROUPS)
103
104  FOREACH(_file ${ARGN})
105    GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
106    FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
[5870]107    IF(NOT _relative_path MATCHES "^\\.\\.")
108      GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
109      STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
110      SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
111    ELSE()
112      # Has to be a compilation
113      SOURCE_GROUP("Compilations" FILES ${_file})
114    ENDIF()
[2620]115  ENDFOREACH(_file)
116
117ENDFUNCTION(GENERATE_SOURCE_GROUPS)
Note: See TracBrowser for help on using the repository browser.