CMake and Unreal

Hello guys!

Is there a way to build a project, or for that matter the whole engine, with CMake so I could work in a other IDE than Visual Studio? I looked at the source code and found a “MakeFileGenerator.cs”, but I don’t know if that does the trick.

I know that there was a similar question, but that was asked on the Mar 25, so I got the hope it could be a little outdated. :slight_smile:


P.S. Please don’t start with something like “why don’t use Visual Studio” or something. I don’t want this to be another “VS vs Everything” thread.

+1. The official response from Epic staff is what one would expect, “VS preferred”, but it would be amazing if someone could figure out how to use other IDEs (like IntelliJ’s CLion).

VS’s extremely slow Intellisense is just killing my production speed outside of the editor.

schmit: Sorry, i don’t know how i respond directly. :stuck_out_tongue: Just realized yesterday that JetBrains released CLion! It’s an awesome IDE and i would love to use it with UE4. That was the main reason i asked this question. :slight_smile:

Why is this question marked as “resolved”? This question definitely isn’t answered!

1 Like

You can definitively get a CMake-driven unreal project. In 4.5 preview, Unreal Engine Linux build process ‘natively’ generates a CMake file (and makefile so) which could serve as input to build the whole engine in whatever IDE you want (I build UE4Editor from QtCreator).
It is generated by the command

mono Binaries/DotNET/UnrealBuildTool.exe -makefile

from the /Engine/Build/BatchFiles/Linux/ script.
I couldn’t say more as I am not so comfortable/haven’t dig enough with UBT yet…

Found the command for individual project:

/Engine/Binaries/DotNET/UnrealBuildTool.exe -makefile -project="/your_project_path/your_project.uproject" -game -engine -progress

PS I am on Ubuntu 14.04 :wink: Nevertheless it should be expected to work on Mac platform too. For Windows users… I could not say.

Usually a Linux user. But since I need windows for studies, I’m running Win8 and I actually, finally got it to create the makefile by setting up the cross compile toolchain. Just set it up and then run the command(s) above, and it’ll create the makefiles.

CLion doesn’t really like the header files for some reason, if someone knows why and how to fix it (or if I’m doing something wrong), please tell me.

Actually you can use CLion with Unreal Engine 4. I’ve looked through some posts and found some answers:

CLion Source Accessor:

There is still big problem with cmake file. I’ve writter a small blog post about changin CMakeFileGenerator to work with CLion. That should work on OS X and, I hope, Linux.

You may change it a bit if you want to make it work on windows. I wish I could publish this changes in public fork, but unfortunately, GitHub doesn’t allow to create public forks.

You may want to look at my answer below. There are some tricks and you still have to tweak your CMakeLists.txt a bit, but the result is quite satisfactory.

I use CLion on Linux and Mac. It definitely works.

When running on Mac, pass the -cmakefile option. On Windows, do the same for GenerateProjectFiles.bat. Linux automatically generates cmake files, so nothing to do there.

Instead of -makefile I would recommend using -cmakefile that allows finer control over the project and also allows native integration with other IDEs such as Clion.

Building on CLion UE4 for Linux Tutorial v1.1

Hello, hopefully I am not too late to reply. I’ve been experimenting with Clion and have so far gotten it to work just as well as compiling Linux on Mac with xcode. The instructions are very similar, although you will need to make some adjustments.

To build UE4 on linux, you will need to first generate the CMakeFile.txt using the “./” command with the terminal.

Afterwards, open the project (the Unreal Engine folder) with Clion. It will then proceed to scan and index the files, once that is done, you will need to configure the build. On the top dropdown menu that shows all the build Targets, first select ShaderCompilerWorker. Configure the settings so that the executable is FakeTarget and the working directory is the root folder of your UnrealEngine. For right now, ignore filling in the ProgramArguments field.

Next, you want to click the build button and let it finish building ShaderCompilerWorker. It will scan the dependencies and build the module. After it finishes, it says that it will begin scanning for dependencies for FakeTarget. At this point, you can go ahead and click the stop button (near bottom left corner red square button). This will stop the build and let you continue onto the next step.

Once it stops, go back to the top drop down menu and select UE4Editor. Then Edit the Configurations, you will again need to put the same settings from before. Select FakeTarget as executable, directory as your UnrealEngine root folder. Leave ProgramArgument empty for right now. Then start the build. It will finish and you will need to stop the build once it starts scanning dependencies for FakeTarget.

Finally, once the build is stopped, go back to edit configurations for UE4Editor and change the executable to UE4Editor found in /Engine/Binaries/Linux.

If you want to build and compile your project, then you must, either use this command or create the CmakeFile from the editor.

 $ ./ -project="/home/user/Documents/Unreal Projects/MyProject/MyProject.uproject" -game -engine

To create the CmakeFile from the editor, go to plugins and make sure that CLion is turned on. Afterwards, go to your Editor Preferences, select the “Source Code” tab, and in the dropdown menu select CLion. Lastly, in the File Menu, you should now see the option to “Refresh Clion”. This will generate the Cmakefiles. Also you will see the option “Open Clion”. Depending on how you installed Clion, to run CLion from the editor you may need to modify the file “Engine/Plugins/Developer/CLionSourceCodeAccess/Source/CLionSourceCodeAcess/Private/CLionSourceCodeAccessor.cpp”.

Replace “/opt/clion/bin/” with your install location.

     // Linux Default Install
         return TEXT("/opt/clion/bin/");

By following this tutorial it will create a bare bones light UE4 editor. I am not certain if these instructions have equivalent results to those on “the building for Macs” instructions, but I have found that they work and if you need to compile the other modules, you can either follow similar steps to those above or simply compile the rest using the traditional “make” command in the terminal. But this will allow Linux users to build, test, and compile UE4 using the CLion IDE instead of only relying on Visual Studios.

I have tested this to work on UE4.15 and UE4.22, will most likely work with all versions in between although the in Editor menus for CLion differ. Also for older versions of UE4 you may need to manually add these lines in order for Cmake to compile the engine with Clang thus solve the GCC error you’re receiving. And yes, I know it says clang+±6.0, but for some reason that is how you activate the Linux ToolChain that comes with the engine and it will automatically select the correct version of Clang.

Add these lines to your CMakeTextLists.txt in order to compiler UE4 versions older than 4.18

 # CMake Flags
 set(CMAKE_CXX_COMPILER /usr/bin/clang++-6.0)

When opening your Unreal Project, you will need to configure the run configuration. For the executable, select the UE4Editor which is found inside the directory “/Engine/Binaries/Linux”. For ProgramArgument put your Unreal Project,

"/home/user/Documents/Unreal Projects/MyProject/MyProject.uproject"

For working directory, use the directory of your project.