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

cmake: Add install export set #164

Merged
merged 4 commits into from
Dec 7, 2023
Merged

Conversation

bwrsandman
Copy link
Contributor

@bwrsandman bwrsandman commented Jul 15, 2022

  • Set convert_utf as private as it is statically linked so we don't want to export it or its headers.
  • Specify libunshield include directory in install interface because it is different than in build-time
    • Removed the redundancy of installing the headers manually
  • Add unshield:: cmake namespace export set named unshieldConfig
  • Set all targets to the unshieldConfig export set

CMake config sets generate the following files:

  • ${install_dir}/lib/cmake/unshieldunshieldConfig.cmake
  • ${install_dir}/lib/cmake/unshieldunshieldConfig-${build-config}.cmake

An export set allows CMake users to more easily link with a cmake library which unshield now is.
They can now in CMake do the following:

find_package(unshield REQUIRED COMPONENTS unshield libunshield)
target_link_libraries(example PRIVATE unshield::libunshield)
add_custom_target(unshield-version COMMAND unshield::unshield -V)

Using add_custom_target(... unshield::unshield...) can be used as a dependency for another target to generate (extract) files

Also added artifact upload to the cmake tests.

Resulting tree

install
├── bin
│   └── unshield
├── include
│   └── libunshield.h
├── lib
│   ├── cmake
│   │   └── unshield
│   │       ├── unshieldConfig.cmake
│   │       └── unshieldConfig-release.cmake
│   ├── libunshield.so -> libunshield.so.0
│   ├── libunshield.so.0 -> libunshield.so.0.0.0
│   ├── libunshield.so.0.0.0
│   └── pkgconfig
│       └── libunshield.pc
└── share
    └── man
        └── man1
            └── unshield.1

ref: https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#exporting-targets

@bwrsandman
Copy link
Contributor Author

Side note, the version is set in

set_target_properties(libunshield PROPERTIES VERSION 0.0.0 SOVERSION 0)

@kratz00
Copy link
Contributor

kratz00 commented Dec 4, 2023

@bwrsandman Please resolve the conflicts and update your branch, I will have a look then, thanks in advance.

Set convert_utf as private as it is statically linked.
Specify libunshield include directory in install interface
Add unshield:: namespace export set
Set all targets to the unshieldConfig export set
@bwrsandman bwrsandman force-pushed the cmake-export-set branch 2 times, most recently from 5b2b501 to 917f3e1 Compare December 4, 2023 22:33
@bwrsandman
Copy link
Contributor Author

Here are the artifacts that the action generates.
image

Copy link
Contributor

@kratz00 kratz00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested it locally, looks good.
The only nitpick I have: Please use all uppercase for CMake variables.

src/CMakeLists.txt Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
@bwrsandman
Copy link
Contributor Author

Switched to UPPER

@twogood twogood merged commit d10852e into twogood:main Dec 7, 2023
6 checks passed
@twogood
Copy link
Owner

twogood commented Dec 7, 2023

Thank you @bwrsandman and @kratz00 !

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

Successfully merging this pull request may close these issues.

3 participants