title: Statically linking boost in cmake undefined zlib issues
body: <p>I am attempting to link a large cmake project statically with latest boost 1.70 (not using the cmake package) however I am getting an undefined ref for zlib. This works fine with dynamic linking but I specifically need static.</p>
  
  <p>I've attempted moving the order of my boost components, specifically adding zlib as a target lib and a number of config options ive read online but no joy !</p>
  
  <p><em>CMAKE FILE</em></p>
  
  <pre><code>cmake_minimum_required(VERSION 3.10)
  project(dummy)
  # =========================== Make Flag Setup ============================
  set(CMAKE_CXX_STANDARD 17)
  set(CMAKE_CXX_EXTENSIONS OFF)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  set(CMAKE_CXX_FLAGS          "-static -Wall -Wno-deprecated-declarations -fPIC ")
  set(CMAKE_CXX_FLAGS_DEBUG    "-O0 -g")
  set(CMAKE_CXX_FLAGS_RELEASE  "-O3 -fpermissive")
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  
  # ========================== Third Party Deps ============================
  set(Boost_NO_BOOST_CMAKE     ON)
  set(Boost_USE_MULTITHREADED  ON)
  set(Boost_USE_STATIC_RUNTIME ON)
  set(Boost_USE_STATIC_LIBS    ON)
  find_package(Boost 1.70.0 REQUIRED COMPONENTS locale exception serialization system timer regex
                                                thread program_options chrono filesystem iostreams)
  include_directories(${Boost_INCLUDE_DIRS} SYSTEM)
  include_directories(.)
  include_directories(src)
  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/proto)
  
  # ============================== Build Exe ==============================
  file(GLOB_RECURSE all_src src/**.cpp)
  add_executable(dummy ${all_src})
  target_link_libraries(dummy ${Boost_LIBRARIES} pthread maxminddb crypto ssl pthread xerces-c cdb aerospike proto z)
  </code></pre>
  
  <p><em>ld error</em></p>
  
  <pre><code>usr/lib/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::after(char const*&amp;, char*&amp;, bool)':
  zlib.cpp:(.text+0x108): undefined reference to `crc32'
  /usr/lib/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::reset(bool, bool)':
  zlib.cpp:(.text+0x181): undefined reference to `deflateReset'
  zlib.cpp:(.text+0x196): undefined reference to `inflateEnd'
  zlib.cpp:(.text+0x1a9): undefined reference to `inflateReset'
  zlib.cpp:(.text+0x1c1): undefined reference to `deflateEnd'
  /usr/lib/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::do_init(boost::iostreams::zlib_params const&amp;, bool, void* (*)(void*, unsigned int, unsigned int), void (*)(void*, void*), void*)':
  zlib.cpp:(.text+0x3c4): undefined reference to `inflateInit2_'
  zlib.cpp:(.text+0x412): undefined reference to `deflateInit2_'
  /usr/lib/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::xdeflate(int)':
  zlib.cpp:(.text+0x154): undefined reference to `deflate'
  /usr/lib/libboost_iostreams.a(zlib.o): In function `boost::iostreams::detail::zlib_base::xinflate(int)':
  zlib.cpp:(.text+0x164): undefined reference to `inflate'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>As with the comment suggestion I tried using the findzlib.cmake package, I even downloaded and compiled the latest version of zlib (1.2.11) as maybe that might work better with the version of boost I have (1.70)</p>
  
  <pre><code>find_package(ZLIB REQUIRED)
  message(ZLIB_INCLUDE   - [${ZLIB_INCLUDE_DIRS}])
  message(ZLIB_FOUND     - [${ZLIB_FOUND}])
  message(ZLIB_LIBRARIES - [${ZLIB_LIBRARIES}])
  ...
  target_link_libraries(dummy ${Boost_LIBRARIES} pthread maxminddb crypto ssl pthread xerces-c cdb aerospike proto ${ZLIB_LIBRARIES})
  </code></pre>
  
  <pre><code>-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
  ZLIB_INCLUDE   - [/usr/include]
  ZLIB_FOUND     - [TRUE]
  ZLIB_LIBRARIES - [/usr/lib/x86_64-linux-gnu/libz.so]
  </code></pre>
  
  <p>And I still get the same linker error, the library it finds is a shared object and the cmake package doesn't seem to have an option for the static lib option. </p>