CMake fixes (#9595)
* Support older versions of CMake.
VERSION_GREATER_EQUAL is supported by CMake >=3.7:
https://cmake.org/cmake/help/latest/command/if.html#version-greater-equal
target_link_options() is supported by CMake >=3.13:
https://cmake.org/cmake/help/latest/command/target_link_options.html
* Use PROTOBUF_USE_DLLS and LIBPROTOC_EXPORTS for libprotoc.so shared library
Similar change for libprotobuf.so and libprotobuf-lite.so was made
in commit 5a0887fc65
.
* Make value of PROTOC_EXPORT dependent on LIBPROTOC_EXPORTS instead of LIBPROTOBUF_EXPORTS
This was probably intention, and LIBPROTOC_EXPORTS is also used above
in _MSC_VER branch.
This commit is contained in:
parent
f2002f6022
commit
1cec803182
@ -135,7 +135,7 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map
|
||||
*;
|
||||
};")
|
||||
# CheckLinkerFlag module available in CMake >=3.18.
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
|
||||
if(${CMAKE_VERSION} VERSION_GREATER 3.18 OR ${CMAKE_VERSION} VERSION_EQUAL 3.18)
|
||||
include(CheckLinkerFlag)
|
||||
check_linker_flag(CXX -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map protobuf_HAVE_LD_VERSION_SCRIPT)
|
||||
else()
|
||||
@ -206,7 +206,7 @@ else (protobuf_BUILD_SHARED_LIBS)
|
||||
# Prior to CMake 3.15, the MSVC runtime library was pushed into the same flags
|
||||
# making programmatic control difficult. Prefer the functionality in newer
|
||||
# CMake versions when available.
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.15)
|
||||
if(${CMAKE_VERSION} VERSION_GREATER 3.15 OR ${CMAKE_VERSION} VERSION_EQUAL 3.15)
|
||||
if (protobuf_MSVC_STATIC_RUNTIME)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
|
||||
else()
|
||||
|
@ -94,16 +94,20 @@ endif()
|
||||
add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC}
|
||||
${libprotobuf_lite_files} ${libprotobuf_lite_includes} ${libprotobuf_lite_rc_files})
|
||||
if(protobuf_HAVE_LD_VERSION_SCRIPT)
|
||||
target_link_options(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf-lite.map)
|
||||
if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
|
||||
target_link_options(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf-lite.map)
|
||||
elseif(protobuf_BUILD_SHARED_LIBS)
|
||||
target_link_libraries(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf-lite.map)
|
||||
endif()
|
||||
set_target_properties(libprotobuf-lite PROPERTIES
|
||||
LINK_DEPENDS ${protobuf_source_dir}/src/libprotobuf-lite.map)
|
||||
endif()
|
||||
target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(libprotobuf-lite PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(protobuf_LINK_LIBATOMIC)
|
||||
target_link_libraries(libprotobuf-lite atomic)
|
||||
target_link_libraries(libprotobuf-lite PRIVATE atomic)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
target_link_libraries(libprotobuf-lite log)
|
||||
target_link_libraries(libprotobuf-lite PRIVATE log)
|
||||
endif()
|
||||
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
|
||||
if(protobuf_BUILD_SHARED_LIBS)
|
||||
|
@ -108,19 +108,23 @@ endif()
|
||||
add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
|
||||
${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes} ${libprotobuf_rc_files})
|
||||
if(protobuf_HAVE_LD_VERSION_SCRIPT)
|
||||
target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf.map)
|
||||
if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
|
||||
target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf.map)
|
||||
elseif(protobuf_BUILD_SHARED_LIBS)
|
||||
target_link_libraries(libprotobuf PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotobuf.map)
|
||||
endif()
|
||||
set_target_properties(libprotobuf PROPERTIES
|
||||
LINK_DEPENDS ${protobuf_source_dir}/src/libprotobuf.map)
|
||||
endif()
|
||||
target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(libprotobuf PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(protobuf_WITH_ZLIB)
|
||||
target_link_libraries(libprotobuf ${ZLIB_LIBRARIES})
|
||||
target_link_libraries(libprotobuf PRIVATE ${ZLIB_LIBRARIES})
|
||||
endif()
|
||||
if(protobuf_LINK_LIBATOMIC)
|
||||
target_link_libraries(libprotobuf atomic)
|
||||
target_link_libraries(libprotobuf PRIVATE atomic)
|
||||
endif()
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
|
||||
target_link_libraries(libprotobuf log)
|
||||
target_link_libraries(libprotobuf PRIVATE log)
|
||||
endif()
|
||||
target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
|
||||
if(protobuf_BUILD_SHARED_LIBS)
|
||||
|
@ -132,12 +132,16 @@ endif()
|
||||
add_library(libprotoc ${protobuf_SHARED_OR_STATIC}
|
||||
${libprotoc_files} ${libprotoc_headers} ${libprotoc_rc_files})
|
||||
if(protobuf_HAVE_LD_VERSION_SCRIPT)
|
||||
target_link_options(libprotoc PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotoc.map)
|
||||
if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13)
|
||||
target_link_options(libprotoc PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotoc.map)
|
||||
elseif(protobuf_BUILD_SHARED_LIBS)
|
||||
target_link_libraries(libprotoc PRIVATE -Wl,--version-script=${protobuf_source_dir}/src/libprotoc.map)
|
||||
endif()
|
||||
set_target_properties(libprotoc PROPERTIES
|
||||
LINK_DEPENDS ${protobuf_source_dir}/src/libprotoc.map)
|
||||
endif()
|
||||
target_link_libraries(libprotoc libprotobuf)
|
||||
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
|
||||
target_link_libraries(libprotoc PRIVATE libprotobuf)
|
||||
if(protobuf_BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(libprotoc
|
||||
PUBLIC PROTOBUF_USE_DLLS
|
||||
PRIVATE LIBPROTOC_EXPORTS)
|
||||
|
@ -454,7 +454,7 @@
|
||||
# else
|
||||
# define PROTOC_EXPORT __declspec(dllimport)
|
||||
# endif // defined(LIBPROTOC_EXPORTS)
|
||||
#elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
|
||||
#elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOC_EXPORTS)
|
||||
# define PROTOC_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
# define PROTOC_EXPORT
|
||||
|
Loading…
Reference in New Issue
Block a user