Generate options wrappers as string literal

This commit is contained in:
Roberto Di Remigio 2018-01-31 11:24:54 +01:00
parent 30d0bb1e44
commit da6c5c0024
No known key found for this signature in database
GPG Key ID: E4FADFE6DFB29C6E

View File

@ -46,40 +46,38 @@ def autogenerated_notice():
def gen_cmake_options_wrappers():
s = []
s.append('\n# Macro for printing an option in a consistent manner')
s.append('# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)')
s.append('# Syntax: print_option(<option to print> <was specified>)')
s.append('macro(print_option variable default)')
s.append(' if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")')
s.append(' message(STATUS "Setting (unspecified) option ${variable}: ${default}")')
s.append(' else()')
s.append(' message(STATUS "Setting option ${variable}: ${${variable}}")')
s.append(' endif()')
s.append('endmacro()')
s = """\n# Macro for printing an option in a consistent manner
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: print_option(<option to print> <was specified>)
macro(print_option variable default)
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
message(STATUS "Setting (unspecified) option ${variable}: ${default}")
else()
message(STATUS "Setting option ${variable}: ${${variable}}")
endif()
endmacro()
s.append('\n# Wraps an option with default ON/OFF. Adds nice messaging to option()')
s.append('# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)')
s.append('# Syntax: option_with_print(<option name> <description> <default value>)')
s.append('macro(option_with_print variable msge default)')
s.append(' print_option(${variable} ${default})')
s.append(' option(${variable} ${msge} ${default})')
s.append('endmacro(option_with_print)')
# Wraps an option with default ON/OFF. Adds nice messaging to option()
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: option_with_print(<option name> <description> <default value>)
macro(option_with_print variable msge default)
print_option(${variable} ${default})
option(${variable} ${msge} ${default})
endmacro(option_with_print)
s.append('\n# Wraps an option with a default other than ON/OFF and prints it')
s.append('# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)')
s.append('# NOTE: Can\'t combine with above b/c CMake handles ON/OFF options specially')
s.append('# NOTE2: CMake variables are always defined so need to further check for if')
s.append('# they are the NULL string. This is also why weneed the force')
s.append('# Syntax: option_with_default(<option name> <description> <default value>)')
s.append('macro(option_with_default variable msge default)')
s.append(' print_option(${variable} "${default}")')
s.append(' if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")')
s.append(' set(${variable} "${default}" CACHE STRING ${msge} FORCE)')
s.append(' endif()')
s.append('endmacro(option_with_default)')
return '\n'.join(s)
# Wraps an option with a default other than ON/OFF and prints it
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# NOTE: Can\'t combine with above b/c CMake handles ON/OFF options specially
# NOTE2: CMake variables are always defined so need to further check for if
# they are the NULL string. This is also why weneed the force
# Syntax: option_with_default(<option name> <description> <default value>)
macro(option_with_default variable msge default)
print_option(${variable} "${default}")
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
set(${variable} "${default}" CACHE STRING ${msge} FORCE)
endif()
endmacro(option_with_default)"""
return s
def gen_setup(config, default_build_type, relative_path, setup_script_name):