Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 21, 2008, 10:36:51 PM (16 years ago)
Author:
rgrieder
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem2/cmake/AddSourceFiles.cmake

    r2131 r2518  
    1616#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
    1717
    18 MACRO(ADD_SOURCE_DIRECTORY _target_list _directory)
     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.
    1924
    20   # Subfolder puts source files into CMake Cache variable _CACHED_SOURCE_FILES
     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
    2146  ADD_SUBDIRECTORY(${_directory})
     47  # Recover our own local variable
     48  SET(_source_files_internal_local ${_source_files_internal_temp})
    2249
    2350  # Put the directory name in front of each source file from the subfolder
    24   # and add it to the source list in the current directory
    25   FOREACH(_source_file ${_CACHED_SOURCE_FILES})
    26     LIST(APPEND ${_target_list} "${_directory}/${_source_file}")
     51  SET(_source_files_internal_temp)
     52  FOREACH(_source_file ${_source_files_internal_parent})
     53    LIST(APPEND _source_files_internal_temp "${_directory}/${_source_file}")
    2754  ENDFOREACH(_source_file)
     55
     56  # Add the content of the temporary list
     57  ADD_SOURCE_FILES(${_source_files_internal_temp})
    2858
    2959ENDMACRO(ADD_SOURCE_DIRECTORY)
    3060
     61# Writes the content from the internal variables to a user specified one
     62MACRO(WRITE_SOURCE_FILES _variable_name)
    3163
    32 MACRO(ADD_SOURCE_FILES _source_list)
    33  
    34   # Put the source file into a variable that still exists in this_folder/../
    35   # Use FORCE to always overwrite the cache variable
    36   SET(_CACHED_SOURCE_FILES ${${_source_list}} CACHE STRING "" FORCE)
    37   MARK_AS_ADVANCED(_CACHED_SOURCE_FILES FORCE)
     64  SET(${_variable_name} ${_source_files_internal_local})
    3865
    39 ENDMACRO(ADD_SOURCE_FILES)
     66ENDMACRO(WRITE_SOURCE_FILES)
Note: See TracChangeset for help on using the changeset viewer.