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(): def gen_cmake_options_wrappers():
s = [] s = """\n# Macro for printing an option in a consistent manner
s.append('\n# Macro for printing an option in a consistent manner') # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
s.append('# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)') # Syntax: print_option(<option to print> <was specified>)
s.append('# Syntax: print_option(<option to print> <was specified>)') macro(print_option variable default)
s.append('macro(print_option variable default)') if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
s.append(' if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")') message(STATUS "Setting (unspecified) option ${variable}: ${default}")
s.append(' message(STATUS "Setting (unspecified) option ${variable}: ${default}")') else()
s.append(' else()') message(STATUS "Setting option ${variable}: ${${variable}}")
s.append(' message(STATUS "Setting option ${variable}: ${${variable}}")') endif()
s.append(' endif()') endmacro()
s.append('endmacro()')
s.append('\n# Wraps an option with default ON/OFF. Adds nice messaging to option()') # 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)') # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
s.append('# Syntax: option_with_print(<option name> <description> <default value>)') # Syntax: option_with_print(<option name> <description> <default value>)
s.append('macro(option_with_print variable msge default)') macro(option_with_print variable msge default)
s.append(' print_option(${variable} ${default})') print_option(${variable} ${default})
s.append(' option(${variable} ${msge} ${default})') option(${variable} ${msge} ${default})
s.append('endmacro(option_with_print)') endmacro(option_with_print)
s.append('\n# Wraps an option with a default other than ON/OFF and prints it') # 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)') # 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') # 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') # 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') # they are the NULL string. This is also why weneed the force
s.append('# Syntax: option_with_default(<option name> <description> <default value>)') # Syntax: option_with_default(<option name> <description> <default value>)
s.append('macro(option_with_default variable msge default)') macro(option_with_default variable msge default)
s.append(' print_option(${variable} "${default}")') print_option(${variable} "${default}")
s.append(' if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")') if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
s.append(' set(${variable} "${default}" CACHE STRING ${msge} FORCE)') set(${variable} "${default}" CACHE STRING ${msge} FORCE)
s.append(' endif()') endif()
s.append('endmacro(option_with_default)') endmacro(option_with_default)"""
return s
return '\n'.join(s)
def gen_setup(config, default_build_type, relative_path, setup_script_name): def gen_setup(config, default_build_type, relative_path, setup_script_name):