| 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 | #    GET_ALL_HEADER_FILES - Finds all header files recursively. | 
|---|
| 27 | #    GENERATE_SOURCE_GROUPS - Set Visual Studio source groups. | 
|---|
| 28 | # | 
|---|
| 29 |  | 
|---|
| 30 | # Adds source files with the full path to a list | 
|---|
| 31 | FUNCTION(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) | 
|---|
| 38 | # Write into the cache to avoid variable scoping in subdirs | 
|---|
| 39 | SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit") | 
|---|
| 40 | ENDFUNCTION(ADD_SOURCE_FILES) | 
|---|
| 41 |  | 
|---|
| 42 |  | 
|---|
| 43 | # Sets source files with the full path | 
|---|
| 44 | FUNCTION(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) | 
|---|
| 51 | # Write into the cache to avoid variable scoping in subdirs | 
|---|
| 52 | SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit") | 
|---|
| 53 | ENDFUNCTION(SET_SOURCE_FILES) | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | # Search the entire directory tree for header files and add them to a variable | 
|---|
| 57 | MACRO(GET_ALL_HEADER_FILES _target_varname) | 
|---|
| 58 | FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h") | 
|---|
| 59 | ENDMACRO(GET_ALL_HEADER_FILES) | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | # Generate source groups according to the directory structure | 
|---|
| 63 | FUNCTION(GENERATE_SOURCE_GROUPS) | 
|---|
| 64 |  | 
|---|
| 65 | FOREACH(_file ${ARGN}) | 
|---|
| 66 | GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION) | 
|---|
| 67 | 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}) | 
|---|
| 71 | ENDFOREACH(_file) | 
|---|
| 72 |  | 
|---|
| 73 | ENDFUNCTION(GENERATE_SOURCE_GROUPS) | 
|---|