From 85e72477f15f0e29868d78701144282dbfcffd5f Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Mon, 13 Dec 2021 11:39:59 -0700 Subject: [PATCH] Handle/allow arbitrary linker arguments in TPL__LIBRARIES (#299, #433) Turns out some Trilinos configure scripts (including some of the ATDM Trilinos configure scripts) use arbitary linker arguments like '-mkl' that are not -L or -l. These arguments need to be moved forward on the link link in the 'all_libs' target. Since this is not very general, I added a 'NOTE' printed to STDOUT in order to warn about this. NOTE: This now allows an agument like: '-o some-name' and it will move '-o' forward and in the next commit the bare 'some-name' arg will be interepreted as a library name and be handled the same as '-l'. But obviously splitting up the arguments `-o some-name` by moving '-o' forward by itself and treating `some-name` as a link library is just wrong but I don't see how we can avoid that. --- test/core/CMakeLists.txt | 2 +- ...rnalPackageWriteConfigFile_UnitTests.cmake | 48 ++++++++++++++++++- ...ribitsExternalPackageWriteConfigFile.cmake | 27 +++++++---- 3 files changed, 65 insertions(+), 12 deletions(-) diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index cfcad4032..5202392a1 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 = 31" + "Final UnitTests Result: num_run = 35" "Final UnitTests Result: PASSED" ) diff --git a/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake b/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake index 2bbc6198b..b52fa4594 100644 --- a/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake +++ b/test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake @@ -348,6 +348,48 @@ target_link_libraries(SomeTpl::lib3 endfunction() +function(unittest_tribits_external_package_process_libraries_list_incl_dirs_0_link_opt_1) + + message("\n***") + message("*** Testing tribits_external_package_process_libraries_list(): incl dirs 0, link opt 1") + message("***\n") + + set(tplName SomeTpl) + set(TPL_${tplName}_LIBRARIES "-mkl") + + 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 '-mkl' in TPL_${tplName}_LIBRARIES forward on the link line which may change the link and break the link!" + ) + + unittest_compare_const( libTargetsList + "" + ) + + unittest_compare_const( libLinkFlagsList + "-mkl" + ) + + unittest_string_block_compare( configFileFragStr +[=[ +#beginning + +]=] + ) + +endfunction() + + function(unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_2_2_lib_files_1) message("\n***") @@ -692,7 +734,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;SEND_ERROR;ERROR: Can't handle argument '-o' in list TPL_SomeTpl_LIBRARIES" + "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!" ) unittest_string_block_compare( tplConfigFileStr @@ -723,6 +765,7 @@ target_include_directories(SomeTpl::all_libs SYSTEM ) target_link_options(SomeTpl::all_libs INTERFACE "-L/some/explicit/path2" + INTERFACE "-o" INTERFACE "-L/some/explicit/path1" ) @@ -751,6 +794,7 @@ unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_1_ unittest_tribits_external_package_process_libraries_list_incl_dirs_0_lib_opts_2_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_duplicate_libs() unittest_tribits_external_package_write_config_file_str_incl_dirs_0_lib_files_1() @@ -761,4 +805,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(31) +unittest_final_result(35) diff --git a/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake b/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake index 69b513e88..d0f38241e 100644 --- a/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake +++ b/tribits/core/package_arch/TribitsExternalPackageWriteConfigFile.cmake @@ -230,7 +230,7 @@ endfunction() # # Read the ``TPL__LIBRARIES` list variable and produce the string for # the IMPORTED targets commands and return list of targets and left over -# linker flags.. +# linker flags. # # Usage:: # @@ -243,17 +243,17 @@ endfunction() # # The arguments are: # -# ````: Name of the external package/TPL +# ````: [In] Name of the external package/TPL # -# ````: Name of list variable that will be set with the -# list of IMPORTED library targets generated from this list. +# ````: [Out] Name of list variable that will be set with +# the list of IMPORTED library targets generated from this list. # -# ````: Name of list variable that will be set with the -# list of ``-L`` library directoy paths. +# ````: [Out] Name of list variable that will be set +# with the list of ``-L`` library directoy paths. # -# ````: A string variable that will be appended with -# the IMPORTED library commands for the list of targts given in -# ````. +# ````: [Inout] A string variable that will be +# appended with the IMPORTED library commands for the list of targts given +# in ````. # function(tribits_external_package_process_libraries_list tplName) @@ -294,6 +294,9 @@ function(tribits_external_package_process_libraries_list tplName) "ERROR: Can't handle argument '${libentry}' in list TPL_${tplName}_LIBRARIES") elseif (libEntryType STREQUAL "LIB_DIR_LINK_OPTION") list(APPEND libLinkFlagsList "${libentry}") + elseif (libEntryType STREQUAL "GENERAL_LINK_OPTION") + message_wrapper("NOTE: Moving the general link argument '${libentry}' in TPL_${tplName}_LIBRARIES forward on the link line which may change the link and break the link!") + list(APPEND libLinkFlagsList "${libentry}") else() tribits_external_package_process_libraries_list_library_entry( ${tplName} "${libentry}" ${libEntryType} libTargets lastLib configFileStr ) @@ -329,14 +332,20 @@ endfunction() # ``LIB_DIR_LINK_OPTION``: A library directory search option of the form # ``-L`` # +# ``GENERAL_LINK_OPTION``: Some other general link option that starts with +# ``-`` but is not ``-l`` or ``-L``. +# # ``UNSUPPORTED_LIB_ENTRY``: An unsupported lib option # function(tribits_tpl_libraries_entry_type libentry libEntryTypeOut) + string(SUBSTRING "${libentry}" 0 1 firstCharLibEntry) string(SUBSTRING "${libentry}" 0 2 firstTwoCharsLibEntry) if (firstTwoCharsLibEntry STREQUAL "-l") set(libEntryType LIB_NAME_LINK_OPTION) elseif (firstTwoCharsLibEntry STREQUAL "-L") set(libEntryType LIB_DIR_LINK_OPTION) + elseif (firstCharLibEntry STREQUAL "-") + set(libEntryType GENERAL_LINK_OPTION) elseif (IS_ABSOLUTE "${libentry}") set(libEntryType FULL_LIB_PATH) else()