LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()

add_executable(unshield "unshield.c")
target_link_libraries(unshield libunshield)
if(WIN32)
    if(HAVE_ICONV)
        target_link_libraries(unshield iconv)
    endif()
    target_link_libraries(unshield z)
endif()

add_executable(unshield-deobfuscate "unshield-deobfuscate.c")
target_link_libraries(unshield-deobfuscate libunshield)
if(WIN32)
    target_link_libraries(unshield-deobfuscate z)
endif()

if(BUILD_STATIC AND MSVC)
    set_msvc_runtime_static()
endif()

install(TARGETS unshield RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()

add_executable(unshield "unshield.c")
target_link_libraries(unshield libunshield)
if(WIN32)
    if(HAVE_ICONV)
        target_link_libraries(unshield iconv)
    endif()
    target_link_libraries(unshield ${ZLIB_LIBRARIES})
endif()

add_executable(unshield-deobfuscate "unshield-deobfuscate.c")
target_link_libraries(unshield-deobfuscate libunshield)
if(WIN32)
    target_link_libraries(unshield-deobfuscate ${ZLIB_LIBRARIES})
endif()

if(BUILD_STATIC AND MSVC)
    set_msvc_runtime_static()
endif()

install(TARGETS unshield RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

Use zlib library name as provided by find_package
Use zlib library name as provided by find_package

find_package(X) sets a variable X_LIBRARIES that can be used to refer to
found library, making it compatible with multiple providers of
libraries that might name the package differently, e.g. scoop and vcpkg
