d-bahr / CRCpp

Easy to use and fast C++ CRC library.
Other
337 stars 91 forks source link

Cmake and vcpkg support? #15

Closed vebjornjr closed 2 years ago

vebjornjr commented 2 years ago

Even though this is a header-only library, it would be nice to be able to get it from vcpkg for simpler updating and versioning.

Do you have any experience with Cmake and vcpkg? I'm just starting to use it myself so I'm not sure I will manage to implement it on my own, but I can try to support/test it for you? When I get more familiar with Cmake and vcpkg I can maybe give it a shot myself if you can't.

Here are some examples of eigen3 and rapidjson (which are header-only too):

https://github.com/microsoft/vcpkg/tree/master/ports/eigen3 https://github.com/microsoft/vcpkg/tree/master/ports/rapidjson https://vcpkg.readthedocs.io/en/latest/examples/packaging-github-repos/

Thank you for this excellent library!

d-bahr commented 2 years ago

I am familiar with CMake but not vcpkg. I'm willing to give vcpkg a look, but I won't have time for about a week. If you don't mind waiting a bit, I'll do some research when I get chance and report back.

vebjornjr commented 2 years ago

Yeah, no problem. No stress at all.

jhaws1982 commented 2 years ago

Using CPM (https://github.com/cpm-cmake/CPM.cmake) you can do this, even without a CMakeLists.txt here:

###############################################################################
# Bring in C++ CRC header-only API
###############################################################################
CPMAddPackage(
  NAME CRCpp
  GIT_TAG release-1.1.0.0
  GITHUB_REPOSITORY "d-bahr/CRCpp"
)
if(CRCpp_ADDED)
  add_library(CRCpp INTERFACE)
  target_include_directories(CRCpp SYSTEM INTERFACE ${CRCpp_SOURCE_DIR}/inc)
endif(CRCpp_ADDED)

A CMakeLists.txt for this would be trivial though and a welcome addition.

d-bahr commented 2 years ago

I have added CMake support in master. I'll be looking at vcpkg more in the next day or two.

d-bahr commented 2 years ago

Okay, so I took a look at vcpkg and, if my understanding is correct, port files are hosted in the vcpkg repository itself. There doesn't appear to be anything required in CRCpp to get it to support vcpkg, but a port file would need to be added to vcpkg instead, as described here: https://github.com/microsoft/vcpkg/blob/master/docs/about/faq.md#can-i-contribute-a-new-library

I don't really have a strong desire to do this myself, as I have never used vcpkg and don't think I am likely to anytime soon. But if someone else wants to contribute a port file to vcpkg, by all means, go ahead. Here is a sample to get started (untested and missing the SHA512 hash):

vcpkg_from_github(
    OUT_SOURCE_PATH SOURCE_PATH
    REPO d-bahr/CRCpp
    REF 1.1.0.0
    SHA512 0
    HEAD_REF master
)

vcpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}"
    OPTIONS
        -DBUILD_DOC:BOOL=OFF
        -DBUILD_TEST:BOOL=OFF
        -DCMAKE_INSTALL_DIR:STRING=cmake
)
vcpkg_cmake_install()

vcpkg_cmake_config_fixup(CONFIG_PATH cmake)

I plan on doing a 1.2.0.0 release soon, which will include a new CRC and CMake compatibility, so that people can start using CMake right away.

335is commented 2 years ago

I looked at using vcpkg, because I do a lot of cross platform builds (Windows server, Ubuntu) and quickly abandoned the idea. It might be fine for local development, but not friendly to build machines for various reasons, the main one being a global package directory. vcpkg is simplistic and limited. I just build my own nuget and debian packages for each open source repo and keep them in an internal "third-party" repo.

d-bahr commented 2 years ago

I tend to agree, but regardless, vcpkg support goes in their repository, not here.

CMake support is done in this commit.

Tested on Linux (Makefile) and Windows (VS 2022).