Skip to content

Commit

Permalink
Don't add duplicate libs (TriBITSPub#299, TriBITSPub#427)
Browse files Browse the repository at this point in the history
This should fix a configure error reported in TriBITSPub#427 where there were duplicate
libs in TPL_LAPACK_LIBRARIES.
  • Loading branch information
bartlettroscoe committed Nov 3, 2021
1 parent ac2d80f commit 90e71c5
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 34 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 = 28"
"Final UnitTests Result: num_run = 31"
"Final UnitTests Result: PASSED"
)

Expand Down
60 changes: 59 additions & 1 deletion test/core/TribitsExternalPackageWriteConfigFile_UnitTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,63 @@ target_link_libraries(SomeTpl::lib3
endfunction()


function(unittest_tribits_external_package_process_libraries_list_duplicate_libs)

message("\n***")
message("*** Testing tribits_external_package_process_libraries_list(): duplicate libs")
message("***\n")

set(tplName SomeTpl)
set(TPL_${tplName}_LIBRARIES
-llib3 -L/some/explicit/path3
/some/other/path/to/libsomelib.a
-llib3 -L/some/explicit/path3
/some/other/path/to/libsomelib.a
-llib1 -L/some/explicit/path1
)

set(configFileFragStr "#beginning\n\n")

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( libTargetsList
"SomeTpl::lib1;SomeTpl::somelib;SomeTpl::lib3"
)

unittest_compare_const( libLinkFlagsList
"-L/some/explicit/path3;-L/some/explicit/path3;-L/some/explicit/path1"
)

unittest_string_block_compare( configFileFragStr
[=[
#beginning

add_library(SomeTpl::lib1 IMPORTED INTERFACE GLOBAL)
set_target_properties(SomeTpl::lib1 PROPERTIES
IMPORTED_LIBNAME "lib1")

add_library(SomeTpl::somelib IMPORTED UNKNOWN GLOBAL)
set_target_properties(SomeTpl::somelib PROPERTIES
IMPORTED_LOCATION "/some/other/path/to/libsomelib.a")
target_link_libraries(SomeTpl::somelib
INTERFACE SomeTpl::lib1)

add_library(SomeTpl::lib3 IMPORTED INTERFACE GLOBAL)
set_target_properties(SomeTpl::lib3 PROPERTIES
IMPORTED_LIBNAME "lib3")
target_link_libraries(SomeTpl::lib3
INTERFACE SomeTpl::somelib)

]=]
)

endfunction()


#
# Tests for tribits_external_package_write_config_file_str()
#
Expand Down Expand Up @@ -694,6 +751,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_duplicate_libs()

unittest_tribits_external_package_write_config_file_str_incl_dirs_0_lib_files_1()
unittest_tribits_external_package_write_config_file_str_incl_dirs_2_lib_files_0()
Expand All @@ -703,4 +761,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(28)
unittest_final_result(31)
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ include(TribitsGeneralMacros)

include(MessageWrapper)

cmake_policy(SET CMP0057 NEW) # Support if ( ... IN_LIST ... )

# @FUNCTION: tribits_external_package_write_config_file()
#
Expand Down Expand Up @@ -296,7 +297,6 @@ function(tribits_external_package_process_libraries_list_full_lib_path
set(configFileStr ${${configFileStrInOut}})
# Should be an absolute library path
get_filename_component(full_libname "${libentry}" NAME_WLE)
#print_var(full_libname)
# Assert is a valid lib name and get lib name
string(LENGTH "${full_libname}" full_libname_len)
if (full_libname_len LESS 0)
Expand All @@ -307,25 +307,27 @@ function(tribits_external_package_process_libraries_list_full_lib_path
tribits_print_invalid_lib_name(${tplName} "${full_libname}")
endif()
string(SUBSTRING "${full_libname}" 3 -1 libname)
#print_var(libname)
# Create IMPORTED library target
string(APPEND configFileStr
"add_library(${tplName}::${libname} IMPORTED UNKNOWN GLOBAL)\n"
"set_target_properties(${tplName}::${libname} PROPERTIES\n"
" IMPORTED_LOCATION \"${libentry}\")\n"
)
# Set dependency on previous library
if (lastLib)
set(prefixed_libname "${tplName}::${libname}")
if (NOT (prefixed_libname IN_LIST libTargets))
# Create IMPORTED library target
string(APPEND configFileStr
"target_link_libraries(${tplName}::${libname}\n"
" INTERFACE ${tplName}::${lastLib})\n"
"add_library(${tplName}::${libname} IMPORTED UNKNOWN GLOBAL)\n"
"set_target_properties(${tplName}::${libname} PROPERTIES\n"
" IMPORTED_LOCATION \"${libentry}\")\n"
)
# Set dependency on previous library
if (lastLib)
string(APPEND configFileStr
"target_link_libraries(${tplName}::${libname}\n"
" INTERFACE ${tplName}::${lastLib})\n"
)
endif()
string(APPEND configFileStr
"\n")
# Update for next loop
set(lastLib ${libname})
list(APPEND libTargets ${prefixed_libname})
endif()
string(APPEND configFileStr
"\n")
# Update for next loop
set(lastLib ${libname})
list(APPEND libTargets "${tplName}::${libname}")
# Set output vars
set(${libTargetsInOut} ${libTargets} PARENT_SCOPE)
set(${lastLibInOut} ${lastLib} PARENT_SCOPE)
Expand All @@ -351,24 +353,27 @@ function(tribits_external_package_process_libraries_list_lib_name_link_option
endif()
# Get <libname> from -l<libname>
string(SUBSTRING "${libentry}" 2 -1 libname)
# Create IMPORTED library target
string(APPEND configFileStr
"add_library(${tplName}::${libname} IMPORTED INTERFACE GLOBAL)\n"
"set_target_properties(${tplName}::${libname} PROPERTIES\n"
" IMPORTED_LIBNAME \"${libname}\")\n"
)
# Set dependency on previous library
if (lastLib)
set(prefixed_libname "${tplName}::${libname}")
if (NOT (prefixed_libname IN_LIST libTargets))
# Create IMPORTED library target
string(APPEND configFileStr
"target_link_libraries(${tplName}::${libname}\n"
" INTERFACE ${tplName}::${lastLib})\n"
"add_library(${tplName}::${libname} IMPORTED INTERFACE GLOBAL)\n"
"set_target_properties(${tplName}::${libname} PROPERTIES\n"
" IMPORTED_LIBNAME \"${libname}\")\n"
)
# Set dependency on previous library
if (lastLib)
string(APPEND configFileStr
"target_link_libraries(${tplName}::${libname}\n"
" INTERFACE ${tplName}::${lastLib})\n"
)
endif()
string(APPEND configFileStr
"\n")
# Update for next loop
set(lastLib ${libname})
list(APPEND libTargets ${prefixed_libname})
endif()
string(APPEND configFileStr
"\n")
# Update for next loop
set(lastLib ${libname})
list(APPEND libTargets "${tplName}::${libname}")
# Set output vars
set(${libTargetsInOut} ${libTargets} PARENT_SCOPE)
set(${lastLibInOut} ${lastLib} PARENT_SCOPE)
Expand Down

0 comments on commit 90e71c5

Please sign in to comment.