David L. Jones | 74b2c7c | 2022-05-31 16:16:02 -0700 | [diff] [blame] | 1 | # CMake definitions for libprotobuf (the "full" C++ protobuf runtime). |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 2 | |
David L. Jones | 74b2c7c | 2022-05-31 16:16:02 -0700 | [diff] [blame] | 3 | include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) |
Carlos O'Ryan | 4ad5f54 | 2023-05-30 14:55:26 -0700 | [diff] [blame] | 4 | include(${protobuf_SOURCE_DIR}/cmake/protobuf-configure-target.cmake) |
Dennis Cappendijk | 4eb02fe | 2017-05-29 17:34:08 +0200 | [diff] [blame] | 5 | |
Konstantin Podsvirov | c3aa4c2 | 2015-10-15 02:56:48 +0300 | [diff] [blame] | 6 | add_library(libprotobuf ${protobuf_SHARED_OR_STATIC} |
David L. Jones | 74b2c7c | 2022-05-31 16:16:02 -0700 | [diff] [blame] | 7 | ${libprotobuf_srcs} |
| 8 | ${libprotobuf_hdrs} |
| 9 | ${protobuf_version_rc_file}) |
Arfrever | 1d13b60 | 2022-03-02 02:06:14 +0100 | [diff] [blame] | 10 | if(protobuf_HAVE_LD_VERSION_SCRIPT) |
Adam Cozzette | b20209f | 2022-03-10 18:36:42 +0000 | [diff] [blame] | 11 | 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() |
Arfrever | 1d13b60 | 2022-03-02 02:06:14 +0100 | [diff] [blame] | 16 | set_target_properties(libprotobuf PROPERTIES |
Adam Cozzette | b20209f | 2022-03-10 18:36:42 +0000 | [diff] [blame] | 17 | LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotobuf.map) |
Arfrever | 1d13b60 | 2022-03-02 02:06:14 +0100 | [diff] [blame] | 18 | endif() |
Adam Cozzette | b20209f | 2022-03-10 18:36:42 +0000 | [diff] [blame] | 19 | target_link_libraries(libprotobuf PRIVATE ${CMAKE_THREAD_LIBS_INIT}) |
Konstantin Podsvirov | 38c5f2f | 2016-07-28 01:28:49 +0300 | [diff] [blame] | 20 | if(protobuf_WITH_ZLIB) |
Adam Cozzette | b20209f | 2022-03-10 18:36:42 +0000 | [diff] [blame] | 21 | target_link_libraries(libprotobuf PRIVATE ${ZLIB_LIBRARIES}) |
boscosiu | 55ed1d4 | 2019-07-03 06:34:09 -0700 | [diff] [blame] | 22 | endif() |
| 23 | if(protobuf_LINK_LIBATOMIC) |
Adam Cozzette | b20209f | 2022-03-10 18:36:42 +0000 | [diff] [blame] | 24 | target_link_libraries(libprotobuf PRIVATE atomic) |
Konstantin Podsvirov | 38c5f2f | 2016-07-28 01:28:49 +0300 | [diff] [blame] | 25 | endif() |
RPG3D | 6aaa40f | 2020-03-08 19:35:07 +0800 | [diff] [blame] | 26 | if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") |
Adam Cozzette | 1ddad63 | 2022-03-10 18:44:16 +0000 | [diff] [blame] | 27 | target_link_libraries(libprotobuf PRIVATE log) |
RPG3D | 6aaa40f | 2020-03-08 19:35:07 +0800 | [diff] [blame] | 28 | endif() |
Mike Kruskal | 6898451 | 2024-03-19 20:13:17 -0700 | [diff] [blame] | 29 | target_include_directories(libprotobuf PUBLIC |
| 30 | $<BUILD_INTERFACE:${protobuf_SOURCE_DIR}/src> |
| 31 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 32 | ) |
Harald Fernengel | f718818 | 2022-09-02 17:23:07 +0200 | [diff] [blame] | 33 | target_link_libraries(libprotobuf PUBLIC ${protobuf_ABSL_USED_TARGETS}) |
Carlos O'Ryan | 4ad5f54 | 2023-05-30 14:55:26 -0700 | [diff] [blame] | 34 | protobuf_configure_target(libprotobuf) |
appledragon | 5a0887f | 2022-02-08 07:50:16 +0800 | [diff] [blame] | 35 | if(protobuf_BUILD_SHARED_LIBS) |
Konstantin Podsvirov | c3aa4c2 | 2015-10-15 02:56:48 +0300 | [diff] [blame] | 36 | target_compile_definitions(libprotobuf |
| 37 | PUBLIC PROTOBUF_USE_DLLS |
| 38 | PRIVATE LIBPROTOBUF_EXPORTS) |
| 39 | endif() |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 40 | set_target_properties(libprotobuf PROPERTIES |
Corentin Le Molgat | 3bc0282 | 2018-01-29 15:11:59 +0100 | [diff] [blame] | 41 | VERSION ${protobuf_VERSION} |
Konstantin Podsvirov | f397ede | 2015-09-17 13:00:12 +0300 | [diff] [blame] | 42 | OUTPUT_NAME ${LIB_PREFIX}protobuf |
Mike Kruskal | 983fc2d | 2022-11-02 23:24:26 -0700 | [diff] [blame] | 43 | 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 Molgat | f7a0584 | 2018-01-29 15:13:23 +0100 | [diff] [blame] | 49 | add_library(protobuf::libprotobuf ALIAS libprotobuf) |
Mike Kruskal | 407aa2d | 2022-10-19 16:10:10 -0700 | [diff] [blame] | 50 | |
Mike Kruskal | 407aa2d | 2022-10-19 16:10:10 -0700 | [diff] [blame] | 51 | target_link_libraries(libprotobuf PRIVATE utf8_validity) |