Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying FIND_SHARED_LIBS per-TPL #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/core/ProcessEnabledTpls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,40 @@ create_process_enabled_tpls_test_case(
)


create_process_enabled_tpls_test_case(
HeadersAndLibsTpl_Shared_PerLibrarySetting
TPL_NAME HeadersAndLibsTpl
TPL_FINDMOD ${HeadersAndLibsTpl_FINDMOD}
INCLUDE_DIRS ${HeadersAndLibsTpl_BASE_DIR}/include
LIBRARY_DIRS ${HeadersAndLibsTpl_BASE_DIR}/lib
EXTRA_ARGS -DHeadersAndLibsTpl_FIND_SHARED_LIBS=ON
PASS_REGULAR_EXPRESSION_ALL
"Processing enabled external package/TPL: HeadersAndLibsTpl .enabled explicitly, disable with -DTPL_ENABLE_HeadersAndLibsTpl=OFF."
"-- Must find at least one lib in each of the lib sets .haltpl1[;]haltpl2."
"-- Searching for libs in HeadersAndLibsTpl_LIBRARY_DIRS='.+/HeadersAndLibsTpl/lib'"
"-- Searching for a lib in the set .haltpl1.:"
"-- Searching for lib 'haltpl1' [.][.][.]"
"-- Found lib '.+/HeadersAndLibsTpl/lib/libhaltpl1.so'"
"-- Searching for a lib in the set .haltpl2.:"
"-- Searching for lib 'haltpl2' [.][.][.]"
"-- Found lib '.+/HeadersAndLibsTpl/lib/libhaltpl2.so'"
"-- TPL_HeadersAndLibsTpl_LIBRARIES='.+/HeadersAndLibsTpl/lib/libhaltpl1.so[;].+/HeadersAndLibsTpl/lib/libhaltpl2.so'"
"-- Must find at least one header in each of the header sets .HeadersAndLibsTpl_header1.hpp[;]HeadersAndLibsTpl_header2.hpp."
"-- Searching for headers in HeadersAndLibsTpl_INCLUDE_DIRS='.+/HeadersAndLibsTpl/include'"
"-- Searching for a header file in the set .HeadersAndLibsTpl_header1.hpp.:"
"-- Searching for header 'HeadersAndLibsTpl_header1.hpp' [.][.][.]"
"-- Found header '.+/HeadersAndLibsTpl/include/?/HeadersAndLibsTpl_header1.hpp'"
"-- Searching for a header file in the set .HeadersAndLibsTpl_header2.hpp.:"
"-- Searching for header 'HeadersAndLibsTpl_header2.hpp' [.][.][.]"
"-- Found header '.+/HeadersAndLibsTpl/include/?/HeadersAndLibsTpl_header2.hpp'"
"-- Found TPL 'HeadersAndLibsTpl' include dirs '.+/HeadersAndLibsTpl/include'"
"-- TPL_HeadersAndLibsTpl_INCLUDE_DIRS='.+/HeadersAndLibsTpl/include'"
"Exported TPL_HeadersAndLibsTpl_NOT_FOUND='FALSE'"
"Exported TPL_HeadersAndLibsTpl_LIBRARIES='.+/HeadersAndLibsTpl/lib/libhaltpl1.so[;].+/HeadersAndLibsTpl/lib/libhaltpl2.so'"
"Exported TPL_HeadersAndLibsTpl_INCLUDE_DIRS='.+/HeadersAndLibsTpl/include'"
)


create_process_enabled_tpls_test_case(
HeadersAndLibsTpl_Shared_FindAll_sets1
TPL_NAME HeadersAndLibsTpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,15 @@ function(tribits_tpl_find_include_dirs_and_libraries TPL_NAME)
#print_var(TPL_CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT)
endif()

# Allow per-TPL shared lib find setting
if (NOT DEFINED ${TPL_NAME}_FIND_SHARED_LIBS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (NOT DEFINED ${TPL_NAME}_FIND_SHARED_LIBS)
if ("${${TPL_NAME}_FIND_SHARED_LIBS}" STREQUAL "")

This works if the variable is undefined and of it is set to "unset" state (see How to check for and tweak TriBITS “ENABLE” cache variables).

Copy link
Member

@bartlettroscoe bartlettroscoe Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could just property define a cache var in one statement with:

set_cache_on_off_empty(
  ${TPL_NAME}_FIND_SHARED_LIBS "${TPL_FIND_SHARED_LIBS}"
  "Find only shared libs for TPL ${TPL_NAME}")

(see set_cache_on_off_empty()).

You would do that if you wanted to provide documentation for the user in the cache file (and with the various CMake GUIs like ccmake or cmake-gui).

set(${TPL_NAME}_FIND_SHARED_LIBS ${TPL_FIND_SHARED_LIBS})
endif()

#print_var(TPL_FIND_SHARED_LIBS)
#print_var(CMAKE_FIND_LIBRARY_SUFFIXES)
# Set libraries to find
if (TPL_FIND_SHARED_LIBS)
if (${TPL_NAME}_FIND_SHARED_LIBS)
# The default should be to find shared libs first
set(TPL_CMAKE_FIND_LIBRARY_SUFFIXES ${TPL_CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT})
else()
Expand Down
Loading