CetCMakeUtilities

Cetbuildtools2 utility functions and macros.

set_ifnot
set_ifnot(<varname> <value>)

Macro that sets the value of the variable <varname> to the given <value> if <varname> evaluates to FALSE. For example,

set(MYVARIABLE ) # empty variable
set_ifnot(MYVARIABLE "newvalue")
message(STATUS "MYVARIABLE = ${MYVARIABLE}") # Prints "MYVARIABLE = newvalue"
enum_option
enum_option(<option>
            VALUES   <value1> ... <valueN>
            TYPE     <valuetype>
            DOC      <docstring>
            [DEFAULT <value>]
            [CASE_INSENSITIVE])

Function Declaring a cache variable <option> that can only take values in the VALUES list. If the <option> variable is set to a value other than one of these values, a fatal error is emitted.

TYPE may be set to “FILEPATH”, “PATH” or “STRING”.

<docstring> should describe the option, and will appear in the interactive CMake interfaces.

If DEFAULT is provided, its <value> argument will be used as the the value to which <option> should default to if not yet set. Otherwise, the first entry in VALUES is used as the default. Obviously, <value> must occur in the VALUES list.

If CASE_INSENSITIVE is supplied, then checks of the value of <option> against the allowed values will ignore the case when performing string comparison. All values are converted to lowercase.

For example,

enum_option(CXX_STANDARD
            VALUES    "c++11" "c++14" "c++17"
            TYPE      STRING
            DOCSTRING "Choose the C++ Standard"
            DEFAULT   "c++14"
            )

Would create a cache variable named CXX_STANDARD with a default value of “c++14” that could be set to “c++11”, “c++14” or “c++17”. With CASE_INSENSITIVE

enum_option(CXX_STANDARD
            VALUES    "c++11" "c++14" "c++17"
            TYPE      STRING
            DOCSTRING "Choose the C++ Standard"
            DEFAULT   "c++14"
            CASE_INSENSITIVE
            )

the behaviour and values that CXX_STANDARD can take are identical, but the user could set the value as “C++11”, “C++14” or “C++17” in addition the lowercase equivalents. This is intended to provide a little more freedom to the user whilst maintaining a clear internal set of values.

set_boost_unit_properties
set_boost_unit_properties(<target>)

Function to apply compile definitions, include directories and link libraries to build target <target> as a Boost.Unit test. If <target> is not a valid CMake target (executable or library), a FATAL_ERROR is raised.

The target properties are appended with:

  • COMPILE_DEFINITIONS: -DBOOST_TEST_DYN_LINK for libraries and executables, with the latter also having -DBOOST_TEST_MAIN appended.
  • INCLUDE_DIRECTORIES: value of Boost_INCLUDE_DIRS
  • LINK_LIBRARIES: value of Boost_UNIT_TEST_FRAMEWORK_LIBRARY

These settings assume that Boost has been located using CMake’s builtin FindBoost module before being called. If the CMake variable Boost_FOUND is not set or no Boost Unit Test Framework library is supplied via the Boost::unit_test_framework imported target or Boost_UNIT_TEST_FRAMEWORK_LIBRARY variable, the function raises a FATAL_ERROR. At present, no checking of Release vs Debug Boost libraries is performed. All properties are marked as PUBLIC usage requirements.

set_tbb_offload_properties
set_tbb_offload_properties(<target>)

Function to apply properties needed to compile target <target> with support for TBB offloads.

Currently unimplemented (see below) but will not emit a warning about its usage.

Todo

Needs find_tbb_offloads command which doesn’t appear to exist anywhere yet. Assumed that this scans source files for usage of offload specific calls, returning true if so. The needed compile flag is then added…