File tree 8 files changed +38
-0
lines changed 8 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,7 @@ cmake_dependent_option(
206
206
"USE_DISTRIBUTED" OFF )
207
207
option (USE_TBB "Use TBB" OFF )
208
208
option (ONNX_ML "Enable traditional ONNX ML API." ON )
209
+ option (HAVE_SOVERSION "Whether to add SOVERSION to the shared objects" OFF )
209
210
210
211
# Linux distributions do not want too many embedded sources, in that sense we
211
212
# need to be able to build pytorch with an (almost) empty third_party
@@ -415,6 +416,7 @@ if(NOT TORCH_BUILD_VERSION)
415
416
endif ()
416
417
caffe2_parse_version_str(TORCH ${TORCH_BUILD_VERSION} )
417
418
caffe2_parse_version_str(CAFFE2 ${TORCH_BUILD_VERSION} )
419
+ set (TORCH_SOVERSION "${TORCH_VERSION_MAJOR} .${TORCH_VERSION_MINOR} " )
418
420
419
421
# ---[ CMake scripts + modules
420
422
list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} /cmake/Modules)
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ file(GLOB C10_SRCS
38
38
file (GLOB_RECURSE C10_ALL_TEST_FILES test /*.cpp)
39
39
file (GLOB_RECURSE C10_HEADERS *.h)
40
40
add_library (c10 ${C10_SRCS} ${C10_HEADERS} )
41
+ if (HAVE_SOVERSION)
42
+ set_target_properties (c10 PROPERTIES
43
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
44
+ endif ()
41
45
# If building shared library, set dllimport/dllexport proper.
42
46
target_compile_options (c10 PRIVATE "-DC10_BUILD_MAIN_LIB" )
43
47
# Enable hidden visibility if compiler supports it.
Original file line number Diff line number Diff line change @@ -522,6 +522,10 @@ endif()
522
522
523
523
524
524
add_library (torch_cpu ${Caffe2_CPU_SRCS} )
525
+ if (HAVE_SOVERSION)
526
+ set_target_properties (torch_cpu PROPERTIES
527
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
528
+ endif ()
525
529
torch_compile_options(torch_cpu) # see cmake/public/utils.cmake
526
530
527
531
if (USE_LLVM AND LLVM_FOUND)
@@ -546,6 +550,10 @@ file(WRITE ${DUMMY_EMPTY_FILE} ${DUMMY_FILE_CONTENT})
546
550
# Wrapper library for people who link against torch and expect both CPU and CUDA support
547
551
# Contains "torch_cpu" and "torch_cuda"
548
552
add_library (torch ${DUMMY_EMPTY_FILE} )
553
+ if (HAVE_SOVERSION)
554
+ set_target_properties (torch PROPERTIES
555
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
556
+ endif ()
549
557
550
558
if (USE_ROCM)
551
559
filter_list(__caffe2_hip_srcs_cpp Caffe2_HIP_SRCS "\\ .(cu|hip)$" )
@@ -1028,6 +1036,10 @@ endif()
1028
1036
# this we have to preload those libs in a global namespace.
1029
1037
if (BUILD_SHARED_LIBS )
1030
1038
add_library (torch_global_deps SHARED ${TORCH_SRC_DIR} /csrc/empty.c)
1039
+ if (HAVE_SOVERSION)
1040
+ set_target_properties (torch_global_deps PROPERTIES
1041
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
1042
+ endif ()
1031
1043
set_target_properties (torch_global_deps PROPERTIES LINKER_LANGUAGE C)
1032
1044
if (USE_MPI)
1033
1045
target_link_libraries (torch_global_deps ${MPI_CXX_LIBRARIES} )
Original file line number Diff line number Diff line change @@ -32,6 +32,10 @@ if(BUILD_CAFFE2_OPS)
32
32
install (TARGETS caffe2_detectron_ops_hip DESTINATION lib)
33
33
elseif (NOT IOS_PLATFORM)
34
34
add_library (caffe2_detectron_ops SHARED ${Detectron_CPU_SRCS} )
35
+ if (HAVE_SOVERSION)
36
+ set_target_properties (caffe2_detectron_ops PROPERTIES
37
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
38
+ endif ()
35
39
target_link_libraries (caffe2_detectron_ops torch ${OpenMP_link} )
36
40
install (TARGETS caffe2_detectron_ops DESTINATION lib)
37
41
if (MSVC )
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ if(BUILD_TEST)
11
11
caffe2_module_test_dynamic
12
12
${CMAKE_CURRENT_SOURCE_DIR} /module_test_dynamic.cc)
13
13
14
+ if (HAVE_SOVERSION)
15
+ set_target_properties (caffe2_module_test_dynamic PROPERTIES
16
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
17
+ endif ()
14
18
target_link_libraries (caffe2_module_test_dynamic torch_library)
15
19
install (TARGETS caffe2_module_test_dynamic DESTINATION lib)
16
20
if (MSVC AND BUILD_SHARED_LIBS )
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ add_library(caffe2_observers
14
14
"${CMAKE_CURRENT_SOURCE_DIR} /observer_config.cc"
15
15
"${CMAKE_CURRENT_SOURCE_DIR} /perf_observer.cc"
16
16
)
17
+ if (HAVE_SOVERSION)
18
+ set_target_properties (caffe2_observers PROPERTIES
19
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
20
+ endif ()
17
21
target_link_libraries (caffe2_observers PUBLIC torch_library)
18
22
target_include_directories (caffe2_observers PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /..)
19
23
target_compile_options (caffe2_observers PRIVATE "-DCAFFE2_BUILD_OBSERVER_LIB" )
Original file line number Diff line number Diff line change @@ -291,6 +291,10 @@ add_custom_command(
291
291
)
292
292
293
293
add_library (torch_python SHARED ${TORCH_PYTHON_SRCS} )
294
+ if (HAVE_SOVERSION)
295
+ set_target_properties (torch_python PROPERTIES
296
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
297
+ endif ()
294
298
add_dependencies (torch_python torch_python_stubs)
295
299
296
300
# Required workaround for generated sources
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ else()
23
23
endif ()
24
24
25
25
add_library (shm SHARED core.cpp)
26
+ if (HAVE_SOVERSION)
27
+ set_target_properties (shm PROPERTIES
28
+ VERSION ${TORCH_VERSION} SOVERSION ${TORCH_SOVERSION} )
29
+ endif ()
26
30
27
31
target_include_directories (shm PUBLIC
28
32
${CMAKE_BINARY_DIR} /aten/src # provides "ATen/TypeExtendedInterface.h" to ATen.h
You can’t perform that action at this time.
0 commit comments