| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
# Macro that configures the package's main config.h file |
| 13 |
# |
| 14 |
function(tribits_add_config_define DEFINE) |
| 15 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 16 |
message("-- " "Package ${PARENT_PACKAGE_NAME}: adding compiler" |
| 17 |
" define to config file: ${DEFINE}") |
| 18 |
endif() |
| 19 |
global_set(${PARENT_PACKAGE_NAME}_CONFIG_DEFINES |
| 20 |
"${${PARENT_PACKAGE_NAME}_CONFIG_DEFINES}\n#define ${DEFINE}") |
| 21 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 22 |
message("-- ${${PARENT_PACKAGE_NAME}_CONFIG_DEFINES}") |
| 23 |
endif() |
| 24 |
endfunction() |
| 25 |
|
| 26 |
|
| 27 |
# @FUNCTION: tribits_configure_file() |
| 28 |
# |
| 29 |
# Macro that configures the package's main configured header file (typically |
| 30 |
# called ``${PACKAGE_NAME}_config.h`` but any name can be used). |
| 31 |
# |
| 32 |
# Usage:: |
| 33 |
# |
| 34 |
# tribits_configure_file(<packageConfigFile>) |
| 35 |
# |
| 36 |
# This function requires the file:: |
| 37 |
# |
| 38 |
# ${PACKAGE_SOURCE_DIR}/cmake/<packageConfigFile>.in |
| 39 |
# |
| 40 |
# exists and it creates the file:: |
| 41 |
# |
| 42 |
# ${CMAKE_CURRENT_BINARY_DIR}/<packageConfigFile> |
| 43 |
# |
| 44 |
# by calling the built-in ``configure_file()`` command:: |
| 45 |
# |
| 46 |
# configure_file( |
| 47 |
# ${PACKAGE_SOURCE_DIR}/cmake/<packageConfigFile>.in |
| 48 |
# ${CMAKE_CURRENT_BINARY_DIR}/<packageConfigFile> |
| 49 |
# ) |
| 50 |
# |
| 51 |
# which does basic substitution of CMake variables (see documentation for |
| 52 |
# built-in CMake `configure_file()`_ command for rules on how it performs |
| 53 |
# substitutions). This command is typically used to configure the package's |
| 54 |
# main `<packageDir>/cmake/<packageName>_config.h.in`_ file. |
| 55 |
# |
| 56 |
# In addition to just calling ``configure_file()``, this function also aids in |
| 57 |
# creating configured header files adding macros for deprecating code as |
| 58 |
# described below. |
| 59 |
# |
| 60 |
# **Deprecated Code Macros** |
| 61 |
# |
| 62 |
# If ``${PARENT_PACKAGE_NAME}_SHOW_DEPRECATED_WARNINGS`` is ``TRUE`` (see |
| 63 |
# `tribits_add_show_deprecated_warnings_option()`_), then the local CMake |
| 64 |
# variable ``${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS`` is set which |
| 65 |
# adds a define ``<PARENT_PACKAGE_NAME_UC>_DEPRECATED`` (where |
| 66 |
# ``<PARENT_PACKAGE_NAME_UC>`` is the package name in all upper-case letters) |
| 67 |
# which adds a compiler-specific deprecated warning for an entity. To take |
| 68 |
# advantage of this, just add the line:: |
| 69 |
# |
| 70 |
# @<PARENT_PACKAGE_NAME_UC>_DEPRECATED_DECLARATIONS@ |
| 71 |
# |
| 72 |
# to the ``<packageConfigFile>.in`` file and it will be expanded at configure |
| 73 |
# time. |
| 74 |
# |
| 75 |
# Then C/C++ code can use this macro to deprecate functions, variables, |
| 76 |
# classes, etc., for example, using:: |
| 77 |
# |
| 78 |
# <PARENT_PACKAGE_NAME_UC>_DEPRECATED class SomeDepreatedClass { ... }. |
| 79 |
# |
| 80 |
# If the particular compiler does not support deprecated warnings, then this |
| 81 |
# macro is defined to be empty. See `Regulated Backward Compatibility and |
| 82 |
# Deprecated Code`_ for more details. |
| 83 |
# |
| 84 |
function(tribits_configure_file PACKAGE_NAME_CONFIG_FILE) |
| 85 |
|
| 86 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 87 |
message("\nPACKAGE_CONFIGURE_FILE: ${PACKAGE_NAME_CONFIG_FILE}") |
| 88 |
endif() |
| 89 |
|
| 90 |
# Set up the deprecated attribute if showing deprecated warnings |
| 91 |
if (${PARENT_PACKAGE_NAME}_SHOW_DEPRECATED_WARNINGS) |
| 92 |
multiline_set(${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS |
| 93 |
"#ifndef ${PARENT_PACKAGE_NAME_UC}_DEPRECATED\n" |
| 94 |
"# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))\n" |
| 95 |
"# define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED __attribute__((__deprecated__))\n" |
| 96 |
"# else\n" |
| 97 |
"# define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED\n" |
| 98 |
"# endif\n" |
| 99 |
"#endif\n" |
| 100 |
"\n" |
| 101 |
"#ifndef ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_MSG\n" |
| 102 |
"# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))\n" |
| 103 |
"# define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_MSG(MSG) __attribute__((__deprecated__ (#MSG) ))\n" |
| 104 |
"# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))\n" |
| 105 |
"# define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_MSG(MSG) __attribute__((__deprecated__))\n" |
| 106 |
"# else\n" |
| 107 |
"# define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_MSG(MSG)\n" |
| 108 |
"# endif\n" |
| 109 |
"#endif\n" |
| 110 |
) |
| 111 |
else() |
| 112 |
multiline_set(${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS |
| 113 |
"#define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED\n" |
| 114 |
"#define ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_MSG(MSG)\n" |
| 115 |
) |
| 116 |
endif() |
| 117 |
|
| 118 |
if (${PARENT_PACKAGE_NAME}_HIDE_DEPRECATED_CODE) |
| 119 |
string(APPEND ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS |
| 120 |
"\n#define ${PARENT_PACKAGE_NAME_UC}_HIDE_DEPRECATED_CODE") |
| 121 |
endif() |
| 122 |
|
| 123 |
# Set up the macro to create the define for time monitor |
| 124 |
set(TIME_MONITOR_DEFINE_NAME ${PARENT_PACKAGE_NAME_UC}_TEUCHOS_TIME_MONITOR) |
| 125 |
set(FUNC_TIME_MONITOR_MACRO_NAME ${PARENT_PACKAGE_NAME_UC}_FUNC_TIME_MONITOR) |
| 126 |
set(FUNC_TIME_MONITOR_DIFF_MACRO_NAME ${PARENT_PACKAGE_NAME_UC}_FUNC_TIME_MONITOR_DIFF) |
| 127 |
if (${PARENT_PACKAGE_NAME}_ENABLE_TEUCHOS_TIME_MONITOR) |
| 128 |
multiline_set(${PARENT_PACKAGE_NAME_UC}_TEUCHOS_TIME_MONITOR_DECLARATIONS |
| 129 |
"#ifndef ${FUNC_TIME_MONITOR_MACRO_NAME}\n" |
| 130 |
"# define ${TIME_MONITOR_DEFINE_NAME}\n" |
| 131 |
"# define ${FUNC_TIME_MONITOR_MACRO_NAME}(FUNCNAME) \\\n" |
| 132 |
" TEUCHOS_FUNC_TIME_MONITOR_DIFF(FUNCNAME, ${PARENT_PACKAGE_NAME_UC})\n" |
| 133 |
"# define ${FUNC_TIME_MONITOR_DIFF_MACRO_NAME}(FUNCNAME, DIFF) \\\n" |
| 134 |
" TEUCHOS_FUNC_TIME_MONITOR_DIFF(FUNCNAME, DIFF)\n" |
| 135 |
"#endif\n" |
| 136 |
) |
| 137 |
else() |
| 138 |
multiline_set(${PARENT_PACKAGE_NAME_UC}_TEUCHOS_TIME_MONITOR_DECLARATIONS |
| 139 |
"#define ${FUNC_TIME_MONITOR_MACRO_NAME}(FUNCNAME)\n" |
| 140 |
"#define ${FUNC_TIME_MONITOR_DIFF_MACRO_NAME}(FUNCNAME, DIFF)\n" |
| 141 |
) |
| 142 |
endif() |
| 143 |
|
| 144 |
# Configure the file |
| 145 |
configure_file( |
| 146 |
${PACKAGE_SOURCE_DIR}/cmake/${PACKAGE_NAME_CONFIG_FILE}.in |
| 147 |
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME_CONFIG_FILE} |
| 148 |
) |
| 149 |
|
| 150 |
endfunction() |