Skip to content

Commit

Permalink
Fix compilation with BUILD_SHARED_LIBS=ON on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Nov 6, 2023
1 parent b86cc54 commit e7719fd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ function(RELATIVE_PROTOBUF_GENERATE_CPP NAME SRCS HDRS ROOT_DIR DEPEND)
return()
endif()

# Add ONNX_API prefix to protobuf classes and methods in all cases
set(ONNX_DLLEXPORT_STR "dllexport_decl=ONNX_API:")
# Add ONNX_PROTO_API prefix to protobuf classes and methods in all cases
set(ONNX_DLLEXPORT_STR "dllexport_decl=ONNX_PROTO_API:")

set(${SRCS})
set(${HDRS})
Expand Down Expand Up @@ -489,17 +489,20 @@ if (MSVC)
set(EXTRA_FLAGS "")
endif()
if (BUILD_SHARED_LIBS OR ONNX_BUILD_MAIN_LIB)
set(ONNX_API_DEFINE "-DONNX_API=__declspec(dllexport)")
set(ONNX_PROTO_API_DEFINE "-DONNX_PROTO_API=__declspec(dllexport)")
set(ONNX_PROTO_API_DEFINE_EXTERNAL "-DONNX_PROTO_API=__declspec(dllimport)")
else()
set(ONNX_API_DEFINE "-DONNX_API=")
set(ONNX_PROTO_API_DEFINE "-DONNX_PROTO_API=")
endif()
else()
# On non-Windows, hide all symbols we don't need
set(ONNX_API_DEFINE "-DONNX_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
set(ONNX_PROTO_API_DEFINE "-DONNX_PROTO_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
set(ONNX_PROTO_API_DEFINE_EXTERNAL "-DONNX_PROTO_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)")
set_target_properties(onnx_proto PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(onnx_proto PROPERTIES VISIBILITY_INLINES_HIDDEN 1)
endif()
target_compile_definitions(onnx_proto PRIVATE ${ONNX_API_DEFINE})
target_compile_definitions(onnx_proto PRIVATE ${ONNX_PROTO_API_DEFINE})
target_compile_definitions(onnx_proto INTERFACE ${ONNX_PROTO_API_DEFINE_EXTERNAL})

if(ONNX_USE_LITE_PROTO)
if(TARGET protobuf::libprotobuf-lite)
Expand Down

0 comments on commit e7719fd

Please sign in to comment.