[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] | 35 | FUNCTION(PREPARE_SOURCE_FILES) |
---|
[2620] | 36 | SET(_fullpath_sources) |
---|
| 37 | FOREACH(_file ${ARGN}) |
---|
[5929] | 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) |
---|
[5963] | 50 | SET(_compilation_file ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name}) |
---|
[5929] | 51 | SET(_include_string) |
---|
| 52 | FOREACH(_file2 ${_compilation}) |
---|
| 53 | SET(_include_string "${_include_string}#include \"${_file2}\"\n") |
---|
| 54 | ENDFOREACH(_file2) |
---|
[6084] | 55 | IF(EXISTS ${_compilation_file}) |
---|
[5963] | 56 | FILE(READ ${_compilation_file} _include_string_file) |
---|
[5929] | 57 | ENDIF() |
---|
| 58 | IF(NOT _include_string STREQUAL "${_include_string_file}") |
---|
[5963] | 59 | FILE(WRITE ${_compilation_file} "${_include_string}") |
---|
[5929] | 60 | ENDIF() |
---|
[5963] | 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 | IF(MSVC) |
---|
| 65 | SET_SOURCE_FILES_PROPERTIES(${_compilation_file} PROPERTIES COMPILE_FLAGS "-Zm1000") |
---|
| 66 | ENDIF() |
---|
[5929] | 67 | ENDIF() |
---|
| 68 | SET(_compilation_name) |
---|
| 69 | SET(_compilation) |
---|
| 70 | SET(_compile FALSE) |
---|
| 71 | ELSE() |
---|
| 72 | # Prefix the full path |
---|
| 73 | GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION) |
---|
| 74 | LIST(APPEND _fullpath_sources ${_filepath}) |
---|
| 75 | IF(_compile AND NOT DISABLE_COMPILATIONS) |
---|
| 76 | LIST(APPEND _compilation ${_filepath}) |
---|
| 77 | LIST(APPEND _fullpath_sources "H") |
---|
| 78 | ENDIF() |
---|
| 79 | ENDIF() |
---|
[2620] | 80 | ENDFOREACH(_file) |
---|
[5929] | 81 | SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE) |
---|
| 82 | ENDFUNCTION(PREPARE_SOURCE_FILES) |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | # Adds source files with the full path to a list |
---|
| 86 | FUNCTION(ADD_SOURCE_FILES _varname) |
---|
| 87 | PREPARE_SOURCE_FILES(${ARGN}) |
---|
[2620] | 88 | # Write into the cache to avoid variable scoping in subdirs |
---|
| 89 | SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit") |
---|
| 90 | ENDFUNCTION(ADD_SOURCE_FILES) |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | # Sets source files with the full path |
---|
| 94 | FUNCTION(SET_SOURCE_FILES _varname) |
---|
[5929] | 95 | PREPARE_SOURCE_FILES(${ARGN}) |
---|
[2620] | 96 | # Write into the cache to avoid variable scoping in subdirs |
---|
| 97 | SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit") |
---|
| 98 | ENDFUNCTION(SET_SOURCE_FILES) |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | # Search the entire directory tree for header files and add them to a variable |
---|
| 102 | MACRO(GET_ALL_HEADER_FILES _target_varname) |
---|
| 103 | FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h") |
---|
| 104 | ENDMACRO(GET_ALL_HEADER_FILES) |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | # Generate source groups according to the directory structure |
---|
| 108 | FUNCTION(GENERATE_SOURCE_GROUPS) |
---|
| 109 | |
---|
| 110 | FOREACH(_file ${ARGN}) |
---|
| 111 | GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION) |
---|
| 112 | FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath}) |
---|
[5929] | 113 | IF(NOT _relative_path MATCHES "^\\.\\.") |
---|
| 114 | GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH) |
---|
| 115 | STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}") |
---|
| 116 | SOURCE_GROUP("Source\\${_group_path}" FILES ${_file}) |
---|
| 117 | ELSE() |
---|
| 118 | # Has to be a compilation |
---|
| 119 | SOURCE_GROUP("Compilations" FILES ${_file}) |
---|
| 120 | ENDIF() |
---|
[2620] | 121 | ENDFOREACH(_file) |
---|
| 122 | |
---|
| 123 | ENDFUNCTION(GENERATE_SOURCE_GROUPS) |
---|