Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/forks/sandbox_qt/cmake/tools/SourceFileUtilities.cmake @ 8740

Last change on this file since 8740 was 7820, checked in by rgrieder, 14 years ago

Fixed problem with files directly supplied to ORXONOX_ADD_TARGET.

  • Property svn:eol-style set to native
File size: 3.6 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.
[5929]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
[5929]35FUNCTION(PREPARE_SOURCE_FILES)
[7805]36  SET(_source_files)
[2620]37  FOREACH(_file ${ARGN})
[7805]38    IF(_file MATCHES "^(COMPILATION_BEGIN|COMPILATION_END|QT)$")
39      # Append keywords verbatim
40      LIST(APPEND _source_files ${_file})
[5929]41    ELSE()
[7805]42      # Store file with path relative to the root source directory
43      FILE(RELATIVE_PATH _file_rel ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
[7820]44      LIST(APPEND _source_files ./${_file_rel})
[5929]45    ENDIF()
[2620]46  ENDFOREACH(_file)
[7805]47  SET(_source_files ${_source_files} PARENT_SCOPE)
[5929]48ENDFUNCTION(PREPARE_SOURCE_FILES)
49
50
51# Adds source files with the full path to a list
52FUNCTION(ADD_SOURCE_FILES _varname)
53  PREPARE_SOURCE_FILES(${ARGN})
[2620]54  # Write into the cache to avoid variable scoping in subdirs
[7805]55  SET(${_varname} ${${_varname}} ${_source_files} CACHE INTERNAL "Do not edit")
[2620]56ENDFUNCTION(ADD_SOURCE_FILES)
57
58
59# Sets source files with the full path
60FUNCTION(SET_SOURCE_FILES _varname)
[5929]61  PREPARE_SOURCE_FILES(${ARGN})
[2620]62  # Write into the cache to avoid variable scoping in subdirs
[7805]63  SET(${_varname} ${_source_files} CACHE INTERNAL "Do not edit")
[2620]64ENDFUNCTION(SET_SOURCE_FILES)
65
66
67# Search the entire directory tree for header files and add them to a variable
68MACRO(GET_ALL_HEADER_FILES _target_varname)
69  FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
70ENDMACRO(GET_ALL_HEADER_FILES)
71
72
73# Generate source groups according to the directory structure
74FUNCTION(GENERATE_SOURCE_GROUPS)
75
76  FOREACH(_file ${ARGN})
77    GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
78    FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
[7805]79    IF(NOT _relative_path MATCHES "^\\.\\./") # Has "../" at the beginning
[5929]80      GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
81      STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
82      SOURCE_GROUP("Source\\${_group_path}" FILES ${_file})
83    ELSE()
[7415]84      # File is being generated in the binary directory
85      SOURCE_GROUP("Generated" FILES ${_file})
[5929]86    ENDIF()
[2620]87  ENDFOREACH(_file)
88
89ENDFUNCTION(GENERATE_SOURCE_GROUPS)
Note: See TracBrowser for help on using the repository browser.