Merge pull request #245 from robertodr/fix-option-wrappers

Do not use CMakeParseArguments for wrappers
This commit is contained in:
Radovan Bast 2018-04-24 09:46:05 +02:00 committed by GitHub
commit ebf3264642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,70 +47,36 @@ def autogenerated_notice():
def gen_cmake_options_wrappers():
s = """\n# Options handling utilities
include(CMakeParseArguments)
include(CMakeDependentOption)
# Macro for printing an option in a consistent manner
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: print_option(NAME <option to print> DEFAULT <was specified>)
macro(print_option)
set(options)
set(oneValueArgs NAME DEFAULT)
set(multiValueArgs)
cmake_parse_arguments(print_option
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
if(NOT DEFINED ${print_option_NAME} OR "${${print_option_NAME}}" STREQUAL "")
message(STATUS "Setting (unspecified) option ${print_option_NAME}: ${print_option_DEFAULT}")
# 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 ${print_option_NAME}: ${print_option_DEFAULT}")
message(STATUS "Setting option ${variable}: ${${variable}}")
endif()
endmacro()
# 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(NAME <option name> MESSAGE <description> DEFAULT <default value>)
macro(option_with_print)
set(options)
set(oneValueArgs NAME MESSAGE DEFAULT)
set(multiValueArgs)
cmake_parse_arguments(option_with_print
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
print_option(
NAME ${option_with_print_NAME}
DEFAULT ${option_with_print_DEFAULT}
)
option(${option_with_print_NAME} ${option_with_print_MESSAGE} ${option_with_print_DEFAULT})
# 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()
# 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
# 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 we need the force
# Syntax: option_with_default(NAME <option name> MESSAGE <description> DEFAULT <default value>)
macro(option_with_default)
set(options)
set(oneValueArgs NAME MESSAGE DEFAULT)
set(multiValueArgs)
cmake_parse_arguments(option_with_default
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
print_option(
NAME ${option_with_default_NAME}
DEFAULT "${option_with_default_DEFAULT}"
)
if(NOT DEFINED ${option_with_default_NAME} OR "${${option_with_default_NAME}}" STREQUAL "")
set(${option_with_default_NAME} "${option_with_default_DEFAULT}" CACHE STRING ${option_with_default_MESSAGE} 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()"""
return s