#
# @tp @b COMPILE @endtp
# Whether to compile module scripts if suitable, i.e., an intermediate
# format exists for the specific scripting language. For example,
# Python modules can be compiled. |
#
# @tp @b CONFIGURATION name @endtp
# Name of build configuration. |
#
#
# @tp @b COPYONLY @endtp
# Whether to only copy the script file without replacing CMake variables
# within the file. This option is passed on to CMake's configure_file()
# command used to configure the script file. By default, the option
# \@ONLY is used instead. |
#
#
# @tp @b EXECUTABLE @endtp
# Specifies that the given script file is an executable script and not a
# module script. Otherwise, if this option is not given and the output
# file name contains a file name extension, the given script file is
# configured as module script. A script file with an output file name
# that has no extension, is always considered to be an executable. |
#
#
# @tp @b DIRECTORY dir @endtp
# Build tree directory of configured script. By default, the directory
# of the output script file is used to set the @c __DIR__ variable
# used to make absolute file paths relative to the configured build
# tree script file in the script configuration file
# (see basis_set_script_path()).
# |
#
# @tp @b DESTINATION dir @endtp
# Installation directory for configured script. If this option is given,
# the @c BUILD_INSTALL_SCRIPT variable is set to @c TRUE before including
# any specified script configuration files (see @p CONFIG_FILE option).
# Moreover, the @c __DIR__ variable is set to the specified directory.
# Otherwise, if this option is omitted, the @c BUILD_INSTALL_SCRIPT variable
# is set to @c FALSE instead and @c __DIR__ is set to the directory of
# the configured @p OUTPUT file. Note that the @c BUILD_INSTALL_SCRIPT and
# @c __DIR__ variables are in particular used by basis_set_script_path()
# to convert the given paths to paths relative to the location of the
# configured/installed script. |
#
#
# @tp @b CACHE_FILE file1 [file2...] @endtp
# List of CMake files with dump of variables which should be included
# before configuring the script. The cache files can be generated using
# the basis_dump_variables() function. |
#
#
# @tp @b CONFIG_FILE file1 [file2...] @endtp
# List of script configuration files to include before the configuration
# of the script. See also the documentation of the @p DESTINATION option. |
#
#
# @tp @b LINK_DEPENDS dep1 [dep2...] @endtp
# List of "link" dependencies, i.e., modules and script/module libraries
# required by this script. For executable scripts, the paths to these
# modules/packages is added to the module search path. If the prefix
# "relative " is given before a file path, it is made relative to the
# output/installation directory of the script file. All given input paths
# must be absolute, however, as the relative location depends on
# whether the script will be installed, i.e., the @c DESTINATION
# is specified, or not. |
#
#
function (basis_configure_script INPUT OUTPUT)
# rename arguments to avoid conflict with script configuration
set (_INPUT_FILE "${INPUT}")
set (_OUTPUT_FILE "${OUTPUT}")
# --------------------------------------------------------------------------
# parse arguments
CMAKE_PARSE_ARGUMENTS (
ARGN
"COMPILE;COPYONLY;EXECUTABLE"
"DIRECTORY;DESTINATION;LANGUAGE;CONFIGURATION"
"CACHE_FILE;CONFIG_FILE;LINK_DEPENDS"
${ARGN}
)
if (ARGN_UNPARSED_ARGUMENTS)
message (FATAL_ERROR "Unrecognized arguments given: ${ARGN_UNPARSED_ARGUMENTS}")
endif ()
if (NOT ARGN_LANGUAGE)
basis_get_source_language (ARGN_LANGUAGE "${_INPUT_FILE}")
endif ()
# --------------------------------------------------------------------------
# include cache files
foreach (_F IN LISTS ARGN_CACHE_FILE)
get_filename_component (_F "${_F}" ABSOLUTE)
if (NOT EXISTS "${_F}")
message (FATAL_ERROR "Cache file ${_F} does not exist!")
endif ()
include ("${_F}")
endforeach ()
# --------------------------------------------------------------------------
# general variables for use in scripts and those intended for use in script
# configurations. The __DIR__ is in particular used by basis_set_script_path()
# to make absolute paths relative to the script file location
if (ARGN_DESTINATION)
if (NOT IS_ABSOLUTE "${ARGN_DESTINATION}")
set (ARGN_DESTINATION "${CMAKE_INSTALL_PREFIX}/${ARGN_DESTINATION}")
endif ()
set (BUILD_INSTALL_SCRIPT TRUE)
set (__DIR__ "${ARGN_DESTINATION}")
else ()
set (BUILD_INSTALL_SCRIPT FALSE)
if (ARGN_DIRECTORY)
if (NOT IS_ABSOLUTE "${ARGN_DIRECTORY}")
message (FATAL_ERROR "Build tree script DIRECTORY must be an absolute path")
endif ()
set (__DIR__ "${ARGN_DIRECTORY}")
string (REPLACE "$<${BASIS_GE_CONFIG}>" "${ARGN_CONFIGURATION}" __DIR__ "${__DIR__}")
else ()
get_filename_component (__DIR__ "${_OUTPUT_FILE}" PATH)
endif ()
endif ()
get_filename_component (__NAME__ "${_OUTPUT_FILE}" NAME)
set (__FILE__ "${__DIR__}/${__NAME__}")
set (__CONFIG__ "${ARGN_CONFIGURATION}")
# --------------------------------------------------------------------------
# replace $