[2620] | 1 | # AddSourceFiles.cmake - CMake Module to include source files in subdirectories. |
---|
| 2 | # Author: Reto '1337' Grieder (2008) |
---|
| 3 | # |
---|
| 4 | # This program is free software; you can redistribute it and/or modify |
---|
| 5 | # it under the terms of the GNU General Public License as published by |
---|
| 6 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | # (at your option) any later version. |
---|
| 8 | # |
---|
| 9 | # This program is distributed in the hope that it will be useful, |
---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | # GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License |
---|
| 15 | # along with this program; if not, write to the Free Software |
---|
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
---|
| 17 | |
---|
| 18 | # Adds source files with the full path to a list |
---|
| 19 | FUNCTION(ADD_SOURCE_FILES _varname) |
---|
| 20 | # Prefix the full path |
---|
| 21 | SET(_fullpath_sources) |
---|
| 22 | FOREACH(_file ${ARGN}) |
---|
| 23 | GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION) |
---|
| 24 | LIST(APPEND _fullpath_sources ${_filepath}) |
---|
| 25 | ENDFOREACH(_file) |
---|
| 26 | # Write into the cache to avoid variable scoping in subdirs |
---|
| 27 | SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit") |
---|
| 28 | ENDFUNCTION(ADD_SOURCE_FILES) |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | # Sets source files with the full path |
---|
| 32 | FUNCTION(SET_SOURCE_FILES _varname) |
---|
| 33 | # Prefix the full path |
---|
| 34 | SET(_fullpath_sources) |
---|
| 35 | FOREACH(_file ${ARGN}) |
---|
| 36 | GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION) |
---|
| 37 | LIST(APPEND _fullpath_sources ${_filepath}) |
---|
| 38 | ENDFOREACH(_file) |
---|
| 39 | # Write into the cache to avoid variable scoping in subdirs |
---|
| 40 | SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit") |
---|
| 41 | ENDFUNCTION(SET_SOURCE_FILES) |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | # Search the entire directory tree for header files and add them to a variable |
---|
| 45 | MACRO(GET_ALL_HEADER_FILES _target_varname) |
---|
| 46 | FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h") |
---|
| 47 | ENDMACRO(GET_ALL_HEADER_FILES) |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | # Generate source groups according to the directory structure |
---|
| 51 | FUNCTION(GENERATE_SOURCE_GROUPS) |
---|
| 52 | |
---|
| 53 | FOREACH(_file ${ARGN}) |
---|
| 54 | GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION) |
---|
| 55 | FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath}) |
---|
| 56 | GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH) |
---|
| 57 | STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}") |
---|
| 58 | SOURCE_GROUP("Source\\${_group_path}" FILES ${_file}) |
---|
| 59 | ENDFOREACH(_file) |
---|
| 60 | |
---|
| 61 | ENDFUNCTION(GENERATE_SOURCE_GROUPS) |
---|