Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package export to installation #762

Open
AndrewAtAvenza opened this issue Dec 31, 2022 · 6 comments
Open

Add package export to installation #762

AndrewAtAvenza opened this issue Dec 31, 2022 · 6 comments

Comments

@AndrewAtAvenza
Copy link

I'm trying build minizip with a locally built zlib because my circumstances don't allow for an internet connection while building minizip. Minizip will basically only look for zlib with find_package or fetch it, so I've had to add package export to my local copy of zlib. But I'm not sure there's a downside to having that all the time, so maybe you add it to the CMakeLists.txt? Replace:

    install(TARGETS zlib zlibstatic
    	  EXPORT ${PROJECT_NAME}
        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )

with

    install(TARGETS zlib zlibstatic
    	  EXPORT ${PROJECT_NAME}
        RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
        ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
        LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )

    install(EXPORT ${PROJECT_NAME}
            DESTINATION "${INSTALL_LIB_DIR}/cmake/${PROJECT_NAME}"
            NAMESPACE "ZLIB::")

Or something similar at any rate! Thanks!

@Neustradamus
Copy link

@gvollant: Can you look?

@AndrewAtAvenza
Copy link
Author

I should mention: I'm not 100% sure what the generally accepted 'proper' location for the CMake package export is within the installation folder structure. I've seen in the 'lib' folder, but maybe it should go in the root in a 'cmake' folder? I honestly have no idea. So long as it's there somewhere, that's good enough for me 😄

@gvollant
Copy link
Contributor

@Neustradamus I did not write myself CMake package, no I prefer CMake expert review this change

@Neustradamus
Copy link

Neustradamus commented Dec 8, 2024

@AndrewAtAvenza: Can you look here the @Adenilson PR?

@bahaa-cpl has commented the PR too.

Linked to:

@AndrewAtAvenza
Copy link
Author

I've looked at the PR and I guess it's fine? My request had more to with adding an export confirmation step to zlib so that I could build minizip on its own (since it needs to consume zlib). I wrote my own minizip CMakeLists.txt that would consume an exported configuration. Adding it to the zlib CMake wouldn't hurt anyone (and potentially help people like me) but I'm not sure if people would want a full on minizip CMakeLists.txt included or not. Maybe?

For the record, here it is:

cmake_minimum_required(VERSION 3.21)

project(minizip C)

add_library(minizip STATIC)

target_include_directories(minizip
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
        $<INSTALL_INTERFACE:include>
        
    PRIVATE
        ../..
)

set(MINIZIP_PUBLIC_HEADERS
    crypt.h
    ioapi.h
    unzip.h
    zip.h
)

set_target_properties(minizip 
    PROPERTIES
        PUBLIC_HEADER "${MINIZIP_PUBLIC_HEADERS}"
)

target_sources(minizip
    PRIVATE
        ioapi.c
        miniunz.c
        minizip.c
        unzip.c
        zip.c
)

find_package(ZLIB REQUIRED)

target_link_libraries(minizip
    PRIVATE
        ZLIB::ZLIB
)

install(TARGETS minizip
    EXPORT 
        minizip 
    ARCHIVE DESTINATION 
        lib 
    PUBLIC_HEADER DESTINATION 
        include/minizip
)

install(EXPORT minizip
    DESTINATION 
        lib/cmake/minizip
    FILE 
        minizipConfig.cmake
    NAMESPACE 
        "MINIZIP::"
)

@AndrewAtAvenza
Copy link
Author

Probably need to add iowin32.[ch] as well as noted in the linked PR if this was going to get used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants