Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/cmake/tools/SourceFileUtilities.cmake @ 7869

Last change on this file since 7869 was 7415, checked in by rgrieder, 14 years ago

Placing all generated files in source group "Generated" for MSVC instead of different groups for PCH, Tolua and Compilations.

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
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.
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.
32 #    GENERATE_SOURCE_GROUPS - Set Visual Studio source groups.
33 #
34
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      IF(NOT DISABLE_COMPILATIONS)
50        SET(_compilation_file ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
51        SET(_include_string)
52        FOREACH(_file2 ${_compilation})
53          SET(_include_string "${_include_string}#include \"${_file2}\"\n")
54        ENDFOREACH(_file2)
55        IF(EXISTS ${_compilation_file})
56          FILE(READ ${_compilation_file} _include_string_file)
57        ENDIF()
58        IF(NOT _include_string STREQUAL "${_include_string_file}")
59          FILE(WRITE ${_compilation_file} "${_include_string}")
60        ENDIF()
61        LIST(APPEND _fullpath_sources ${_compilation_file})
62        # MSVC hack that excludes the compilations from the intellisense database
63        # (There is a bug with the "-" instead of "/". Only works for "Zm#" argument)
64        # 2nd Note: Exploiting this results in a strange separation of the compilation
65        # file, causing the compiler not to use multi processing --> slower compiling.
66        #IF(MSVC)
67        #    SET_SOURCE_FILES_PROPERTIES(${_compilation_file} PROPERTIES COMPILE_FLAGS "-Zm1000")
68        #ENDIF()
69      ENDIF()
70      SET(_compilation_name)
71      SET(_compilation)
72      SET(_compile FALSE)
73    ELSE()
74      # Prefix the full path
75      GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
76      LIST(APPEND _fullpath_sources ${_filepath})
77      IF(_compile AND NOT DISABLE_COMPILATIONS)
78        LIST(APPEND _compilation ${_filepath})
79        LIST(APPEND _fullpath_sources "H")
80      ENDIF()
81    ENDIF()
82  ENDFOREACH(_file)
83  SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
84ENDFUNCTION(PREPARE_SOURCE_FILES)
85
86
87# Adds source files with the full path to a list
88FUNCTION(ADD_SOURCE_FILES _varname)
89  PREPARE_SOURCE_FILES(${ARGN})
90  # Write into the cache to avoid variable scoping in subdirs
91  SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
92ENDFUNCTION(ADD_SOURCE_FILES)
93
94
95# Sets source files with the full path
96FUNCTION(SET_SOURCE_FILES _varname)
97  PREPARE_SOURCE_FILES(${ARGN})
98  # Write into the cache to avoid variable scoping in subdirs
99  SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
100ENDFUNCTION(SET_SOURCE_FILES)
101
102
103# Search the entire directory tree for header files and add them to a variable
104MACRO(GET_ALL_HEADER_FILES _target_varname)
105  FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
106ENDMACRO(GET_ALL_HEADER_FILES)
107
108
109# Generate source groups according to the directory structure
110FUNCTION(GENERATE_SOURCE_GROUPS)
111
112  FOREACH(_file ${ARGN})
113    GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
114    FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
115    IF(NOT _relative_path MATCHES "^\\.\\.")
116      GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
117      STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
118      SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
119    ELSE()
120      # File is being generated in the binary directory
121      SOURCE_GROUP("Generated" FILES ${_file})
122    ENDIF()
123  ENDFOREACH(_file)
124
125ENDFUNCTION(GENERATE_SOURCE_GROUPS)
Note: See TracBrowser for help on using the repository browser.