From 35d82aaa31fe81ca30a619320bb71fe481e9d4c7 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Tue, 14 Dec 2021 15:48:02 -0700 Subject: [PATCH] Interpret a raw identifer in TPL__LIBRARIES as a lib name (#299, #433) Of note: * Added unit test to make that single-char lib name like 'm' will be interepreted as a library. * The arguments '-o some-other-option' that were an error before are now allowed and '-o' is interepreted as its own link option and moved forward and 'some-other-option' is interpreted as a library name. --- test/core/CMakeLists.txt | 2 +- ...rnalPackageWriteConfigFile_UnitTests.cmake | 71 ++++++++++++++++++- ...ribitsExternalPackageWriteConfigFile.cmake | 15 +++- 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 5202392a1..60f267c0c 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -145,7 +145,7 @@ tribits_add_advanced_test( TribitsExternalPackageWriteConfigFile_UnitTests -DCURRENT_TEST_DIRECTORY=${CMAKE_CURRENT_BINARY_DIR} -P "${CMAKE_CURRENT_SOURCE_DIR}/TribitsExternalPackageWriteConfigFile_UnitTests.cmake" PASS_REGULAR_EXPRESSION_ALL - "Final UnitTests Result: num_run = 35" + "Final UnitTests Result: num_run = 39" "Final UnitTests Result: PASSED" ) diff --git a/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake b/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake index b52fa4594..b9089a084 100644 --- a/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake +++ b/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake @@ -390,6 +390,62 @@ function(unittest_tribits_external_package_process_libraries_list_incl_dirs_0_li endfunction() +function(unittest_tribits_external_package_process_libraries_list_incl_dirs_0_libname_2) + + message("\n***") + message("*** Testing tribits_external_package_process_libraries_list(): incl dirs 0, libname 2") + message("***\n") + + set(tplName SomeTpl) + set(TPL_${tplName}_LIBRARIES + some1_Longer2-Name3 # Lower case, upper case, _, -, and digits + - # One-char special case that should never happen + c # One-char special case like 'm' + ) + + set(configFileFragStr "#beginning\n\n") + + set(MESSAGE_WRAPPER_UNIT_TEST_MODE ON) + global_null_set(MESSAGE_WRAPPER_INPUT) + + tribits_external_package_process_libraries_list( ${tplName} + LIB_TARGETS_LIST_OUT libTargetsList + LIB_LINK_FLAGS_LIST_OUT libLinkFlagsList + CONFIG_FILE_STR_INOUT configFileFragStr + ) + + unittest_compare_const( MESSAGE_WRAPPER_INPUT + "NOTE: Moving the general link argument '-' in TPL_SomeTpl_LIBRARIES forward on the link line which may change the link and break the link!" + ) + + unittest_compare_const( libTargetsList + "SomeTpl::c;SomeTpl::some1_Longer2-Name3" + ) + + unittest_compare_const( libLinkFlagsList "-" ) + + message("configFileFragStr:\n\n${configFileFragStr}") + + unittest_string_block_compare( configFileFragStr +[=[ +#beginning + +add_library(SomeTpl::c IMPORTED INTERFACE GLOBAL) +set_target_properties(SomeTpl::c PROPERTIES + IMPORTED_LIBNAME "c") + +add_library(SomeTpl::some1_Longer2-Name3 IMPORTED INTERFACE GLOBAL) +set_target_properties(SomeTpl::some1_Longer2-Name3 PROPERTIES + IMPORTED_LIBNAME "some1_Longer2-Name3") +target_link_libraries(SomeTpl::some1_Longer2-Name3 + INTERFACE SomeTpl::c) + +]=] + ) + +endfunction() + + function(unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_2_2_lib_files_1) message("\n***") @@ -724,6 +780,7 @@ function(unittest_tribits_external_package_write_config_file_str_incl_dirs_1_bad set(TPL_${tplName}_LIBRARIES -llib2 -L/some/explicit/path2 -o some-other-option + some=nonsupported-opt -llib1 -L/some/explicit/path1 ) @@ -734,7 +791,7 @@ function(unittest_tribits_external_package_write_config_file_str_incl_dirs_1_bad tplConfigFileStr ) unittest_compare_const( MESSAGE_WRAPPER_INPUT - "SEND_ERROR;ERROR: Can't handle argument 'some-other-option' in list TPL_SomeTpl_LIBRARIES;NOTE: Moving the general link argument '-o' in TPL_SomeTpl_LIBRARIES forward on the link line which may change the link and break the link!" + "SEND_ERROR;ERROR: Can't handle argument 'some=nonsupported-opt' in list TPL_SomeTpl_LIBRARIES;NOTE: Moving the general link argument '-o' in TPL_SomeTpl_LIBRARIES forward on the link line which may change the link and break the link!" ) unittest_string_block_compare( tplConfigFileStr @@ -749,15 +806,22 @@ add_library(SomeTpl::lib1 IMPORTED INTERFACE GLOBAL) set_target_properties(SomeTpl::lib1 PROPERTIES IMPORTED_LIBNAME "lib1") +add_library(SomeTpl::some-other-option IMPORTED INTERFACE GLOBAL) +set_target_properties(SomeTpl::some-other-option PROPERTIES + IMPORTED_LIBNAME "some-other-option") +target_link_libraries(SomeTpl::some-other-option + INTERFACE SomeTpl::lib1) + add_library(SomeTpl::lib2 IMPORTED INTERFACE GLOBAL) set_target_properties(SomeTpl::lib2 PROPERTIES IMPORTED_LIBNAME "lib2") target_link_libraries(SomeTpl::lib2 - INTERFACE SomeTpl::lib1) + INTERFACE SomeTpl::some-other-option) add_library(SomeTpl::all_libs INTERFACE IMPORTED GLOBAL) target_link_libraries(SomeTpl::all_libs INTERFACE SomeTpl::lib1 + INTERFACE SomeTpl::some-other-option INTERFACE SomeTpl::lib2 ) target_include_directories(SomeTpl::all_libs SYSTEM @@ -795,6 +859,7 @@ unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_2_ unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_3_3() unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_2_2_lib_files_1() unittest_tribits_external_package_process_libraries_list_incl_dirs_0_link_opt_1() +unittest_tribits_external_package_process_libraries_list_incl_dirs_0_libname_2() unittest_tribits_external_package_process_libraries_list_duplicate_libs() unittest_tribits_external_package_write_config_file_str_incl_dirs_0_lib_files_1() @@ -805,4 +870,4 @@ unittest_tribits_external_package_write_config_file_str_incl_dirs_2_lib_opts_2_2 unittest_tribits_external_package_write_config_file_str_incl_dirs_1_bad_lib_args() # Pass in the number of expected tests that must pass! -unittest_final_result(35) +unittest_final_result(39) diff --git a/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake b/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake index d0f38241e..3de401327 100644 --- a/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake +++ b/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake @@ -329,6 +329,8 @@ endfunction() # ``LIB_NAME_LINK_OPTION``: A library name link option of the form # ``-l`` # +# ``LIB_NAME``: A library name of the form ```` +# # ``LIB_DIR_LINK_OPTION``: A library directory search option of the form # ``-L`` # @@ -348,12 +350,15 @@ function(tribits_tpl_libraries_entry_type libentry libEntryTypeOut) set(libEntryType GENERAL_LINK_OPTION) elseif (IS_ABSOLUTE "${libentry}") set(libEntryType FULL_LIB_PATH) + elseif (libentry MATCHES "^[a-zA-Z_][a-zA-Z0-9_-]*$") + set(libEntryType LIB_NAME) else() set(libEntryType UNSUPPORTED_LIB_ENTRY) endif() set(${libEntryTypeOut} ${libEntryType} PARENT_SCOPE) endfunction() - +# NOTE: Above, if libentry is only 1 char long, then firstTwoCharsLibEntry is +# also 1 char long and the above logic still works. # Function to process a library inside of loop over TPL__LIBRARIES # in the function tribits_external_package_process_libraries_list() @@ -404,6 +409,9 @@ function(tribits_external_package_get_libname_and_path_from_libentry elseif (libEntryType STREQUAL "LIB_NAME_LINK_OPTION") tribits_external_package_get_libname_from_lib_name_link_option("${libentry}" libname) set(libpath "") + elseif (libEntryType STREQUAL "LIB_NAME") + set(libname "${libentry}") + set(libpath "") else() message(FATAL_ERROR "Error libEntryType='${libEntryType}' not supported here!") endif() @@ -423,7 +431,10 @@ function(tribits_external_package_append_add_library_str "set_target_properties(${prefixed_libname} PROPERTIES\n" " IMPORTED_LOCATION \"${libpath}\")\n" ) - elseif (libEntryType STREQUAL "LIB_NAME_LINK_OPTION") + elseif ( + (libEntryType STREQUAL "LIB_NAME_LINK_OPTION") + OR (libEntryType STREQUAL "LIB_NAME") + ) string(APPEND configFileStr "add_library(${prefixed_libname} IMPORTED INTERFACE GLOBAL)\n" "set_target_properties(${prefixed_libname} PROPERTIES\n"