nefarius / ViGEmClient

ViGEm Client SDK for feeder development.
https://docs.nefarius.at/projects/ViGEm/
MIT License
134 stars 65 forks source link

CMake: Setup for find_package and pkg-config #32

Closed mnerv closed 1 year ago

mnerv commented 1 year ago

Configure CMake to generate the required config files for fing_package to work.

Usage:

find_package(ViGEmClient REQUIRED)

# Static linking
target_link_libraries(main PRIVATE ViGEmClient::ViGEmClient)

# Dynamic linking
target_link_libraries(main PRIVATE ViGEmClient::ViGEmClientShared)

pkg-config generation doesn't work as expected when installing it with --prefix flag. The $prefix and $exec_prefix of the generated pc file still contain the default value. This will be fine if installed normally.

To compile and generate the required file for CMake use

cmake -S . -Bbuild

You can later use the command below to build a release version or use cmake --open build to open it in Visual Studio to build. The command below just uses MSBuild in the background and --config Debug flag can be passed to generate a debug build.

cmake --build build --config Release

For installation you can use

cmake --install build

Not that this requires admin privileges because it tries to install it at C:\Program (x86)\ViGEmClient directory. This can be overridden with --prefix flags to specify other locations.

To make find_package works you need to have the path to where ViGEmClientConfig.cmake file is generated in an environment variable list called CMAKE_PREFIX_PATH, this tells cmake where to find the library. If the library is installed at the default location then it should be located at C:\Program Files (x86)\ViGEmClient\lib\cmake\ViGEmClient. Just append this path to the environment variable and it should work.

As I'm still new to cmake the location might not be 100% correct but it serves as a start :)

nefarius commented 1 year ago

Thank you!