Skip to content

Commit

Permalink
Interpret a raw identifer in TPL_<tplName>_LIBRARIES as a lib name (T…
Browse files Browse the repository at this point in the history
…riBITSPub#299, TriBITSPub#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.
  • Loading branch information
bartlettroscoe committed Dec 15, 2021
1 parent 85e7247 commit 35d82aa
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 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 = 35"
"Final UnitTests Result: num_run = 39"
"Final UnitTests Result: PASSED"
)

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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ endfunction()
# ``LIB_NAME_LINK_OPTION``: A library name link option of the form
# ``-l<libname>``
#
# ``LIB_NAME``: A library name of the form ``<libname>``
#
# ``LIB_DIR_LINK_OPTION``: A library directory search option of the form
# ``-L<dir>``
#
Expand All @@ -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_<tplName>_LIBRARIES
# in the function tribits_external_package_process_libraries_list()
Expand Down Expand Up @@ -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()
Expand All @@ -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"
Expand Down

0 comments on commit 35d82aa

Please sign in to comment.