Skip to content

Commit

Permalink
Replace append_string_var(...) with string(APPEND ...) and deprecate (T…
Browse files Browse the repository at this point in the history
…riBITSPub#411)

I just noticed that CMake 3.17 suppports string(APPEND ...).  The more that we
can remove from TriBITS the better.
  • Loading branch information
bartlettroscoe committed Oct 21, 2021
1 parent bc14759 commit cd3e16a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
44 changes: 22 additions & 22 deletions tribits/core/package_arch/TribitsAddAdvancedTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SCRIPT_NAME>\"\n"
Expand Down Expand Up @@ -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 :-)

Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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" )

Expand All @@ -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" )

Expand Down
2 changes: 1 addition & 1 deletion tribits/core/package_arch/TribitsLibraryMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions tribits/core/package_arch/TribitsProcessEnabledTpl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tribits/core/utils/AppendStringVar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stringVar> "<string1>" "<string2>" ...)
#
function(append_string_var STRING_VAR_OUT)
#message("APPEND_STRING_VAR: ${STRING_VAR_OUT} {${ARGN}}")
concat_strings( STRING_VAR "${${STRING_VAR_OUT}}" ${ARGN} )
Expand Down
2 changes: 1 addition & 1 deletion tribits/core/utils/DriveAdvancedTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion tribits/ctest_driver/TribitsCTestDriverCoreHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down

0 comments on commit cd3e16a

Please sign in to comment.