Integrating
How to embed Plugify into your own projects.
Plugify is designed to be easily integrated into your projects, whether you're building a game modding platform, a standalone application, or a plugin-based system. This guide will walk you through the process of integrating Plugify into your project using CMake, covering both external and embedded integration methods.
Integration Methods
1. External Integration
To use Plugify as an external library, you can locate it directly with find_package()
in your CMake project. This method is ideal if you want to keep Plugify as a separate dependency.
Example:
2. Embedded Integration
If you prefer to embed Plugify directly into your project, you can include the entire source tree as a subdirectory. This method is useful if you want to customize or extend Plugify's functionality.
Example:
3. Embedded Integration with FetchContent
For projects using CMake 3.11 or later, you can use the FetchContent
module to automatically download and integrate Plugify at configure time.
Example:
Note: The URL approach is recommended for stable releases. For more details, see the FetchContent documentation.
4. Supporting Both External and Embedded Integration
If you want your project to support both external and embedded integration, you can use the following pattern:
Top-Level
Thirdparty
In this setup, thirdparty/plugify
should contain a complete copy of the Plugify source tree.
Example: Initializing Plugify in Your Application
Once integrated, you can initialize Plugify in your application as follows:
Best Practices
- Use Consistent Build Environments:
- Ensure that Plugify and your project are built with the same compiler and C++ version to avoid compatibility issues.
- Disable Unnecessary Features:
- If you don’t need tests or documentation, disable them using CMake options like
PLUGIFY_BUILD_TESTS
andPLUGIFY_BUILD_DOCS
.
- If you don’t need tests or documentation, disable them using CMake options like
- Handle Errors Gracefully:
- Always check the return values of Plugify's initialization and management functions to handle errors effectively.
- Use FetchContent for Stable Releases:
- When using
FetchContent
, prefer downloading stable releases from GitHub to ensure compatibility and reliability.
- When using
Troubleshooting
- Missing Packages: If the Package Manager reports missing packages, ensure that the required packages are available in the configured directories or repositories.
- Conflicted Packages: Resolve conflicts by uninstalling or updating the conflicting packages.
- Build Errors: Verify that your CMake configuration matches Plugify's requirements (e.g., C++20, compatible compilers).