~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to CMake/VariableList.cmake

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#
 
3
# Function converts a list of cmake cache varibles to a string of
 
4
# cmake code which set each cmake cache variable. The output in cache
 
5
# is suitable to be writen to a file for "-C file" command line
 
6
# argument for cmake.
 
7
#
 
8
function( VariableListToCache var_list cache )
 
9
  foreach( var IN LISTS ${var_list} )
 
10
    if( DEFINED ${var} )
 
11
      set( value "${${var}}" )
 
12
      get_property( type CACHE ${var} PROPERTY TYPE )
 
13
      get_property( advanced CACHE ${var} PROPERTY ADVANCED )
 
14
      get_property( helpstring CACHE ${var} PROPERTY HELPSTRING )
 
15
      get_property( strings CACHE ${var} PROPERTY STRINGS )
 
16
 
 
17
      # apply escape sequences
 
18
      foreach( e "\\" "(" ")" "#" "$" "^" "@" )
 
19
        STRING( REPLACE "${e}" "\\${e}" value "${value}" )
 
20
      endforeach()
 
21
 
 
22
      if ( "${type}" STREQUAL "" )
 
23
        set( type STRING )
 
24
      endif()
 
25
 
 
26
      set( _cache "${_cache}
 
27
set( ${var} \"${value}\" CACHE \"${type}\" \"${helpstring}\" FORCE )")
 
28
 
 
29
      if( "${advanced}" )
 
30
              set( _cache "${_cache}
 
31
  mark_as_advanced( ${var} )")
 
32
       endif()
 
33
       if( NOT "${strings}" STREQUAL "" )
 
34
              set( _cache "${_cache}
 
35
  set_property(CACHE ${var} PROPERTY STRINGS \"${strings}\")")
 
36
       endif()
 
37
    endif()
 
38
  endforeach()
 
39
  set( ${cache} "${_cache}" PARENT_SCOPE)
 
40
endfunction( )
 
41
 
 
42
#
 
43
# Function which converts a list a cmake cache variable into a list of
 
44
# "-Dvar:type=value;" suitable for command line initialization.
 
45
#
 
46
function( VariableListToArgs var_list args )
 
47
  foreach( var IN LISTS ${var_list} )
 
48
    if( DEFINED ${var} AND NOT ${var} STREQUAL "" ) # if variable has been set
 
49
      get_property( type CACHE ${var} PROPERTY TYPE )
 
50
      if (NOT "${type}" STREQUAL "")
 
51
        set(type ":${type}")
 
52
      else()
 
53
        set(type ":UNINITIALIZED")
 
54
      endif()
 
55
      set(value ${${var}})
 
56
      STRING( REPLACE ";" "$<SEMICOLON>" value "${value}" )
 
57
      list( APPEND _args "-D${var}:${type}=${value}" )
 
58
    endif()
 
59
  endforeach()
 
60
  set( ${args} "${_args}" PARENT_SCOPE)
 
61
endfunction( )