caseymcc / UE4CMake

Provides a simple way to add a cmake lib to any Unreal Engine 4 (UE4) or 5 (UE5) project.
MIT License
78 stars 14 forks source link

useSystemCompiler = false on Linux does not work #25

Closed mdluhosch closed 4 weeks ago

mdluhosch commented 1 month ago

I used the latest main branch as a submodule but it was not able to use the clang from Unreal Engine. I made it work by adding following lines to https://github.com/caseymcc/UE4CMake/blob/main/Source/toolchains/unix_toolchain.in

set(CMAKE_C_COMPILER_TARGET x86_64-unknown-linux) set(CMAKE_CXX_COMPILER_TARGET x86_64-unknown-linux)

With this CMake knows how to invoke the clang and clang++ correctly. Without this the CMake configure step fails as soon as CMake tries to check if the compiler is working.

I am not sure how to generate the correct triple correctly. If you invoke the unreal clang with -print-target-triple then you get "x86_64-unknown-linux-gnu" which unfortunately does not work you need to remove the -gnu.

I am using latest unreal engine (5.4.3)

Starkium commented 1 month ago

I don't even know how you got this far. I can't even generate project files with this thing

caseymcc commented 1 month ago

@mdluhosch You have to make sure cmake can see your unreal compiler. You should be able to identify the compiler location using cmake options (-DCMAKE_C_COMPILER_TARGET=..., etc...) fed to the add command via args

 bool add(ReadOnlyTargetRules target, ModuleRules rules, string targetName, string targetLocation, string args, bool useSystemCompiler=false)

@Starkium let me know the issue and I might be able to help or catch me on discord.

caseymcc commented 1 month ago

Also I spent sometime awhile back, trying to get static builds working https://github.com/caseymcc/UE4CMake/tree/linux_clang. I did get it to work by manually coping all the settings (as everything in the build system is private). However you might be better off setting useSystemCompiler = true and building a SO.

Starkium commented 1 month ago

@mdluhosch You have to make sure cmake can see your unreal compiler. You should be able to identify the compiler location using cmake options (-DCMAKE_C_COMPILER_TARGET=..., etc...) fed to the add command via args

 bool add(ReadOnlyTargetRules target, ModuleRules rules, string targetName, string targetLocation, string args, bool useSystemCompiler=false)

@Starkium let me know the issue and I might be able to help or catch me on discord.

I think it's more than that. I'm trying to get this to work on Unreal 5.4 and it seems like a lot of stuff is either deprecated or just missing an include or something

mdluhosch commented 1 month ago

@caseymcc not sure If we talk about the same thing. I have not an issue anymore. For me static linking with the Unreal Clang is fine. Here is the history of how I made it work:

This did fail as soon as CMake tried to test the C/C++ compiler.

Then I made it work like this:

This already worked and I could link my static library build by Unreals Clang. First I thought nice now I have a solution but then I found it kind of strange that this did not work out of the box because the bool at the end kind of suggests that this should work out of the box. So I came up with the naive patch above.

caseymcc commented 1 month ago

@mdluhosch I think that will work for most things, however you may run into an issue with crashing if you pass structures through the library interface as unfortunately the default cmake setup that will be generated will not match the same compiler flags that the unreal build is using. which is why at one point I attempted to duplicate the compiler/linker flags from the unreal build system.

mdluhosch commented 4 weeks ago

Now I see... Yes I agree it seems to be much harder to get all the settings correct. I will close this Issue.