Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem2/cmake/AddSourceFiles.cmake @ 2565

Last change on this file since 2565 was 2518, checked in by rgrieder, 16 years ago

Adjusted source file macros to cmake 2.6 because it offers PARENT_SCOPE variable setting which removes my little hack with the CMake cache.
Also notice that the syntax has changed:

ADD_SOURCE_FILES(

Blubb.cc
Asdf.cc

)
ADD_SOURCE_DIRECTORY(ford_prefect)

These two commands can be written in an arbitrary order.
To actually use the created list of souce files, there is a third macro:
WRITE_SOURCE_FILES(myVariableName)

A demonstration can be found by looking at src/orxonox/CMakeLists.txt and src/orxonox/objects/CMakeLists.txt

File size: 2.7 KB
Line 
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# BIG FAT NOTE:
19# There's possibly a bug in the CMake behaviour when using PARENT_SCOPE.
20# It seems like the parent variable doesn't get updated locally but written
21# correclty to the parent scope. So accessing a parent variable will always
22# return its value BEFORE the local scope was created! Mind this when
23# updating to a new CMake version.
24
25# Adds source files to the internal handler
26MACRO(ADD_SOURCE_FILES)
27 
28  # Write to parent scoped variables AND to our own scope
29  # (Also see the big fat note at the beginning of the file)
30  # --> _source_files_internal_parent stays constant here, not matter what!
31  SET(_source_files_internal_local ${_source_files_internal_local} ${ARGN})
32  SET(_source_files_internal_parent ${_source_files_internal_local} PARENT_SCOPE)
33
34ENDMACRO(ADD_SOURCE_FILES)
35
36
37# Adds a subdirectory to the internal souce file handler
38MACRO(ADD_SOURCE_DIRECTORY _directory)
39
40  # Save variable
41  SET(_source_files_internal_temp ${_source_files_internal_local})
42  # Clear the local variable because we use it in the child scope
43  SET(_source_files_internal_local)
44
45  # Subfolder puts source files into CMake variable _source_files_internal_parent
46  ADD_SUBDIRECTORY(${_directory})
47  # Recover our own local variable
48  SET(_source_files_internal_local ${_source_files_internal_temp})
49
50  # Put the directory name in front of each source file from the subfolder
51  SET(_source_files_internal_temp)
52  FOREACH(_source_file ${_source_files_internal_parent})
53    LIST(APPEND _source_files_internal_temp "${_directory}/${_source_file}")
54  ENDFOREACH(_source_file)
55
56  # Add the content of the temporary list
57  ADD_SOURCE_FILES(${_source_files_internal_temp})
58
59ENDMACRO(ADD_SOURCE_DIRECTORY)
60
61# Writes the content from the internal variables to a user specified one
62MACRO(WRITE_SOURCE_FILES _variable_name)
63
64  SET(${_variable_name} ${_source_files_internal_local})
65
66ENDMACRO(WRITE_SOURCE_FILES)
Note: See TracBrowser for help on using the repository browser.