Mercurial > code
changeset 625:dccaf66c8b9f
CMake: get rid of DefineOption
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 23 Oct 2017 15:21:54 +0200 |
parents | 01e01777ff50 |
children | 64884a4de16a |
files | cmake/functions/DefineOption.cmake |
diffstat | 1 files changed, 0 insertions(+), 180 deletions(-) [+] |
line wrap: on
line diff
--- a/cmake/functions/DefineOption.cmake Fri Oct 20 14:18:37 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,180 +0,0 @@ -# -# DefineOption.cmake -- evolved option definition -# -# Copyright (c) 2016-2017 David Demelier <markand@malikania.fr> -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -# -# define_option -# ------------------------------------------------------------------- -# -# Define an option. -# -# The option may have different types, it can be STRING, PATH, BOOL and FEATURE, -# it will create cache variables using set() or option depending on the type. -# -# General invocation takes the following arguments: -# -# define_option( -# NAME variable name -# TYPE BOOL | FEATURE | PATH | STRING -# DOC (Optional) option description -# DEFAULT (Optional) default value -# ) -# -# Some types can takes more arguments, see below the following sections. -# -# ## String and paths -# -# If type is set to PATH, an additional ${NAME}_ABS variable is defined as the -# absolute directory to CMAKE_INSTALL_PREFIX if the value is relative. -# -# Example: -# -# if an option WITH_DOCDIR is of type PATH and set to "share/doc", the variable -# WITH_DOCDIR_ABS will be set to CMAKE_INSTALL_PREFIX/share/doc. -# -# ## Booleans -# -# If type is set to BOOL, an additional variable ${NAME}_MSG is set to "Yes" or -# to "No" depending if the option value is set. -# -# If no default value is given, it is set to On. -# -# Example: -# -# If an option WITH_FOO is of type BOOL and set to On, WITH_FOO_MSG will be set -# to "Yes". -# -# ## Features -# -# The FEATURE type is a superset of BOOL. It is designed to check if an option -# is enabled and able to build. For example, the user requests the feature -# 'abc' but can't be enabled because the system lacks missing tools. -# -# If no default value is given, it is set ${CONDITION}. -# -# The command may take the new following extra arguments: -# -# - CONDITION The condition to enable the feature, -# - CONDITION_MESSAGE (Optional: default "${OPT_NAME} not found") the reason -# to set if the condition is not matched, -# - DISABLED_MESSAGE (Optional: default: "${OPT_NAME} disabled by user") the -# reason when the option has been disabled by the user. -# -# This command create the same variables as BOOL type. It adds also -# ${NAME}_ENABLED variable which is set to On if both ${CONDITION} and ${NAME} -# are set to On. -# -# Example: -# -# find_package(OpenSSL) -# -# define_option( -# NAME SSL -# TYPE FEATURE -# CONDITION ${OPENSSL_FOUND} -# CONDITION_MESSAGE "OpenSSL not found" -# DISABLED_MESSAGE "OpenSSL disabled by user" -# ) -# -# By default, if OpenSSL is not found and SSL kept to On, SSL_ENABLED will be -# set to Off and SSL_MSG will be set to "OpenSSL not found". -# -# If SSL is set to Off, SSL_ENABLED will be set to Off and SSL_MSG set to -# "OpenSSL disabled by user". -# - -include(CMakeParseArguments) - -macro (define_option) - set(args CONDITION CONDITION_MESSAGE DEFAULT DOC NAME TYPE) - - cmake_parse_arguments(OPT "" "${args}" "" ${ARGN}) - - if (NOT DEFINED OPT_NAME) - message(FATAL_ERROR "Missing NAME argument") - endif () - if (NOT DEFINED OPT_DOC) - set(OPT_DOC "Option ${OPT_NAME}") - endif () - - if (${OPT_TYPE} MATCHES BOOL) - if (DEFINED OPT_DEFAULT) - option(${OPT_NAME} ${OPT_DOC} ${OPT_DEFAULT}) - else () - option(${OPT_NAME} ${OPT_DOC} On) - endif () - - if (${OPT_NAME}) - set(${OPT_NAME}_MSG "Yes") - else () - set(${OPT_NAME}_MSG "No") - endif () - elseif (${OPT_TYPE} MATCHES FEATURE) - if (NOT DEFINED OPT_CONDITION) - message(FATAL_ERROR "Missing CONDITION argument for FEATURE type") - endif () - if (NOT DEFINED OPT_CONDITION_MESSAGE) - set(OPT_CONDITION_MESSAGE "${OPT_NAME} not found") - endif () - if (NOT DEFINED OPT_DISABLED_MESSAGE) - set(OPT_DISABLED_MESSAGE "${OPT_NAME} disabled by user") - endif () - - if (DEFINED OPT_DEFAULT) - option(${OPT_NAME} ${OPT_DOC} ${OPT_DEFAULT}) - else () - option(${OPT_NAME} ${OPT_DOC} ${OPT_CONDITION}) - endif () - - if (NOT ${OPT_CONDITION}) - set(${OPT_NAME}_ENABLED Off) - set(${OPT_NAME}_MSG ${OPT_CONDITION_MESSAGE}) - elseif (NOT ${OPT_NAME}) - set(${OPT_NAME}_ENABLED Off) - set(${OPT_NAME}_MSG ${OPT_DISABLED_MESSAGE}) - else () - set(${OPT_NAME}_ENABLED On) - set(${OPT_NAME}_MSG "Yes") - endif () - - unset(OPT_CONDITION) - unset(OPT_CONDITION_MESSAGE) - unset(OPT_DISABLED_MESSAGE) - elseif (${OPT_TYPE} MATCHES STRING OR ${OPT_TYPE} MATCHES PATH) - # Force usage of string because FILEPATH, PATH always use absolute paths. - if (OPT_DEFAULT) - set(${OPT_NAME} ${OPT_DEFAULT} CACHE STRING ${OPT_DOC}) - else () - set(${OPT_NAME} "" CACHE STRING ${OPT_DOC}) - endif () - - if (${OPT_TYPE} MATCHES PATH) - if (IS_ABSOLUTE "${${OPT_NAME}}") - set(${OPT_NAME}_ABS ${${OPT_NAME}}) - else () - set(${OPT_NAME}_ABS ${CMAKE_INSTALL_PREFIX}/${${OPT_NAME}}) - endif () - endif () - else () - message(FATAL_ERROR "Invalid ${OPT_TYPE} type given") - endif () - - unset(OPT_DEFAULT) - unset(OPT_DOC) - unset(OPT_NAME) - unset(OPT_TYPE) -endmacro ()