blob: 11c09b1bc0e128209f1a7573a8cf7ea4a9e05e5e [file] [log] [blame]
David L. Jones74b2c7c2022-05-31 16:16:02 -07001# CMake definitions for libprotobuf (the "full" C++ protobuf runtime).
Feng Xiao4333edb2015-05-31 02:28:34 -07002
David L. Jones74b2c7c2022-05-31 16:16:02 -07003include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)
Carlos O'Ryan4ad5f542023-05-30 14:55:26 -07004include(${protobuf_SOURCE_DIR}/cmake/protobuf-configure-target.cmake)
Dennis Cappendijk4eb02fe2017-05-29 17:34:08 +02005
Konstantin Podsvirovc3aa4c22015-10-15 02:56:48 +03006add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
David L. Jones74b2c7c2022-05-31 16:16:02 -07007 ${libprotobuf_srcs}
8 ${libprotobuf_hdrs}
9 ${protobuf_version_rc_file})
Arfrever1d13b602022-03-02 02:06:14 +010010if(protobuf_HAVE_LD_VERSION_SCRIPT)
Adam Cozzetteb20209f2022-03-10 18:36:42 +000011 if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
12 target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf.map)
13 elseif(protobuf_BUILD_SHARED_LIBS)
14 target_link_libraries(libprotobuf PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf.map)
15 endif()
Arfrever1d13b602022-03-02 02:06:14 +010016 set_target_properties(libprotobuf PROPERTIES
Adam Cozzetteb20209f2022-03-10 18:36:42 +000017 LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf.map)
Arfrever1d13b602022-03-02 02:06:14 +010018endif()
Adam Cozzetteb20209f2022-03-10 18:36:42 +000019target_link_libraries(libprotobuf PRIVATE ${CMAKE_THREAD_LIBS_INIT})
Konstantin Podsvirov38c5f2f2016-07-28 01:28:49 +030020if(protobuf_WITH_ZLIB)
Adam Cozzetteb20209f2022-03-10 18:36:42 +000021 target_link_libraries(libprotobuf PRIVATE ${ZLIB_LIBRARIES})
boscosiu55ed1d42019-07-03 06:34:09 -070022endif()
23if(protobuf_LINK_LIBATOMIC)
Adam Cozzetteb20209f2022-03-10 18:36:42 +000024 target_link_libraries(libprotobuf PRIVATE atomic)
Konstantin Podsvirov38c5f2f2016-07-28 01:28:49 +030025endif()
RPG3D6aaa40f2020-03-08 19:35:07 +080026if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
Adam Cozzette1ddad632022-03-10 18:44:16 +000027 target_link_libraries(libprotobuf PRIVATE log)
RPG3D6aaa40f2020-03-08 19:35:07 +080028endif()
Mike Kruskal68984512024-03-19 20:13:17 -070029target_include_directories(libprotobuf PUBLIC
30 $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src>
31 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
32)
Harald Fernengelf7188182022-09-02 17:23:07 +020033target_link_libraries(libprotobuf PUBLIC ${protobuf_ABSL_USED_TARGETS})
Carlos O'Ryan4ad5f542023-05-30 14:55:26 -070034protobuf_configure_target(libprotobuf)
appledragon5a0887f2022-02-08 07:50:16 +080035if(protobuf_BUILD_SHARED_LIBS)
Konstantin Podsvirovc3aa4c22015-10-15 02:56:48 +030036 target_compile_definitions(libprotobuf
37 PUBLIC PROTOBUF_USE_DLLS
38 PRIVATE LIBPROTOBUF_EXPORTS)
39endif()
Feng Xiao4333edb2015-05-31 02:28:34 -070040set_target_properties(libprotobuf PROPERTIES
Corentin Le Molgat3bc02822018-01-29 15:11:59 +010041 VERSION ${protobuf_VERSION}
Konstantin Podsvirovf397ede2015-09-17 13:00:12 +030042 OUTPUT_NAME ${LIB_PREFIX}protobuf
Mike Kruskal983fc2d2022-11-02 23:24:26 -070043 DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}"
44 # For -fvisibility=hidden and -fvisibility-inlines-hidden
45 C_VISIBILITY_PRESET hidden
46 CXX_VISIBILITY_PRESET hidden
47 VISIBILITY_INLINES_HIDDEN ON
48)
Corentin Le Molgatf7a05842018-01-29 15:13:23 +010049add_library(protobuf::libprotobuf ALIAS libprotobuf)
Mike Kruskal407aa2d2022-10-19 16:10:10 -070050
Mike Kruskal407aa2d2022-10-19 16:10:10 -070051target_link_libraries(libprotobuf PRIVATE utf8_validity)