-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
cmake: fix for absolute path to libm.so in pxrConfig.cmake #2796
cmake: fix for absolute path to libm.so in pxrConfig.cmake #2796
Conversation
Filed as internal issue #USD-8922 |
This version of your change is very much in line with my patch for macOS to fix the same issue. I don't have a Linux box to test with but I think having the same format for linkage would be nice to have for uniformity. |
The absolute path makes pxrConfig.cmake non-portable between different distros of Linux (or any other situation where the location of libm.so differs).
5145779
to
3d6db6f
Compare
Hi @dgovil - I tested, and setting M_LIB to just Updated my PR just to remove the special casing for APPLE - in this case, anything non-windows can do it the same way. |
On related note - I discovered the same basic issue exists for a number of other libs on Linux - here's the full list of Linux libs I had to patch up:
Somewhat similarly, I also found some issues with full paths to static libs getting baked into the
In case anyone else has similar problems when trying to use find_package(pxr
HINTS
${USD_LOCATION}
$ENV{USD_LOCATION}
${PXR_USD_LOCATION}
$ENV{PXR_USD_LOCATION}
${PXR_DIR}
$ENV{PXR_DIR}
)
# Fix for absolute paths to libs in pxrConfig.cmake - see:
# https://github.com/PixarAnimationStudios/OpenUSD/issues/2798
# https://github.com/PixarAnimationStudios/OpenUSD/pull/2796
function(fix_absolute_interface_linked_libs lib_names)
cmake_parse_arguments(args
"STATIC"
""
""
${ARGN}
)
if(args_STATIC)
set(lib_prefix "${CMAKE_STATIC_LIBRARY_PREFIX}")
set(lib_suffix "${CMAKE_STATIC_LIBRARY_SUFFIX}")
else()
set(lib_prefix "${CMAKE_SHARED_LIBRARY_PREFIX}")
set(lib_suffix "${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
string(LENGTH "${lib_suffix}." suffix_plus_dot_len)
get_property(import_targets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY IMPORTED_TARGETS)
foreach(target ${import_targets})
get_target_property(interface_link_libraries ${target} INTERFACE_LINK_LIBRARIES)
if(NOT interface_link_libraries)
continue()
endif()
set(modified_interface_link_libraries, "")
set(found_bad_lib FALSE)
foreach(link_lib ${interface_link_libraries})
list(APPEND modified_interface_link_libraries "${link_lib}")
if(NOT IS_ABSOLUTE "${link_lib}")
continue()
endif()
get_filename_component(link_lib_ext ${link_lib} EXT)
set(is_lib_suffix FALSE)
if("${link_lib_ext}" STREQUAL "${lib_suffix}")
# check if the extension is exactly, ie, ".so"
set(is_lib_suffix TRUE)
elseif(NOT WIN32)
# check if the extension starts with, ie, ".so." - like libm.so.6
string(SUBSTRING "${link_lib_ext}" 0 ${suffix_plus_dot_len} possible_suffix_plus_dot)
if("${possible_suffix_plus_dot}" STREQUAL "${lib_suffix}.")
set(is_lib_suffix TRUE)
endif()
endif()
if(NOT is_lib_suffix)
# if the extension isn't, ie, ".so" or ".so.6", skip
continue()
endif()
if(EXISTS "${link_lib}")
continue()
endif()
get_filename_component(link_lib_shortname ${link_lib} NAME_WE)
foreach(lib_name ${lib_names})
if("${link_lib_shortname}" STREQUAL "${CMAKE_SHARED_LIBRARY_PREFIX}${lib_name}")
# Ok, we found an absolute path to our lib, that doesn't exist on the current system
# replace with just the lib name
set(found_bad_lib TRUE)
message(VERBOSE "Fixing non-existant INTERFACE_LINK_LIBRARIES entry for '${target}': ${link_lib}")
list(POP_BACK modified_interface_link_libraries)
if(NOT args_STATIC)
list(APPEND modified_interface_link_libraries "${lib_name}")
endif()
break()
endif()
endforeach()
if(found_bad_lib)
set_target_properties(${target} PROPERTIES
INTERFACE_LINK_LIBRARIES
"${modified_interface_link_libraries}"
)
endif()
endforeach()
endforeach()
endfunction()
if(WIN32)
fix_absolute_interface_linked_libs("osdCPU;osdGPU" STATIC)
else()
fix_absolute_interface_linked_libs("GL;GLU;ICE;SM;X11;Xext;Xt;m")
endif() |
As a follow up to this comment:
...I think most of the other absolute paths there came in "recursively" due to
Until this is fixed there, however, and we update to that version, we may want to consider applying these as patches to our source. I'll open a separate issue / PR for that, though, when/if I get the time... |
Just a quick note that the above two MRs were merged into MaterialX 1.38.9. |
Hi - someone else ran into this issue, and was wondering if we might get this merged. Any chance it can make it in the next release? |
Description of Change(s)
The absolute path makes
pxrConfig.cmake
non-portable between different distros of Linux (or any other situation where the location oflibm.so
differs).I'm pushing two PRs with two different approaches to fixing this
libm.so
(found viafind_library
), we simply link to the libm
, and assume that the standard cmake variables / methods for finding libs will be sufficientfind_library
to find the location oflibm.so
, but we don't link directly to the absolute path this finds; instead, we link to justm
, but we make sure the directory we find it in is searched by the linker for any targets using it, viatarget_link_directories
Of the two approaches, I prefer the simple one (this one), because they will only differ in behavior if:
libm.so
not installed in a standard system library directory (ie, not via the distro's standard package manager)libm.so
is in a location that WON'T be found at link time via CMake or the compiler's standard mechanisms for altering linking commands (ie, due to modifcations to theCMAKE_SHARED_LINKER_FLAGS
cmake variable or theLDFLAGS
env variable)find_library
I think that particular combination of circustances is rare enough that it's unlikely a current member of the USD community will see a difference. Given that, I'd prefer to keep the codebase simpler. (ie, the "safe" approach would require remembering to call
target_link_directories(new_lib PRIVATE ${M_LIB_DIR})
on any new_lib which has a dependency onlibm.so
...)Fixes Issue(s)