Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion Indexing in Makefile project

Tags:

clion

So, I understand that CLion currently only fully supports CMake projects. I don't care if I can't compile or run anything with CLion, as I don't currently do that with Eclipse anyway. I am just looking for editor support, with nice click-to-follow, autocomplete, etc.

What I am wondering is whether or not indexing can still work for non-CMake projects. I can create my project just fine, and indexing completes just fine, but after that is done it can't find my include files. It creates a default CMakeLists.txt file, in which the appropriate sources and include_directories have been added. It doesn't seem to make a difference though, as after indexing completes I still can't click-to-follow #include lines, and any references to things in other files don't work correctly.

Is there something else I can do to make indexing work so I can use CLion as an editor, or is this a pipe dream until Makefile support is someday added?

like image 296
Dustin Wilhelmi Avatar asked Nov 23 '22 03:11

Dustin Wilhelmi


1 Answers

After some research, I found out your best chances are:

  1. Once it's created, edit CMakeLists.txt (for example, see How to find libraries). One example:

    set(Library "../Library")
    include_directories(${Library})
    set(SOURCES main.cpp)
    add_executable(project_name ${SOURCES})
    

Note ../ goes to the up folder and in the main.cpp you can use #include "header_to_add.h" (header_to_add.h must be in ../Library folder.

  1. Edit the source code of you .cpp, .h or whatever to add the full path of the library you want to #include taking into account the scope starts in the directory where the file is.

For example: #include "../Library/header_to_add.h" (note the "../" goes one level up from the current folder".

  1. (Maybe not possible or hard) Modify the makefile to prepare CMake to get the necessary inputs (for example, see this).

I recommend the first one mainly because it maintains the structure outside the source files.

Edit: Also it's possible to prepare CMake to use makefile (Source).

like image 183
Antonio VR Avatar answered Dec 24 '22 11:12

Antonio VR