{"id":23124858,"url":"https://github.com/caseymcc/ue4cmake","last_synced_at":"2025-04-06T01:06:34.959Z","repository":{"id":64447124,"uuid":"310726049","full_name":"caseymcc/UE4CMake","owner":"caseymcc","description":"Provides a simple way to add a cmake lib to any Unreal Engine 4 (UE4) or 5 (UE5) project.","archived":false,"fork":false,"pushed_at":"2025-03-01T15:45:57.000Z","size":90,"stargazers_count":98,"open_issues_count":5,"forks_count":18,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-30T00:06:15.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caseymcc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-06T23:17:40.000Z","updated_at":"2025-03-27T16:53:31.000Z","dependencies_parsed_at":"2025-02-27T15:19:00.254Z","dependency_job_id":"3505f41d-f521-4c2b-bcbc-254ac7e32639","html_url":"https://github.com/caseymcc/UE4CMake","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FUE4CMake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FUE4CMake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FUE4CMake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FUE4CMake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caseymcc","download_url":"https://codeload.github.com/caseymcc/UE4CMake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419859,"owners_count":20936012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-17T08:07:47.986Z","updated_at":"2025-04-06T01:06:34.930Z","avatar_url":"https://github.com/caseymcc.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![discord](https://img.shields.io/discord/495955797872869376.svg?logo=discord \"Discord\")](https://discord.gg/4AYSjfEByn)\n\n# UE4CMake\nProvides a simple way to add a cmake lib to any Unreal Engine 4 or 5 project. \n\nIt works by setting itself up as an empty plugin, this allows the `.cs` build files to generate an Assembly that will be included into your project through the plugin system.\n\n## Setup\nCopy the contents of this repo (or git submodule it) into your UE4/5 project under `Plugins/UE4CMake`. The directory naming matters as some of the build script is hard coded to use the above naming (as there is no easy way to get the specific plugin directory otherwise). The `.uplugin` file sets up a plugin with no source, however it allows the `CMakeTarget.Build.cs` file to be compiled and included with your project.\n\nIn your UE4/5 project file `.uproject` (or if you are building a plugin it should work with your `.uplugin` file) add `CMakeTarget` as a plugin as follows\n```\n    \"FileVersion\": 3,\n    ...\n    \"Plugins\": [\n\t\t{\n\t\t\t\"Name\": \"CMakeTarget\",\n\t\t\t\"Enabled\": true\n\t\t}\n\t]\n```\nThis generates the UE4CMake Assembly and links it with your build Assembly which will allow you to call the functions in the UE4CMake build scripts.\n\nFrom there you can include any modern cmake project (older cmake may/may not have issues). Just call the static function `CMakeTarget.add()` with the `TargetRules`, `ModuleRules`, `lib's cmake target name`, `location of lib` and any `cmake args`. \n\n```c++\npublic class {YourProject}:ModuleRules\n{\n    public {YourProject}(ReadOnlyTargetRules Target) : base(Target)\n    {\n        ...\n        CMakeTarget.add(Target, this, \"{lib's cmake target name}\", \"{location to cmake lib source}\", \"{cmake args}\", {bool, use system compiler});\n        ...\n    }\n}\n```\n- {lib's cmake target name} - target name in the libraries `CMakeLists.txt` file, name provided to add_library({target name})\n- {location to cmake lib source} - directory of libraries `CMakeLists.txt`, it can be relative to your projects `{Project}.Build.cs` or an absolute path (although you should generate it from something relative like, this.ModuleDirectory).\n- {cmake args} - any cmake arguments you want to provide to the target, some information is pulled from the unreal build system like, `BUILD_TYPE`, `INSTALL_PATH`, `CXX_COMPILER`, and etc... but you can still override them via this argument and set any options.\n- {bool, use system compiler} - optional linux only,  tells the build system to use the system compiler over the embbeded compiler in UE4/5. The embbeded compiler can be limited although it is relatively new clang version, for example even though it supports C++17 it does not include the std::filesystem library. Likely if you use this option your cmake library needs to be a shared object (.so) as static linking from a different compiler likely won't work.\n\n#### Including third-party headers\nFor legacy reasons, Unreal Engine forces 4-byte packing on Win32. This can result in **hard-to-debug alignment issues** in classes that use 8-byte types such as doubles or longs. To restore the default packing around third-party code that defines 8-byte types in public structs, use the following macros:\n```cpp\nPRAGMA_PUSH_PLATFORM_DEFAULT_PACKING\n#include \u003cthirdparty.h\u003e\nPRAGMA_POP_PLATFORM_DEFAULT_PACKING\n```\nFor more info, check the [Unreal Engine Docs](https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/BuildTools/UnrealBuildTool/ThirdPartyLibraries/#defaultpackingandalignment)\n\n## How it works\n\nWhen your project build files are generated, CMakeTarget will create a directory in the Intermediate directory under `Intermediate/CMakeTarget/{LibName}`. It will generate a `CMakeLists.txt` file that will link to then added library directory. It will then call cmake to generate the build files for that library under `build` in the same `Intermediate/CMakeTarget/{LibName}` directory. Once the cmake generation is complete it will then use cmake to build the library and will fetch the library's include directoryes and additonal libraries required for the target. It will then automatically add those to the `ModuleRules` variables `PublicIncludePaths` and `PublicAdditionalLibraries`. It will also add the cmake target's `CMakeLists.txt` file and source files to `ModuleRules.ExternalDependencies` so that changes to the cmake target or it's source will outdate the UE4/5 project which will force a re-build of the cmake target. If the cmake generation or build fails it will add a non existent file to the dependencies forcing the UE4/5 build system to run cmake again on the next build. Once the cmake completes successfully the non existent file will no longer be included.\n\nThe above cmake functionality generates an output file in the `Intermediate/CMakeTarget/{LibName}/Build` directory `buildinfo_{BuildType}.ouput`, this file includes all the information that is added to the `ModuleRules`. This same directory includes all the cmake build information that is generated and will include cmake logs if you run into errors. \n\nThere is support to get the binary locations of the lib but is not currently setup.\n\n## Example\n[FastNoise2](https://github.com/caseymcc/UE4_FastNoise2)\n\n### FastNoise2Example.uproject:\nOriginal\n```c++\n{\n\t\"FileVersion\": 3,\n\t\"EngineAssociation\": \"4.25\",\n\t\"Category\": \"\",\n\t\"Description\": \"\",\n\t\"Modules\": [\n\t\t{\n\t\t\t\"Name\": \"FastNoise2Example\",\n\t\t\t\"Type\": \"Runtime\",\n\t\t\t\"LoadingPhase\": \"Default\"\n\t\t}\n\t]\n}\n```\nto\n```c++\n{\n\t\"FileVersion\": 3,\n\t\"EngineAssociation\": \"4.25\",\n\t\"Category\": \"\",\n\t\"Description\": \"\",\n\t\"Modules\": [\n\t\t{\n\t\t\t\"Name\": \"FastNoise2Example\",\n\t\t\t\"Type\": \"Runtime\",\n\t\t\t\"LoadingPhase\": \"Default\"\n\t\t}\n\t],\n\t\"Plugins\": [\n\t\t{\n\t\t\t\"Name\": \"CMakeTarget\",\n\t\t\t\"Enabled\": true\n\t\t}\n\t]\n}\n```\n\n### FastNoise2Example.Build.cs:\nOriginal\n```c++\nusing UnrealBuildTool;\n\npublic class FastNoise2Example : ModuleRules\n{\n    public FastNoise2Example(ReadOnlyTargetRules Target) : base(Target)\n    {\n        ...\n    }\n}\n```\nto\n```c++\nusing UnrealBuildTool;\n\npublic class FastNoise2Example : ModuleRules\n{\n    public FastNoise2Example(ReadOnlyTargetRules Target) : base(Target)\n    {\n        ...\n        CMakeTarget.add(Target, this, \"FastNoise\", Path.Combine(this.ModuleDirectory, \"../Deps/FastNoise2\"), \"-DFASTNOISE2_NOISETOOL=OFF\", true);\n        ...\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaseymcc%2Fue4cmake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaseymcc%2Fue4cmake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaseymcc%2Fue4cmake/lists"}