Commit 0dca3cc5 authored by Feng Xiao's avatar Feng Xiao Committed by GitHub

Merge pull request #1865 from podsvirov/topic-cmake-project

CMake: Improvements and Bugfixes
parents dedd8aec eefd1fdd
...@@ -86,6 +86,7 @@ if (CMAKE_USE_PTHREADS_INIT) ...@@ -86,6 +86,7 @@ if (CMAKE_USE_PTHREADS_INIT)
add_definitions(-DHAVE_PTHREAD) add_definitions(-DHAVE_PTHREAD)
endif (CMAKE_USE_PTHREADS_INIT) endif (CMAKE_USE_PTHREADS_INIT)
set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB) if (protobuf_WITH_ZLIB)
find_package(ZLIB) find_package(ZLIB)
if (ZLIB_FOUND) if (ZLIB_FOUND)
...@@ -96,6 +97,7 @@ if (protobuf_WITH_ZLIB) ...@@ -96,6 +97,7 @@ if (protobuf_WITH_ZLIB)
# Using imported target if exists # Using imported target if exists
if (TARGET ZLIB::ZLIB) if (TARGET ZLIB::ZLIB)
set(ZLIB_LIBRARIES ZLIB::ZLIB) set(ZLIB_LIBRARIES ZLIB::ZLIB)
set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()")
endif (TARGET ZLIB::ZLIB) endif (TARGET ZLIB::ZLIB)
else (ZLIB_FOUND) else (ZLIB_FOUND)
set(HAVE_ZLIB 0) set(HAVE_ZLIB 0)
......
...@@ -56,7 +56,10 @@ set(libprotobuf_files ...@@ -56,7 +56,10 @@ set(libprotobuf_files
add_library(libprotobuf ${protobuf_SHARED_OR_STATIC} add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
${libprotobuf_lite_files} ${libprotobuf_files}) ${libprotobuf_lite_files} ${libprotobuf_files})
target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT})
if(protobuf_WITH_ZLIB)
target_link_libraries(libprotobuf ${ZLIB_LIBRARIES})
endif()
target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src) target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS) if(MSVC AND protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf target_compile_definitions(libprotobuf
......
# User options # User options
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
# Depend packages
@_protobuf_FIND_ZLIB@
# Imported targets # Imported targets
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")
......
...@@ -147,7 +147,6 @@ function(_protobuf_find_libraries name filename) ...@@ -147,7 +147,6 @@ function(_protobuf_find_libraries name filename)
LOCATION_RELEASE) LOCATION_RELEASE)
get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename} get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename}
LOCATION_DEBUG) LOCATION_DEBUG)
endif()
select_library_configurations(${name}) select_library_configurations(${name})
set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE) set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment