Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
ZLIB: Update documentation and example
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslo committed May 26, 2019
1 parent c2075c0 commit 51e6b30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
16 changes: 12 additions & 4 deletions docs/packages/pkg/ZLIB.rst
Expand Up @@ -13,8 +13,16 @@ ZLIB
- `Hunterized <https://github.com/hunter-packages/zlib/tree/hunter>`__
- `Example <https://github.com/ruslo/hunter/blob/master/examples/ZLIB/CMakeLists.txt>`__

.. code-block:: cmake
.. literalinclude:: /../examples/ZLIB/CMakeLists.txt
:language: cmake
:start-after: # DOCUMENTATION_START {
:end-before: # DOCUMENTATION_END }

hunter_add_package(ZLIB)
find_package(ZLIB CONFIG REQUIRED)
target_link_libraries(... ZLIB::zlib)
For compatibility with
`FindZLIB <https://cmake.org/cmake/help/latest/module/FindZLIB.html>`__
module, the ``ALIAS`` target ``ZLIB::ZLIB`` can be used too:

.. literalinclude:: /../examples/ZLIB/CMakeLists.txt
:language: cmake
:start-after: # DOCUMENTATION_START_1 {
:end-before: # DOCUMENTATION_END_1 }
29 changes: 9 additions & 20 deletions examples/ZLIB/CMakeLists.txt
@@ -1,34 +1,23 @@
# Copyright (c) 2014, Ruslan Baratov
# All rights reserved.

cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.2)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-zlib)

# download gtest
# DOCUMENTATION_START {
hunter_add_package(ZLIB)

# now gtest can be used
find_package(ZLIB CONFIG REQUIRED)

add_executable(foo main.c)
target_link_libraries(foo ZLIB::zlib)

# Compatibility mode
find_package(ZLIB REQUIRED)
string(COMPARE EQUAL "${ZLIB_INCLUDE_DIRS}" "" is_empty)
if(is_empty)
message(FATAL_ERROR "Expected non-empty")
endif()

string(COMPARE EQUAL "${ZLIB_LIBRARIES}" "ZLIB::zlib" is_good)
if(NOT is_good)
message(FATAL_ERROR "Expected ZLIB::zlib but not ${ZLIB_LIBRARIES}")
endif()
add_executable(boo main.c)
target_link_libraries(boo PRIVATE ZLIB::zlib)
# DOCUMENTATION_END }

include_directories("${ZLIB_INCLUDE_DIRS}")
target_link_libraries(foo ${ZLIB_LIBRARIES})
# DOCUMENTATION_START_1 {
add_executable(baz main.c)
target_link_libraries(baz PRIVATE ZLIB::ZLIB)
# DOCUMENTATION_END_1 }

0 comments on commit 51e6b30

Please sign in to comment.