Skip to content

Commit

Permalink
Handle/allow arbitrary linker arguments in TPL_<tplName>_LIBRARIES (#299
Browse files Browse the repository at this point in the history
, #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<libname>'.  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.
  • Loading branch information
bartlettroscoe committed Dec 15, 2021
1 parent fd77678 commit 85e7247
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
48 changes: 46 additions & 2 deletions test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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***")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ endfunction()
#
# Read the ``TPL_<tplName>_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::
#
Expand All @@ -243,17 +243,17 @@ endfunction()
#
# The arguments are:
#
# ``<tplName>``: Name of the external package/TPL
# ``<tplName>``: [In] Name of the external package/TPL
#
# ``<libTargetsListOut>``: Name of list variable that will be set with the
# list of IMPORTED library targets generated from this list.
# ``<libTargetsListOut>``: [Out] Name of list variable that will be set with
# the list of IMPORTED library targets generated from this list.
#
# ``<libLinkFlagsListOut>``: Name of list variable that will be set with the
# list of ``-L<dir>`` library directoy paths.
# ``<libLinkFlagsListOut>``: [Out] Name of list variable that will be set
# with the list of ``-L<dir>`` library directoy paths.
#
# ``<configFileFragStrInOut>``: A string variable that will be appended with
# the IMPORTED library commands for the list of targts given in
# ``<libTargetsList>``.
# ``<configFileFragStrInOut>``: [Inout] A string variable that will be
# appended with the IMPORTED library commands for the list of targts given
# in ``<libTargetsList>``.
#
function(tribits_external_package_process_libraries_list tplName)

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -329,14 +332,20 @@ endfunction()
# ``LIB_DIR_LINK_OPTION``: A library directory search option of the form
# ``-L<dir>``
#
# ``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()
Expand Down

0 comments on commit 85e7247

Please sign in to comment.