Change location of CMakeLists.txt

Is it possible to change where CMakeLists.txt resides?

It appears that CLion always assumes it resides in the top level of the project directory, but for various reasons (yes, legacy import of another project), mine is not.

Is there a way to tell CLion to look in a particular place for CMakeLists.txt?

6 comments
Comment actions Permalink

Hi,

It is impossible to change the location of CMakeLists.txt, but there is another way to solve the problem. First, open CMakeLists.txt in CLion, and then make a right click in the project tree and select "Change Project Root". After selecting a real project root there everything should work correctly.

0
Comment actions Permalink

When I try that, I get a file picker dialog box.

I select the directory which contains the CMakeLists.txt file, but I don't see any change in the status of the "Problems" in the CMake window.

It still says "Error:CMakeLists.txt not found in /....{top-level project directory}

Do I need to do something to make it resync/force it to understand the root where CMakeLists.txt is located is not in the top level directory of the project, but in a subdirectory?

0
Comment actions Permalink

I assumed that you have CMakeLists.txt in some subdirectory of your project. If that's the case, then in "Change Project Root" you should select the top-level directory of your project, not the directory with CMakeLists.txt

If my assumption is wrong, then could you please describe the layout of your project? Or, better yet, create a sample project that has a similar structure.

0
Comment actions Permalink

Here's the layout:

TOPDIR
|
--src
|   |
|   --- *.c
|
|--out
   |
   --- CMakeLists.txt


I select TOPDIR when I import the files.
I want it to pick up the CMakeLists.txt from the "out" subdirectory.

Note:  the references to the source files in the CMakeLists.txt are all relative, e.g.

add_executable(myproject   ../src/source1.cc  ../src/source2.cc.cc)

0
Comment actions Permalink

OK, I see. You don't need to use project import since you already have a CMakeLists.txt for your project. Here is what you need to do:

1) File -> Open (or Open Project in the Welcome screen), select TOPDIR/out/CMakeLists.txt
2) After that make a right click in the project tree -> Change Project Root -> select TOPDIR.

0
Comment actions Permalink

Ah yes... that works.

I guess I was confused because it doesn't seem to be possible to change *after* you've first imported a project starting at the top level with an existing CMakeLists.txt.

0

Please sign in to leave a comment.