Rewrite option wrappers using cmake_parse_arguments
This commit is contained in:
parent
dd806dadfd
commit
e9eba12bdd
@ -47,38 +47,66 @@ 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(<option to print> <was specified>)
|
||||
macro(print_option variable default)
|
||||
if(NOT DEFINED ${variable} OR "${${variable}}" STREQUAL "")
|
||||
message(STATUS "Setting (unspecified) option ${variable}: ${default}")
|
||||
# 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_VARIABLE}}" STREQUAL "")
|
||||
message(STATUS "Setting (unspecified) option ${print_option_VARIABLE}: ${print_option_DEFAULT}")
|
||||
else()
|
||||
message(STATUS "Setting option ${variable}: ${${variable}}")
|
||||
message(STATUS "Setting option ${print_option_NAME}: ${print_option_DEFAULT}")
|
||||
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(<option name> <description> <default value>)
|
||||
macro(option_with_print variable msge default)
|
||||
print_option(${variable} ${default})
|
||||
option(${variable} ${msge} ${default})
|
||||
endmacro(option_with_print)
|
||||
# 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(${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
|
||||
# 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)
|
||||
# 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(${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()
|
||||
endmacro(option_with_default)"""
|
||||
endmacro()"""
|
||||
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)
|
||||
# on windows cmake corrects this so we have to make it wrong again
|
||||
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:
|
||||
s.append('\n# included cmake modules')
|
||||
|
@ -59,14 +59,46 @@
|
||||
# - "'-DBLACS_IMPLEMENTATION=\"{0}\"'.format(arguments['--blacs'])"
|
||||
# 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(ENABLE_LAPACK "Enable LAPACK autodetection" "auto")
|
||||
option_with_default(MKL_FLAG "MKL flag for the Intel compiler and linker. Skips BLAS/LAPACK autodetection" "off")
|
||||
option_with_default(MATH_LIB_SEARCH_ORDER "Search order for autodetection of math libraries" "MKL;ESSL;OPENBLAS;ATLAS;ACML;SYSTEM_NATIVE")
|
||||
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(SCALAPACK_LIBRARIES "Link line for ScaLAPACK libraries" "")
|
||||
option_with_default(BLACS_IMPLEMENTATION "Implementation of BLACS for MKL ScaLAPACK" "openmpi")
|
||||
option_with_default(
|
||||
NAME ENABLE_BLAS
|
||||
MESSAGE "Enable BLAS autodetection"
|
||||
DEFAULT "auto"
|
||||
)
|
||||
option_with_default(
|
||||
NAME ENABLE_LAPACK
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user