Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem2/cmake/SourceFileUtilities.cmake @ 2623

Last change on this file since 2623 was 2620, checked in by rgrieder, 16 years ago

Added SourceFileUtilities.cmake:

  • GET_ALL_HEADER_FILES: Macro that finds all header files in a directory
  • SET_SOURCE_FILES: Functions to administrate source files among directories
  • ADD_SOURCE_FILES: Like above but doesn't overwrite
  • GENERATE_SOURCE_GROUPS: creates the source groups for the visual studio IDE according to the directory structure

Added FlagUtilities.cmake:

  • SET_COMPILER_FLAGS and SET_LINKER_FLAGS. For details see the files. The functions should be able to do all you need…
  • Property svn:eol-style set to native
File size: 2.5 KB
RevLine 
[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
19FUNCTION(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")
28ENDFUNCTION(ADD_SOURCE_FILES)
29
30
31# Sets source files with the full path
32FUNCTION(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")
41ENDFUNCTION(SET_SOURCE_FILES)
42
43
44# Search the entire directory tree for header files and add them to a variable
45MACRO(GET_ALL_HEADER_FILES _target_varname)
46  FILE(GLOB_RECURSE ${_target_varname} ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
47ENDMACRO(GET_ALL_HEADER_FILES)
48
49
50# Generate source groups according to the directory structure
51FUNCTION(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
61ENDFUNCTION(GENERATE_SOURCE_GROUPS)
Note: See TracBrowser for help on using the repository browser.