Skip to content

Commit

Permalink
CMake: Rename example{,64} -> zlib_example{,64}
Browse files Browse the repository at this point in the history
Also adds `ZLIB_ENABLE_EXAMPLES` option to control whether those
targets are added.

This is helpful when including zlib as a sub-project, since the CMake
target namespace is global.
  • Loading branch information
jbms committed Oct 4, 2022
1 parent 21767c6 commit 13cb983
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(VERSION "1.2.12")

option(ASM686 "Enable building i686 assembly implementation")
option(AMD64 "Enable building amd64 assembly implementation")
option(ZLIB_ENABLE_EXAMPLES "Build examples" OFF)

set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
Expand Down Expand Up @@ -230,20 +231,22 @@ endif()
# Example binaries
#============================================================================

add_executable(example test/example.c)
target_link_libraries(example zlib)
add_test(example example)
if(ZLIB_ENABLE_EXAMPLES)
add_executable(zlib_example test/example.c)
target_link_libraries(zlib_example zlib)
add_test(zlib_example zlib_example)

add_executable(minigzip test/minigzip.c)
target_link_libraries(minigzip zlib)
add_executable(minigzip test/minigzip.c)
target_link_libraries(minigzip zlib)

if(HAVE_OFF64_T)
add_executable(example64 test/example.c)
target_link_libraries(example64 zlib)
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
add_test(example64 example64)

add_executable(minigzip64 test/minigzip.c)
target_link_libraries(minigzip64 zlib)
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
if(HAVE_OFF64_T)
add_executable(zlib_example64 test/example.c)
target_link_libraries(zlib_example64 zlib)
set_target_properties(zlib_example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
add_test(zlib_example64 zlib_example64)

add_executable(minigzip64 test/minigzip.c)
target_link_libraries(minigzip64 zlib)
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
endif()
endif()

0 comments on commit 13cb983

Please sign in to comment.