Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2573 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
RevLine 
[2131]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
[2518]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.
[2125]24
[2518]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
[2130]46  ADD_SUBDIRECTORY(${_directory})
[2518]47  # Recover our own local variable
48  SET(_source_files_internal_local ${_source_files_internal_temp})
[2125]49
[2130]50  # Put the directory name in front of each source file from the subfolder
[2518]51  SET(_source_files_internal_temp)
52  FOREACH(_source_file ${_source_files_internal_parent})
53    LIST(APPEND _source_files_internal_temp "${_directory}/${_source_file}")
[2125]54  ENDFOREACH(_source_file)
[2130]55
[2518]56  # Add the content of the temporary list
57  ADD_SOURCE_FILES(${_source_files_internal_temp})
58
[2130]59ENDMACRO(ADD_SOURCE_DIRECTORY)
60
[2518]61# Writes the content from the internal variables to a user specified one
62MACRO(WRITE_SOURCE_FILES _variable_name)
[2130]63
[2518]64  SET(${_variable_name} ${_source_files_internal_local})
[2130]65
[2518]66ENDMACRO(WRITE_SOURCE_FILES)
Note: See TracBrowser for help on using the repository browser.