From cd3e16afcc06d1584814d319281652133ef320f8 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 21 Oct 2021 16:42:13 -0600 Subject: [PATCH] Replace append_string_var(...) with string(APPEND ...) and deprecate (#411) I just noticed that CMake 3.17 suppports string(APPEND ...). The more that we can remove from TriBITS the better. --- .../package_arch/TribitsAddAdvancedTest.cmake | 44 +++++++++---------- .../TribitsCreateClientTemplateHeaders.cmake | 6 +-- .../package_arch/TribitsGlobalMacros.cmake | 6 +-- .../package_arch/TribitsLibraryMacros.cmake | 2 +- .../TribitsProcessEnabledTpl.cmake | 6 +-- tribits/core/utils/AppendStringVar.cmake | 4 ++ tribits/core/utils/DriveAdvancedTest.cmake | 2 +- .../TribitsCTestDriverCoreHelpers.cmake | 2 +- 8 files changed, 38 insertions(+), 34 deletions(-) diff --git a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake index dd035e8de..be4914951 100644 --- a/tribits/core/package_arch/TribitsAddAdvancedTest.cmake +++ b/tribits/core/package_arch/TribitsAddAdvancedTest.cmake @@ -945,7 +945,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) set(TEST_SCRIPT_STR "") - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "#\n" "# This is a CMake script and must be run as \"cmake -P \"\n" @@ -1187,7 +1187,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) string(REPLACE ";" "," FILES_TO_COPY_COMMA_SEP "${FILES_TO_COPY_COMMA_SEP}" ) # NOTE: Above, we have to replace ';' with ',' or the lower commands - # append_string_var() will replace ';' with ''. This is *not* what we + # string(APPEND ) will replace ';' with ''. This is *not* what we # want. In DriveAdvancedTest.cmake, we will replace the ',' with ';' # again :-) @@ -1234,7 +1234,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) # Write the vars for COPY_FILES_TO_TEST_DIR - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_COPY_FILES_TO_TEST_DIR" " \"${FILES_TO_COPY_COMMA_SEP}\")\n" @@ -1244,13 +1244,13 @@ function(tribits_add_advanced_test TEST_NAME_IN) "${TEST_CMND_STR}" ) endif() - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_SOURCE_DIR" " \"${COPY_FILES_TO_TEST_DIR_SOURCE_DIR}\")\n" ) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_DEST_DIR" " \"${COPY_FILES_TO_TEST_DIR_DEST_DIR}\")\n" @@ -1263,7 +1263,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) tribits_join_exec_process_set_args( TEST_CMND_STR "${TEST_CMND_ARRAY}" ) #print_var(TEST_CMND_STR) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_CMND ${TEST_CMND_STR} )\n" ) @@ -1275,7 +1275,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) endif() if (PARSE_MESSAGE) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_MESSAGE \"${PARSE_MESSAGE}\" )\n" ) @@ -1285,25 +1285,25 @@ function(tribits_add_advanced_test TEST_NAME_IN) if ("${PARSE_WORKING_DIRECTORY}" STREQUAL "TEST_NAME") set(PARSE_WORKING_DIRECTORY ${TEST_NAME}) endif() - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_WORKING_DIRECTORY \"${PARSE_WORKING_DIRECTORY}\" )\n" ) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_SKIP_CLEAN_WORKING_DIRECTORY ${PARSE_SKIP_CLEAN_WORKING_DIRECTORY} )\n" ) endif() if (PARSE_OUTPUT_FILE) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_OUTPUT_FILE \"${PARSE_OUTPUT_FILE}\" )\n" ) endif() if (PARSE_NO_ECHO_OUTPUT) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_NO_ECHO_OUTPUT \"${PARSE_NO_ECHO_OUTPUT}\" )\n" ) @@ -1312,58 +1312,58 @@ function(tribits_add_advanced_test TEST_NAME_IN) # Set up pass/fail if (PARSE_PASS_ANY) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_ANY TRUE )\n" ) elseif (PARSE_STANDARD_PASS_OUTPUT) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION \"End Result: TEST PASSED\" )\n" ) elseif (PARSE_PASS_REGULAR_EXPRESSION) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION \"${PARSE_PASS_REGULAR_EXPRESSION}\" )\n" ) elseif (PARSE_PASS_REGULAR_EXPRESSION_ALL) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_PASS_REGULAR_EXPRESSION_ALL " ) foreach(REGEX_STR ${PARSE_PASS_REGULAR_EXPRESSION_ALL}) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\"${REGEX_STR}\" " ) endforeach() - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR ")\n" ) endif() if (PARSE_FAIL_REGULAR_EXPRESSION) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_FAIL_REGULAR_EXPRESSION \"${PARSE_FAIL_REGULAR_EXPRESSION}\" )\n" ) endif() if (PARSE_ALWAYS_FAIL_ON_NONZERO_RETURN) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_ALWAYS_FAIL_ON_NONZERO_RETURN TRUE )\n" ) endif() if (PARSE_ALWAYS_FAIL_ON_ZERO_RETURN) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_ALWAYS_FAIL_ON_ZERO_RETURN TRUE )\n" ) endif() if (PARSE_WILL_FAIL) - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set( TEST_${TEST_CMND_IDX}_WILL_FAIL TRUE )\n" ) @@ -1451,7 +1451,7 @@ function(tribits_add_advanced_test TEST_NAME_IN) # F.2) Write the cmake -P script # - append_string_var( TEST_SCRIPT_STR + string(APPEND TEST_SCRIPT_STR "\n" "set(PROJECT_NAME ${PROJECT_NAME})\n" "\n" diff --git a/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake b/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake index 3288e28ba..cc2c6ca42 100644 --- a/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake +++ b/tribits/core/package_arch/TribitsCreateClientTemplateHeaders.cmake @@ -128,14 +128,14 @@ function(tribits_create_client_template_headers BASE_DIR) # Create the client header file set(CLIENT_HEADER_STR "") - append_string_var(CLIENT_HEADER_STR + string(APPEND CLIENT_HEADER_STR "#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}\"\n" ) if (HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION) set(TEMPLATE_INSTANT_TYPE_NAME "explicit instantiation") else() set(TEMPLATE_INSTANT_TYPE_NAME "implicit instantiation") - append_string_var(CLIENT_HEADER_STR + string(APPEND CLIENT_HEADER_STR "#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT}\"\n" ) endif() @@ -161,7 +161,7 @@ function(tribits_create_client_template_headers BASE_DIR) # Create the SIERRA BJAM version of the header file foreach(OUTPUT_DIR ${PARSE_ADDITIONAL_OUTPUT_DIRS}) set(EXTERNAL_CLIENT_HEADER_STR "") - append_string_var(EXTERNAL_CLIENT_HEADER_STR + string(APPEND EXTERNAL_CLIENT_HEADER_STR "#include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DECL_EXT}\"\n" "#ifndef HAVE_${PARENT_PACKAGE_NAME_UC}_EXPLICIT_INSTANTIATION\n" "# include \"${DECL_HEADER_BASE}${${PARENT_PACKAGE_NAME}_TEMPLATE_DEF_EXT}\"\n" diff --git a/tribits/core/package_arch/TribitsGlobalMacros.cmake b/tribits/core/package_arch/TribitsGlobalMacros.cmake index 56adf17e0..91c2a6cf4 100644 --- a/tribits/core/package_arch/TribitsGlobalMacros.cmake +++ b/tribits/core/package_arch/TribitsGlobalMacros.cmake @@ -84,7 +84,7 @@ include(TribitsTplDeclareLibraries) # Deprecated # macro(tribits_assert_and_setup_project_and_static_system_vars) - append_string_var(IN_SOURCE_ERROR_COMMON_MSG + string(APPEND IN_SOURCE_ERROR_COMMON_MSG "\nYou must now run something like:\n" " $ cd ${CMAKE_CURRENT_SOURCE_DIR}/\n" " $ rm -r CMakeCache.txt CMakeFiles/" @@ -1312,7 +1312,7 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST tribits_generate_single_repo_version_string( ${CMAKE_CURRENT_SOURCE_DIR} SINGLE_REPO_VERSION) - append_string_var(REPO_VERSION_FILE_STR + string(APPEND REPO_VERSION_FILE_STR "*** Base Git Repo: ${PROJECT_NAME}\n" "${SINGLE_REPO_VERSION}\n" ) @@ -1336,7 +1336,7 @@ function(tribits_generate_repo_version_file_string PROJECT_REPO_VERSION_FILE_ST tribits_generate_single_repo_version_string( "${CMAKE_CURRENT_SOURCE_DIR}/${EXTRAREPO_DIR}" SINGLE_REPO_VERSION) - append_string_var(REPO_VERSION_FILE_STR + string(APPEND REPO_VERSION_FILE_STR "*** Git Repo: ${EXTRAREPO_DIR}\n" "${SINGLE_REPO_VERSION}\n" ) diff --git a/tribits/core/package_arch/TribitsLibraryMacros.cmake b/tribits/core/package_arch/TribitsLibraryMacros.cmake index 7087ebbae..85cbe0184 100644 --- a/tribits/core/package_arch/TribitsLibraryMacros.cmake +++ b/tribits/core/package_arch/TribitsLibraryMacros.cmake @@ -165,7 +165,7 @@ function(tribits_configure_file PACKAGE_NAME_CONFIG_FILE) endif() if (${PARENT_PACKAGE_NAME}_HIDE_DEPRECATED_CODE) - append_string_var(${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS + string(APPEND ${PARENT_PACKAGE_NAME_UC}_DEPRECATED_DECLARATIONS "\n#define ${PARENT_PACKAGE_NAME_UC}_HIDE_DEPRECATED_CODE") endif() diff --git a/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake b/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake index dd4eece4a..ee5d67598 100644 --- a/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake +++ b/tribits/core/package_arch/TribitsProcessEnabledTpl.cmake @@ -57,13 +57,13 @@ function(tribits_process_enabled_tpl TPL_NAME) # Setup the processing string set(PROCESSING_MSG_STRING "Processing enabled TPL: ${TPL_NAME} (") if (TPL_${TPL_NAME}_ENABLING_PKG) - append_string_var(PROCESSING_MSG_STRING + string(APPEND PROCESSING_MSG_STRING "enabled by ${TPL_${TPL_NAME}_ENABLING_PKG}," ) else() - append_string_var(PROCESSING_MSG_STRING + string(APPEND PROCESSING_MSG_STRING "enabled explicitly," ) endif() - append_string_var(PROCESSING_MSG_STRING + string(APPEND PROCESSING_MSG_STRING " disable with -DTPL_ENABLE_${TPL_NAME}=OFF)" ) # Print the processing header diff --git a/tribits/core/utils/AppendStringVar.cmake b/tribits/core/utils/AppendStringVar.cmake index 63d5cc7b4..5735e56cd 100644 --- a/tribits/core/utils/AppendStringVar.cmake +++ b/tribits/core/utils/AppendStringVar.cmake @@ -55,6 +55,10 @@ include(PrintVar) # If one wants to ignore the meaning of these special characters and are okay # with just adding one string at a time, then use `append_string_var_ext()`_. # +# **DEPRECATED**: Instead, use:: +# +# string(APPEND "" "" ...) +# function(append_string_var STRING_VAR_OUT) #message("APPEND_STRING_VAR: ${STRING_VAR_OUT} {${ARGN}}") concat_strings( STRING_VAR "${${STRING_VAR_OUT}}" ${ARGN} ) diff --git a/tribits/core/utils/DriveAdvancedTest.cmake b/tribits/core/utils/DriveAdvancedTest.cmake index 1950cac80..628b4ed57 100644 --- a/tribits/core/utils/DriveAdvancedTest.cmake +++ b/tribits/core/utils/DriveAdvancedTest.cmake @@ -387,7 +387,7 @@ function(drive_advanced_test) if (CMND_IDX EQUAL 0) set(TEST_NAMES_STR "TEST_0") else() - append_string_var( TEST_NAMES_STR ", TEST_${CMND_IDX}" ) + string(APPEND TEST_NAMES_STR ", TEST_${CMND_IDX}" ) endif() endforeach() message("Running test commands: ${TEST_NAMES_STR}") diff --git a/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake b/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake index 350652e60..ed329adf1 100644 --- a/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake +++ b/tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake @@ -394,7 +394,7 @@ macro(enable_only_modified_packages) file(STRINGS ${EXTRAREPO_MODIFIED_FILES_FILE_NAME} EXTRAREPO_MODIFIED_FILES_STR) set(EXTRAREPO_FILES_STR "") foreach(STR_LINE ${EXTRAREPO_MODIFIED_FILES_STR}) - append_string_var(EXTRAREPO_FILES_STR "${EXTRAREPO_DIR}/${STR_LINE}\n") + string(APPEND EXTRAREPO_FILES_STR "${EXTRAREPO_DIR}/${STR_LINE}\n") endforeach() file(APPEND "${MODIFIED_FILES_FILE_NAME}" ${EXTRAREPO_FILES_STR})