Skip to content

Commit

Permalink
Update CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Oct 9, 2023
1 parent f7ebe3d commit 6436ec2
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tools/pnnx/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,33 @@ if(PROTOBUF_FOUND)
endif()

if(TorchVision_FOUND)
get_target_property(TorchVision_location TorchVision::TorchVision LOCATION)
get_target_property(TorchVision_type TorchVision::TorchVision TYPE)
message(STATUS "TorchVision_location = ${TorchVision_location}")
message(STATUS "TorchVision_type = ${TorchVision_type}")
if(TorchVision_type STREQUAL "SHARED_LIBRARY")
target_link_libraries(pnnx PRIVATE -Wl,--no-as-needed ${TorchVision_location} -Wl,--as-needed)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
target_link_libraries(pnnx INTERFACE "-Wl,--no-as-needed,\"$<TARGET_FILE:TorchVision::TorchVision>\" -Wl,--as-needed")
else()
target_link_libraries(pnnx INTERFACE TorchVision::TorchVision)
endif()
target_link_libraries(pnnx INTERFACE $<TARGET_PROPERTY:TorchVision::TorchVision,INTERFACE_LINK_LIBRARIES>)
elseif(TorchVision_type STREQUAL "STATIC_LIBRARY")
target_link_libraries(pnnx PRIVATE -Wl,--whole-archive ${TorchVision_location} -Wl,--no-whole-archive)
if(APPLE)
target_link_libraries(pnnx INTERFACE -Wl,-force_load,\"$<TARGET_FILE:TorchVision::TorchVision>\")
elseif(MSVC)
target_link_libraries(pnnx INTERFACE "$<TARGET_FILE:TorchVision::TorchVision>")
target_link_options(pnnx INTERFACE "-WHOLEARCHIVE:$<TARGET_FILE:TorchVision::TorchVision>")
else()
target_link_libraries(pnnx INTERFACE "-Wl,--whole-archive,\"$<TARGET_FILE:TorchVision::TorchVision>\" -Wl,--no-whole-archive")
endif()
endif()

set_target_properties(pnnx PROPERTIES
INTERFACE_COMPILE_DEFINITIONS $<TARGET_PROPERTY:TorchVision::TorchVision,INTERFACE_COMPILE_DEFINITIONS>
INTERFACE_COMPILE_OPTIONS $<TARGET_PROPERTY:TorchVision::TorchVision,INTERFACE_COMPILE_OPTIONS>
INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:TorchVision::TorchVision,INTERFACE_INCLUDE_DIRECTORIES>
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:TorchVision::TorchVision,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
)

#target_link_libraries(pnnx PRIVATE TorchVision::TorchVision)
endif()

Expand Down

0 comments on commit 6436ec2

Please sign in to comment.