| 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 |
include(CMakeParseArguments) |
| 12 |
include(PrintVar) |
| 13 |
|
| 14 |
|
| 15 |
# |
| 16 |
# Function that creates a set of template code client headers that either |
| 17 |
# includes or does not include the template instantiations depending on |
| 18 |
# whether implicit or explicit instantiation is supported or not. |
| 19 |
# |
| 20 |
# Usage: |
| 21 |
# |
| 22 |
# tribits_create_client_template_headers( |
| 23 |
# BASE_DIR |
| 24 |
# [ADDITIONAL_OUTPUT_DIRS ABSDIR1 ABSDIR2 ...] |
| 25 |
# ) |
| 26 |
# |
| 27 |
# The arguments are: |
| 28 |
# |
| 29 |
# BASE_DIR |
| 30 |
# |
| 31 |
# The base directory where files with the extension |
| 32 |
# ${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT} will be |
| 33 |
# globed for. |
| 34 |
# |
| 35 |
# ADDITIONAL_OUTPUT_DIRS |
| 36 |
# |
| 37 |
# If set, then the files will be copied to an additional output |
| 38 |
# directories as well. These must be absolute paths. |
| 39 |
# |
| 40 |
# The default file extensions are: |
| 41 |
# |
| 42 |
# ${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT = "_decl.hpp" |
| 43 |
# ${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT = "_def.hpp" |
| 44 |
# |
| 45 |
|
| 46 |
function(tribits_create_client_template_headers BASE_DIR) |
| 47 |
|
| 48 |
#print_var(BASE_DIR) |
| 49 |
|
| 50 |
# |
| 51 |
# A) Parse the input arguments |
| 52 |
# |
| 53 |
|
| 54 |
cmake_parse_arguments( |
| 55 |
#prefix |
| 56 |
PARSE |
| 57 |
#options |
| 58 |
"" |
| 59 |
#one_value_keywords |
| 60 |
"" |
| 61 |
#multi_value_keywords |
| 62 |
"ADDITIONAL_OUTPUT_DIRS" |
| 63 |
${ARGN} |
| 64 |
) |
| 65 |
|
| 66 |
tribits_check_for_unparsed_arguments() |
| 67 |
|
| 68 |
# |
| 69 |
# B) Get the names of the extensions |
| 70 |
# |
| 71 |
|
| 72 |
if (NOT ${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT) |
| 73 |
set(${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT "_decl.hpp") |
| 74 |
endif() |
| 75 |
|
| 76 |
if (NOT ${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT) |
| 77 |
set(${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT "_def.hpp") |
| 78 |
endif() |
| 79 |
|
| 80 |
# |
| 81 |
# C) Glob the names of all the X_decl.hpp files |
| 82 |
# |
| 83 |
|
| 84 |
file(GLOB DECL_HEADERS_LIST "${BASE_DIR}/*${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}") |
| 85 |
#print_var(DECL_HEADERS_LIST) |
| 86 |
|
| 87 |
# |
| 88 |
# D) Write the client header files for each globed decl file |
| 89 |
# |
| 90 |
|
| 91 |
assert_defined(HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION) |
| 92 |
|
| 93 |
foreach(DECL_HEADER ${DECL_HEADERS_LIST}) |
| 94 |
|
| 95 |
# Get the base file names (without _decl.hpp) |
| 96 |
string(REGEX REPLACE ".*/(.+)${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}" "\\1" DECL_HEADER_BASE ${DECL_HEADER}) |
| 97 |
#print_var(DECL_HEADER_BASE) |
| 98 |
|
| 99 |
# Create the client header file |
| 100 |
set(CLIENT_HEADER_STR "") |
| 101 |
string(APPEND CLIENT_HEADER_STR |
| 102 |
"#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}\"\n" |
| 103 |
) |
| 104 |
if (HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION) |
| 105 |
set(TEMPLATE_INSTANT_TYPE_NAME "explicit instantiation") |
| 106 |
else() |
| 107 |
set(TEMPLATE_INSTANT_TYPE_NAME "implicit instantiation") |
| 108 |
string(APPEND CLIENT_HEADER_STR |
| 109 |
"#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT}\"\n" |
| 110 |
) |
| 111 |
endif() |
| 112 |
set(BIN_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/${DECL_HEADER_BASE}.hpp") |
| 113 |
set(WRITE_NEW_HEADER_FILE TRUE) |
| 114 |
if (EXISTS "${BIN_HEADER_FILE}") |
| 115 |
# See if the file is the same and if it is, skip writing it again to avoid |
| 116 |
# unnecessarily rebuilding object code. |
| 117 |
file(READ "${BIN_HEADER_FILE}" EXISTING_BIN_HEADER_STR) |
| 118 |
if (CLIENT_HEADER_STR STREQUAL EXISTING_BIN_HEADER_STR) |
| 119 |
set(WRITE_NEW_HEADER_FILE FALSE) |
| 120 |
endif() |
| 121 |
endif() |
| 122 |
|
| 123 |
# Write the header file |
| 124 |
if (WRITE_NEW_HEADER_FILE) |
| 125 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 126 |
message("Writing ${TEMPLATE_INSTANT_TYPE_NAME} header ${BIN_HEADER_FILE}") |
| 127 |
endif() |
| 128 |
file(WRITE "${BIN_HEADER_FILE}" "${CLIENT_HEADER_STR}") |
| 129 |
endif() |
| 130 |
|
| 131 |
# Create the SIERRA BJAM version of the header file |
| 132 |
foreach(OUTPUT_DIR ${PARSE_ADDITIONAL_OUTPUT_DIRS}) |
| 133 |
set(EXTERNAL_CLIENT_HEADER_STR "") |
| 134 |
string(APPEND EXTERNAL_CLIENT_HEADER_STR |
| 135 |
"#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}\"\n" |
| 136 |
"#ifndef HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION\n" |
| 137 |
"# include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT}\"\n" |
| 138 |
"#endif\n" |
| 139 |
) |
| 140 |
set(EXTERNAL_HEADER "${OUTPUT_DIR}/${DECL_HEADER_BASE}.hpp") |
| 141 |
if (NOT EXISTS "${EXTERNAL_HEADER}") |
| 142 |
file(WRITE "${EXTERNAL_HEADER}" "${EXTERNAL_CLIENT_HEADER_STR}") |
| 143 |
endif() |
| 144 |
endforeach() |
| 145 |
|
| 146 |
endforeach() |
| 147 |
|
| 148 |
endfunction() |
| 149 |
|