Rewrite option wrappers using cmake_parse_arguments

This commit is contained in:
Roberto Di Remigio 2018-03-12 17:59:02 +01:00
parent dd806dadfd
commit e9eba12bdd
No known key found for this signature in database
GPG Key ID: E4FADFE6DFB29C6E
2 changed files with 86 additions and 26 deletions

View File

@ -47,38 +47,66 @@ def autogenerated_notice():
def gen_cmake_options_wrappers(): def gen_cmake_options_wrappers():
s = """\n# Options handling utilities s = """\n# Options handling utilities
include(CMakeParseArguments)
include(CMakeDependentOption) include(CMakeDependentOption)
# Macro for printing an option in a consistent manner # Macro for printing an option in a consistent manner
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard) # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: print_option(<option to print> <was specified>) # Syntax: print_option(NAME <option to print> DEFAULT <was specified>)
macro(print_option variable default) macro(print_option)
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "") set(options)
message(STATUS "Setting (unspecified) option ${variable}: ${default}") set(oneValueArgs NAME DEFAULT)
set(multiValueArgs)
cmake_parse_arguments(print_option
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
if(NOT DEFINED ${print_option_NAME} OR "${${print_option_VARIABLE}}" STREQUAL "")
message(STATUS "Setting (unspecified) option ${print_option_VARIABLE}: ${print_option_DEFAULT}")
else() else()
message(STATUS "Setting option ${variable}: ${${variable}}") message(STATUS "Setting option ${print_option_NAME}: ${print_option_DEFAULT}")
endif() endif()
endmacro() endmacro()
# Wraps an option with default ON/OFF. Adds nice messaging to option() # Wraps an option with default ON/OFF. Adds nice messaging to option()
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard) # Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard)
# Syntax: option_with_print(<option name> <description> <default value>) # Syntax: option_with_print(NAME <option name> MESSAGE <description> DEFAULT <default value>)
macro(option_with_print variable msge default) macro(option_with_print)
print_option(${variable} ${default}) set(options)
option(${variable} ${msge} ${default}) set(oneValueArgs NAME MESSAGE DEFAULT)
endmacro(option_with_print) set(multiValueArgs)
cmake_parse_arguments(option_with_print
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
print_option(${option_with_print_NAME} ${option_with_print_DEFAULT})
option(${option_with_print_NAME} ${option_with_print_MESSAGE} ${option_with_print_DEFAULT})
endmacro()
# 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
# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard) # 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 # 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 # they are the NULL string. This is also why we need the force
# Syntax: option_with_default(<option name> <description> <default value>) # Syntax: option_with_default(NAME <option name> MESSAGE <description> DEFAULT <default value>)
macro(option_with_default variable msge default) macro(option_with_default)
print_option(${variable} "${default}") set(options)
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "") set(oneValueArgs NAME MESSAGE DEFAULT)
set(${variable} "${default}" CACHE STRING ${msge} FORCE) set(multiValueArgs)
cmake_parse_arguments(option_with_default
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
print_option(${option_with_default_NAME} "${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)
endif() endif()
endmacro(option_with_default)""" endmacro()"""
return s return s
@ -198,7 +226,7 @@ def gen_cmakelists(project_name, project_language, min_cmake_version, default_bu
rel_cmake_module_path = os.path.join(relative_path, directory) rel_cmake_module_path = os.path.join(relative_path, directory)
# on windows cmake corrects this so we have to make it wrong again # on windows cmake corrects this so we have to make it wrong again
rel_cmake_module_path = rel_cmake_module_path.replace('\\', '/') rel_cmake_module_path = rel_cmake_module_path.replace('\\', '/')
s.append('set(CMAKE_MODULE_PATH ${{CMAKE_MODULE_PATH}} ${{PROJECT_SOURCE_DIR}}/{0})'.format(rel_cmake_module_path)) s.append('list(APPEND CMAKE_MODULE_PATH ${{PROJECT_SOURCE_DIR}}/{0})'.format(rel_cmake_module_path))
if len(modules) > 0: if len(modules) > 0:
s.append('\n# included cmake modules') s.append('\n# included cmake modules')

View File

@ -59,14 +59,46 @@
# - "'-DBLACS_IMPLEMENTATION=\"{0}\"'.format(arguments['--blacs'])" # - "'-DBLACS_IMPLEMENTATION=\"{0}\"'.format(arguments['--blacs'])"
# warning: "the math_libs.cmake module is deprecated and will be removed in future versions" # warning: "the math_libs.cmake module is deprecated and will be removed in future versions"
option_with_default(ENABLE_BLAS "Enable BLAS autodetection" "auto") option_with_default(
option_with_default(ENABLE_LAPACK "Enable LAPACK autodetection" "auto") NAME ENABLE_BLAS
option_with_default(MKL_FLAG "MKL flag for the Intel compiler and linker. Skips BLAS/LAPACK autodetection" "off") MESSAGE "Enable BLAS autodetection"
option_with_default(MATH_LIB_SEARCH_ORDER "Search order for autodetection of math libraries" "MKL;ESSL;OPENBLAS;ATLAS;ACML;SYSTEM_NATIVE") DEFAULT "auto"
option_with_default(BLAS_LANG "Linker language for BLAS detection" "Fortran") )
option_with_default(LAPACK_LANG "Linker language for LAPACK detection" "Fortran") option_with_default(
option_with_default(SCALAPACK_LIBRARIES "Link line for ScaLAPACK libraries" "") NAME ENABLE_LAPACK
option_with_default(BLACS_IMPLEMENTATION "Implementation of BLACS for MKL ScaLAPACK" "openmpi") MESSAGE "Enable LAPACK autodetection"
DEFAULT "auto"
)
option_with_default(
NAME MKL_FLAG
MESSAGE "MKL flag for the Intel compiler and linker. Skips BLAS/LAPACK autodetection"
DEFAULT "off"
)
option_with_default(
NAME MATH_LIB_SEARCH_ORDER
MESSAGE "Search order for autodetection of math libraries"
DEFAULT "MKL;ESSL;OPENBLAS;ATLAS;ACML;SYSTEM_NATIVE"
)
option_with_default(
NAME BLAS_LANG
MESSAGE "Linker language for BLAS detection"
DEFAULT "Fortran"
)
option_with_default(
NAME LAPACK_LANG
MESSAGE "Linker language for LAPACK detection"
DEFAULT "Fortran"
)
option_with_default(
NAME SCALAPACK_LIBRARIES
MESSAGE "Link line for ScaLAPACK libraries"
DEFAULT ""
)
option_with_default(
NAME BLACS_IMPLEMENTATION
MESSAGE "Implementation of BLACS for MKL ScaLAPACK"
DEFAULT "openmpi"
)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# ENABLE_STATIC_LINKING # ENABLE_STATIC_LINKING