clion.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. .. _doc_configuring_an_ide_clion:
  2. CLion
  3. =====
  4. `CLion <https://www.jetbrains.com/clion/>`_ is a
  5. `JetBrains <https://www.jetbrains.com/>`_ IDE for C++ that's free for individual, non-commercial development.
  6. Importing the project
  7. ---------------------
  8. CLion can import a project's `compilation database file <https://clang.llvm.org/docs/JSONCompilationDatabase.html>`_, commonly named ``compile_commands.json``. To generate the compilation database file, open the terminal, change to the Godot root directory, and run:
  9. ::
  10. scons compiledb=yes
  11. Then, open the Godot root directory with CLion and wait for the project to be fully
  12. indexed. If code completion, parameter information, or refactoring are not enabled,
  13. you will need to load the project with CMake. To do this, find the ``CMakeLists.txt``
  14. file in the ``platform\android\java\nativeSrcsConfigs`` directory, right click and
  15. select :button:`Load CMake Project`. Once the project reloads, a ``godot`` build configuration
  16. will be added. This configuration can be safely deleted as the CMake file will not
  17. build the project and only exists for loading the project in JetBrains IDEs.
  18. .. note:: Windows Users:
  19. For ``compile_commands.json`` to load correctly in CLion, you must first have the Visual Studio toolchain configured for CLion.
  20. - Navigate to **Preferences > Build, Execution, Deployment > Toolchains**
  21. - Click the **+** button and select ``Visual Studio``
  22. - CLion will attempt to detect your Visual Studio installation. If it is unsuccessful, use the file icon to the right of ``Toolset:`` to select the directory with your Visual Studio installation.
  23. You may exit and reload CLion and it will reload ``compile_commands.json``
  24. .. figure:: img/clion_visual_studio_toolchain.webp
  25. :align: center
  26. Compiling and debugging the project
  27. -----------------------------------
  28. CLion does not support compiling and debugging Godot via SCons out of the box. This can be achieved by creating a custom build target and run configuration in CLion. Before creating a custom build target, you must :ref:`compile Godot <toc-devel-compiling>` once on the command line, to generate the Godot executable. Open the terminal, change into the Godot root directory, and execute:
  29. ::
  30. scons dev_build=yes
  31. To add a custom build target that invokes SCons for compilation:
  32. - Open CLion and navigate to **Preferences > Build, Execution, Deployment > Custom Build Targets**
  33. .. figure:: img/clion-preferences.png
  34. :align: center
  35. - Click **Add target** and give the target a name, e.g. ``Godot debug``.
  36. .. figure:: img/clion-target.png
  37. :align: center
  38. - Click **...** next to the **Build:** selectbox, then click the **+** button in the **External Tools** dialog to add a new external tool.
  39. .. figure:: img/clion-external-tools.png
  40. :align: center
  41. - Give the tool a name, e.g. ``Build Godot debug``, set **Program** to ``scons``, set **Arguments** to the compilation settings you want (see :ref:`compiling Godot <toc-devel-compiling>`), and set the **Working directory** to ``$ProjectFileDir$``, which equals the Godot root directory. Click **OK** to create the tool.
  42. .. note:: CLion does not expand shell commands like ``scons -j$(nproc)``. Use concrete values instead, e.g. ``scons -j8``.
  43. .. figure:: img/clion-create-build-tool.webp
  44. :align: center
  45. - Back in the **External Tools** dialog, click the **+** again to add a second external tool for cleaning the Godot build via SCons. Give the tool a name, e.g. ``Clean Godot debug``, set **Program** to ``scons``, set **Arguments** to ``-c`` (which will clean the build), and set the **Working directory** to ``$ProjectFileDir$``. Click **OK** to create the tool.
  46. .. figure:: img/clion-create-clean-tool.png
  47. :align: center
  48. - Close the **External Tools** dialog. In the **Custom Build Target** dialog for the custom ``Godot debug`` build target, select the **Build Godot debug** tool from the **Build** select box, and select the **Clean Godot debug** tool from the **Clean** select box. Click **OK** to create the custom build target.
  49. .. figure:: img/clion-select-tools.png
  50. :align: center
  51. - In the main IDE window, click **Add Configuration**.
  52. .. figure:: img/clion-add-configuration.png
  53. :align: center
  54. - In the **Run/Debug Configuration** dialog, click **Add new...**, then select **Custom Build Application** to create a new custom run/debug configuration.
  55. .. figure:: img/clion-add-custom-build-application.png
  56. :align: center
  57. - Give the run/debug configuration a name, e.g. ``Godot debug``, select the ``Godot debug`` custom build target as the **Target**. Select the Godot executable in the ``bin/`` folder as the **Executable**, and set the **Program arguments** to ``--editor --path path-to-your-project/``, where ``path-to-your-project/`` should be a path pointing to an existing Godot project. If you omit the ``--path`` argument, you will only be able to debug the Godot Project Manager window. Click **OK** to create the run/debug configuration.
  58. .. figure:: img/clion-run-configuration.png
  59. :align: center
  60. You can now build, run, debug, profile, and Valgrind check the Godot editor via the run configuration.
  61. .. figure:: img/clion-build-run.png
  62. :align: center
  63. When playing a scene, the Godot editor will spawn a separate process. You can debug this process in CLion by going to **Run > Attach to process...**, typing ``godot``, and selecting the Godot process with the highest **pid** (process ID), which will usually be the running project.
  64. Ignoring object and library files
  65. -----------------------------------
  66. After building Godot in CLion, you may see the object and library files showing up in the **Project** view.
  67. .. figure:: img/clion-object-library-files-in-project-view.webp
  68. :align: center
  69. You can configure CLion to ignore those files:
  70. - Open CLion and navigate to **Preferences > Editor > File Types > Ignored Files and Folders**
  71. - Click the **+** button to add ``*.o`` and ``*.a`` to the list. In Windows, you would add ``*.obj`` and ``*.dll``.
  72. .. figure:: img/clion-ignore-object-library-files.webp
  73. :align: center
  74. Now, the files should be ignored in the Project view.