Created
August 12, 2020 09:29
-
-
Save jc-lab/d65d7d91f49c2664c943364981bad3e0 to your computer and use it in GitHub Desktop.
CMake ZLIB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IN MAIN PROJECT | |
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | |
# ExternalZlib.cmake | |
FetchContent_Declare( | |
zlib | |
GIT_REPOSITORY https://github.com/madler/zlib.git | |
GIT_TAG v1.2.11 | |
) | |
FetchContent_GetProperties(zlib) | |
if (NOT zlib_POPULATED) | |
FetchContent_Populate(zlib) | |
add_subdirectory(${zlib_SOURCE_DIR} ${zlib_BINARY_DIR}) | |
endif() | |
message("zlib_SOURCE_DIR = ${zlib_SOURCE_DIR}") | |
target_include_directories(zlibstatic | |
INTERFACE | |
$<INSTALL_INTERFACE:include> | |
$<BUILD_INTERFACE:${zlib_SOURCE_DIR}> | |
$<BUILD_INTERFACE:${zlib_BINARY_DIR}> | |
) | |
#add_library(ZLIB::zlibstatic ALIAS zlibstatic) | |
#add_library(ZLIB::ZLIB ALIAS zlibstatic) | |
message("CMAKE_CURRENT_LIST_DIR => ${CMAKE_CURRENT_LIST_DIR}") | |
install(TARGETS zlibstatic EXPORT zlibstatic-targets | |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT zlibstatic | |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT zlibstatic | |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT zlibstatic | |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ZLIB | |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ZLIB | |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ZLIB) | |
#install(TARGETS zlibstatic EXPORT zlibstatic-targets | |
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ZLIB | |
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ZLIB | |
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ZLIB) | |
#set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files") | |
set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_CURRENT_BINARY_DIR}) | |
#if(NOT MSVC) | |
# set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/zlib" CACHE STRING "${_cmakedir_desc}") | |
#else() | |
# set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}") | |
#endif() | |
#mark_as_advanced(CMAKE_INSTALL_CMAKEDIR) | |
export(TARGETS zlibstatic | |
NAMESPACE ZLIB:: | |
FILE ${CMAKE_INSTALL_CMAKEDIR}/zlibstatic-targets.cmake | |
) | |
install(EXPORT zlibstatic-targets | |
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" | |
NAMESPACE ZLIB:: | |
COMPONENT zlibstatic-export) | |
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/ | |
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" | |
COMPONENT zlibstatic-export | |
PATTERN zlibstatic-targets.cmake EXCLUDE | |
) | |
include(CMakePackageConfigHelpers) | |
configure_package_config_file( | |
"zlibstatic-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/zlibstatic-config.cmake" | |
INSTALL_DESTINATION "./" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(ZLIB_FOUND TRUE) | |
message("FINDZLIB CALLED // ${THIRDPARTY_BINARY_DIR}/zlibstatic-targets.cmake") | |
if (EXISTS "${THIRDPARTY_BINARY_DIR}/zlibstatic-targets.cmake") | |
set(ZLIB_LIBRARIES ZLIB::ZLIB) | |
message("FINDZLIB: HAS TARGET!") | |
include("${THIRDPARTY_BINARY_DIR}/zlibstatic-targets.cmake") | |
if (NOT TARGET ZLIB::ZLIB) | |
add_library(ZLIB::ZLIB STATIC IMPORTED) | |
get_target_property(ZLIB_INTERFACE_INCLUDE_DIRECTORIES ZLIB::zlibstatic INTERFACE_INCLUDE_DIRECTORIES) | |
get_target_property(ZLIB_IMPORTED_LOCATION_DEBUG ZLIB::zlibstatic IMPORTED_LOCATION_DEBUG) | |
get_target_property(ZLIB_IMPORTED_LOCATION_RELEASE ZLIB::zlibstatic IMPORTED_LOCATION_RELEASE) | |
get_target_property(ZLIB_IMPORTED_LOCATION_RELWITHDEBINFO ZLIB::zlibstatic IMPORTED_LOCATION_RELWITHDEBINFO) | |
get_target_property(ZLIB_IMPORTED_LOCATION ZLIB::zlibstatic IMPORTED_LOCATION) | |
set_target_properties(ZLIB::ZLIB PROPERTIES | |
INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INTERFACE_INCLUDE_DIRECTORIES}" | |
) | |
if(ZLIB_IMPORTED_LOCATION_RELEASE) | |
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY | |
IMPORTED_CONFIGURATIONS RELEASE) | |
set_target_properties(ZLIB::ZLIB PROPERTIES | |
IMPORTED_LOCATION_RELEASE "${ZLIB_IMPORTED_LOCATION_RELEASE}") | |
endif() | |
if(ZLIB_IMPORTED_LOCATION_DEBUG) | |
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY | |
IMPORTED_CONFIGURATIONS DEBUG) | |
set_target_properties(ZLIB::ZLIB PROPERTIES | |
IMPORTED_LOCATION_DEBUG "${ZLIB_IMPORTED_LOCATION_DEBUG}") | |
endif() | |
if(NOT ZLIB_IMPORTED_LOCATION_RELEASE AND NOT ZLIB_IMPORTED_LOCATION_DEBUG) | |
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY | |
IMPORTED_LOCATION "${ZLIB_IMPORTED_LOCATION}") | |
endif() | |
endif() | |
else() | |
set(ZLIB_LIBRARIES zlibstatic) | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment