Allow using cppcodec as a CMake dependency #76

Merged
jpetso merged 2 commits from modern-cmake into master 2022-09-06 13:42:09 -05:00
jpetso commented 2022-08-21 12:20:17 -05:00 (Migrated from github.com)

A continuation/refinement of PR #73, which does not get updates as the author wasn't the submitter of the PR. This PR I can change and hopefully merge.

This makes CMakeLists.txt suitable for inclusion into a
parent CMake project via add_subdirectory() command,
and defines the cppcodec target as INTERFACE library.
Use it in a target_link_libraries() command as dependency
in order to add cppcodec's include directories to your target.

The minimum CMake requirement is now 3.13, picking up various
improvements to INTERFACE library targets and avoiding any
confusion around CMake policy CMP0076, a behavior changed in 3.13.

The CMake build will now build tests, examples and tools if built
stand-alone, but exclude them if built as part of another project.
This can be customized via CPPCODEC_BUILD_{TESTING,EXAMPLES,TOOLS}
CMake definitions for a given build.

Fixes #60
Fixes #61

This commit is based on changes by Quintz Gábor (@quiga on GitHub),
but modified and extended in a number of ways.

Thanks also to Aditya Gupta (@adi-g15), anonymous @ghuser404
and Kingsley Chen (@kingsamchen) for keeping this issue on
my radar and providing valuable feedback.

Includes an extra commit for standard CMake formatting with gersemi. The main commit changes only lines with semantic differences.

A continuation/refinement of PR #73, which does not get updates as the author wasn't the submitter of the PR. This PR I can change and hopefully merge. This makes CMakeLists.txt suitable for inclusion into a parent CMake project via `add_subdirectory()` command, and defines the `cppcodec` target as `INTERFACE` library. Use it in a `target_link_libraries()` command as dependency in order to add cppcodec's include directories to your target. The minimum CMake requirement is now 3.13, picking up various improvements to `INTERFACE` library targets and avoiding any confusion around CMake policy CMP0076, a behavior changed in 3.13. The CMake build will now build tests, examples and tools if built stand-alone, but exclude them if built as part of another project. This can be customized via `CPPCODEC_BUILD_{TESTING,EXAMPLES,TOOLS}` CMake definitions for a given build. Fixes #60 Fixes #61 This commit is based on changes by Quintz Gábor (@quiga on GitHub), but modified and extended in a number of ways. Thanks also to Aditya Gupta (@adi-g15), anonymous @ghuser404 and Kingsley Chen (@kingsamchen) for keeping this issue on my radar and providing valuable feedback. Includes an extra commit for standard CMake formatting with gersemi. The main commit changes only lines with semantic differences.
CorvetteCole commented 2022-08-24 19:42:12 -05:00 (Migrated from github.com)

this works wonderfully, I am looking forward to it being merged

this works wonderfully, I am looking forward to it being merged
adi-g15 commented 2022-08-25 05:13:35 -05:00 (Migrated from github.com)

Works fine as a git submodule, with add_subdirectory in CMakeLists.txt now :D

Test repo: https://github.com/adi-g15/tmp-pr-fix/tree/modern-cmake

Thanks for implementing this 😅

Works fine as a git submodule, with `add_subdirectory` in `CMakeLists.txt` now :D > Test repo: https://github.com/adi-g15/tmp-pr-fix/tree/modern-cmake Thanks for implementing this :sweat_smile:
CorvetteCole commented 2022-08-25 07:39:45 -05:00 (Migrated from github.com)

I'm using it via CMake's fetchcontent:

# fetch cppcodec
# use fork for now, check https://github.com/tplgy/cppcodec/pull/76
FetchContent_Declare(
        cppcodec
        GIT_REPOSITORY https://github.com/jpetso/cppcodec # this is the upstream: https://github.com/tplgy/cppcodec.git
        GIT_TAG 2053efc5b5c6ec85b8ae49389d794cff410949a0
)
FetchContent_MakeAvailable(cppcodec)
I'm using it via CMake's fetchcontent: ``` # fetch cppcodec # use fork for now, check https://github.com/tplgy/cppcodec/pull/76 FetchContent_Declare( cppcodec GIT_REPOSITORY https://github.com/jpetso/cppcodec # this is the upstream: https://github.com/tplgy/cppcodec.git GIT_TAG 2053efc5b5c6ec85b8ae49389d794cff410949a0 ) FetchContent_MakeAvailable(cppcodec) ```
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-tplgy/cppcodec!76
No description provided.