CetCMakeUtils

General functions and macros.

cet_passthrough

Turn a flag or option value into something that can be passed on to another function or macro.

cet_passthrough([FLAG] [KEYWORD <keyword>]
                [EMPTY_KEYWORD <empty-keyword>] <in_var>
                IN_PLACE|<out-var>)

cet_passthrough([FLAG] VALUES [<val>...]
                KEYWORD <keyword>
                [EMPTY_KEYWORD <empty-keyword>] <out-var>)

Options

EMPTY_KEYWORD <empty-keyword>

If <in-var> or VALUES evaluates to the empty string, the result is <empty-keyword>

FLAG

If <in-var> or VALUES evaluates to TRUE, the result is <keyword> (or see KEYWORD, below). Otherwise the result will be the empty string (or see EMPTY_KEYWORD, above).

IN_PLACE

If <in-var> is specified this option signifies that the result will be placed in <in-var>. In this case <out-var> must then not be present.

KEYWORD <keyword>

If specified, the option keyword will be <keyword>. Otherwise, if <in-var> is specified, then it will be the name “<in-var>” with any leading <prefix>_ stripped off the front. Failing that, the name “<out-var>” will be used as the default.

VALUES <val>...

The values to be passed through to another function or macro may be specified as <val>... rather than as <in-var>. In this case, <out-var> is required and IN_PLACE is not permitted.

Non-option arguments

<in-var>

The name of a variable holding the values to be passed through. <in-var> must not be present if VALUES is specified.

<out-var>

The name of a variable to hold the values in passthrough form. If IN_PLACE and <in-var> are both specified, than <out-var> must not be present.

Examples

  • set(MYOPTS_VERBOSE TRUE)
    cet_passthrough(FLAG IN_PLACE MYOPTS_VERBOSE)
    

    MYOPTS_VERBOSE will have the value “VERBOSE” in the calling function or macro.

  • cet_passthrough(FLAG VALUES "NOTFOUND" USE_MYPACKAGE)
    

    USE_MYPACKAGE will be empty in the calling function or macro.

  • cet_passthrough(FLAG VALUES "MYTEXT" USE_MYPACKAGE)
    

    USE_MYPACKAGE will have the value USE_MYPACKAGE in the calling function or macro.

  • cet_passthrough(IN_PLACE VALUES
      "Mary had a little lamb; Its fleece was white as snow"
      KEYWORD RHYME MARY_LAMB)
    

    The list MARY_LAMB will consist of the three elements:

    "RHYME" "Mary had a little lamb" "Its fleece was white as snow"
    

    in the calling function or macro. Note the lack of whitespace at the beginning of the third element of the list.

  • cet_passthrough(VALUES
      "Mary had a little lamb\\\\; Its fleece was white as snow"
      KEYWORD RHYME MARY_LAMB)
    

    The list MARY_LAMB will consist of the two elements:

    "RHYME" "Mary had a little lamb; Its fleece was white as snow"
    

    in the calling function or macro.

cet_source_file_extensions

Produce an ordered list of source file extensions for enabled languages.

cet_source_file_extensions(<out-var>)

Non-option arguments

<out-var>

Variable to contain the resulting ordered list of extensions.

Notes

Note

Prescribed order of enabled languages: CUDA, CXX C, Fortran, <lang>..., ASM.

cet_exclude_files_from

Remove duplicates and other files from a list, explicitly or by regular expression.

cet_exclude_files_from(<sources-var> [REGEX <regex>...] [NOP] <file>...)

Options

NOP

Optional separator between a list option and non-option arguments; no other effect.

REGEX

Entries in <sources-var> matching <regex>... will be removed.

Non-option arguments

<sources-var>

The name of a variable containing a list of files to be pruned.

<file>...

Files to be removed from <sources-var> (exact matches only).

Notes

Note

Relative paths are interpreted with respect to the value of CMAKE_CURRENT_SOURCE_DIR.

cet_timestamp

Generate a current timestamp.

cet_timestamp(<out-var> [SYSTEM_DATE_CMD] [<fmt>])

Options

SYSTEM_DATE_CMD

Use the system date(1) command even if <fmt> is understood by string(TIMESTAMP)

Non-option arguments

<out-var>

Variable in which to store the formatted timestamp.

<fmt>

The desired format of the timestamp, using % placeholders understood by string(TIMESTAMP) or the system date(1) command.

Examples

  • cet_timestamp(RESULT)
    message(STATUS "${RESULT}")
    
    -- Sun Jan 01 23:59:59 CST 1970
    
  • cet_timestamp(RESULT "%Y-%m-%d %H:%M:%S %z")
    message(STATUS "${RESULT}")
    
    -- 1970-01-01 23:59:59 -0600
    

Notes

Changed in version 2.07.00: %Y was missing from the default format in earlier versions.

Changed in version 3.08.00: added SYSTEM_DATE_CMD.

cet_find_simple_package

find_package() for packages without generated CMake config files or a Find<name>.cmake module.

Deprecated since version 2.0: if no FindXXX.cmake module or CMake config file is available for <name>, write your own find module or request one from the SciSoft team.

find_simple_package([HEADERS <header>...]
  [INCPATH_SUFFIXES <dir>...] [INCPATH_VAR <var>]
  [LIB_VAR <var>] [LIBNAMES <libname>...]
  [LIBPATH_SUFFIXES <dir>...]
  <name>)

Options

HEADERS <header>...

Look for <header>... to ascertain the include path. If not specified, use <name>.{h,hh,H,hxx,hpp}

INCPATH_SUFFIXES <dir>...

Add <suffix>... to paths when searching for headers (defaults to “include”).

INCPATH_VAR <var>

Store the found include path in <var>. If not specified, we invoke include_directories() with the found include path.

LIB_VAR <var>

Store the found library as <var>. If not specified, use <name> as converted to an upper case identifier.

LIBNAMES <libname>...

Look for <libname>... as a library in addition to name.

LIBPATH_SUFFIXES <dir>...

Add <dir>... to paths when searching for libraries.

Non-option arguments

<name>

The primary name of the library (without prefix or suffix) or headers to be found.

cet_localize_pv

Ensure that specified path-type project variables are absolute in the current directory scope for in-tree project <project>.

cet_localize_pv(<project> [<project-var-name>])
cet_localize_pv(<project> ALL)

Non-option arguments

<project>

The name of a CMake project in the current source tree.

<project-var-name>

The name of a project variable (without a <project>_ prefix).

cet_localize_pv_all

Equivalent to cet_localize_pv(<project> ALL).

cet_localize_pv_all(<project>)
cet_cmake_module_directories

Make the specified CMake module-containing directories available in the current directory scope via CMAKE_MODULE_PATH and to client packages via find_package().

cet_cmake_module_directories([NO_CONFIG] [NO_LOCAL] [PROJECT <project>] <dir>...)

Options

BINARY

Also add the corresponding directories in the project build tree to CMAKE_MODULE_PATH in the current scope.

See also

NO_LOCAL

NO_CONFIG

Do not add these directories to CMAKE_MODULE_PATH in the CMake config file for <project>.

NO_LOCAL

Do not add these directories to CMAKE_MODULE_PATH in the current scope. Implied if <project> is not equal to the value of CETMODULES_CURRENT_PROJECT_NAME

PROJECT <project>

Specify the project to which these module directories belong. If not specifed, <project> defaults to CETMODULES_CURRENT_PROJECT_NAME.

Non-option arguments

<dir>...

Directories containing CMake modules.

cet_export_alias

Define and export aliases of the specified targets into the specified or default export set.

Deprecated since version 3.15: in favor of cet_make_alias(), which

is more flexible, more robust against user error and makes fewer assumptions.

cet_export_alias([<options>] [ALIAS] <target>...)
ALIAS <target>...

Optional keyword specifying targets to be aliased. If non-option arguments are also specified, they will be appended to the list specified here.

ALIAS_NAMESPACE <namespace>

Targets specified without a namespace (via ::) will be taken from <namespace>.

EXPORT_SET <export-set>

Aliased targets will be exported into <export-set>, which will be created if necessary with cet_register_export_set() and an appropriate default namespace based on <export-set>. If you require a different namespace than the default, call cet_register_export_set() yourself prior to calling cet_export_alias().

NOP

Optional separator between a list option and non-option arguments; no other effect.

Non-option arguments

<target>...

Targets to be aliased.

See also

ALIAS

Notes

Note

If no <export-set> is specified, the default export set will be used.

cet_make_alias

Define an alias and optionally export it.

cet_make_alias(TARGET <target> [<options>] [<target-export-set>])
EXPORT_SET <export-set>

Aliased targets will be exported into <export-set>, which will be created if necessary with cet_register_export_set() and an appropriate default namespace based on <export-set>. If you require a different namespace than the default, call cet_register_export_set() yourself prior to calling cet_export_alias(). If no <export-set> is specified, the default export set will be used.

NAME <name>

Specify the alias as <name>. If <name> is namespaced, then it will not be exported, and the presence of EXPORT_SET is an error. Without NAME the alias will have the same root name as <target>.

NOP

Optional separator between a list option and non-option arguments; no other effect.

TARGET <target>

Target to be aliased.

TARGET_EXPORT_SET <target-export-set>

If the primary target (after resolving all aliases) represented by <target> may be found in multiple export sets, specify the correct one here.

Notes

cet_real_path

Convert provided paths to a PATH-like string or CMake list of real paths via file(REAL_PATH).

cet_real_path(<out-var> [LIST] <path>...)

Options

LIST

Results will be returned in <out-var> as a “;”-separated CMake list rather than the default “:”-separated PATH-like string.

Non-option arguments

<out-var>

Variable to hold the results.

<path>

Input paths for conversion.

cet_filter_subdirs

Filter paths based on their roots.

cet_filter_subdirs([EXCLUDE <subdir>...] [INCLUDE <subdir>...] <path>...)

Options

(EXCLUDE|INCLUDE) <root>...

Exclude or select <path> based on whether it is a subdirectory of <root> after accounting for symbolic links.

Non-option arguments

<path>...

Candidate paths to be filtered.