In CLion, how can I rename a project?
Asked Answered
T

6

26

I try to rename my project from encoding to Tutorial, but after I refactor directory name, it comes out an error, like:

Error: CMakeLists.txt not found in D:\code\encoding

I find that files in .idea directory don't change automatically, they are still encoding.iml, encodings.xml.

Top answered 11/10, 2015 at 15:34 Comment(1)
If you've correctly set up your project's CMakeLists.txt, I'd suggest that you: 1) close the IDE. 2) rename the directory. 3) remove the .idea folder. 4) import the renamed directory in CLion. The IDE still has some rough edges like the one you mentioned, but if you base your project's config on the CMakeLists.txt file (I'm not a fan of the GUI config options), you should be able to fix quiet a few "glitches" by simply removing the .idea directory and re-importing the project.Zootomy
P
48

In the project folder, cd to the .idea directory. Locate the .name file and open it for editing. A single line of the current project name is displayed. Change it and save it.

If the .name file is not present, create it, then add a single line of text with the desired name.

Now reopen CLion and the project name has changed.

Phyfe answered 21/1, 2016 at 1:2 Comment(6)
pretty sure you don't know what you're talking about. There is no .name file anywhere in the ${PROJECT_DIR}/.idea directory.Firebrick
I do know what I am talking about. If you do not have a .name flle in the .idea directory then add one, like this at the CLI: $ cat > .name [enter] my-project-name[enter] ctrl-dPhyfe
BTW, tel yesterday, you may not believe me so check out: #21177995Phyfe
With the clarification that you should create the .idea/.name file if it doesn't exist, I withdraw my earlier objection. terrinator_s's answer is the correct/easiest one. I submitted an edit with an extra sentence about creating the file. Now if only SE will let me undo my downvote...Firebrick
Note, I have found that CLion has to be closed (or perhaps just the project need to be closed) when adding the .name file. If you add .name while project is open then when project is closed the .name is deleted (probably part of saving project at close).Chrysotile
That's an ugly hack, so I filed a bug report against CLion.Anomalistic
C
9

When using CLion with CMake, the project name is set by the project command inside the CMakeLists.txt.

Look for a line like the following and change "my_project_name" to the CLion project name you want.

project(my_project_name)

Then reload the file using Tools >> CMake >> Reload CMake Project or, if present, by clicking on Reload changes in the yellow bar across the top of the CMakeLists.txt editor window.

Note, if you use New Cmake Project From Sources... to create your project, then CLion generates the CMakeLists.txt at that time including a project command using the directory name. It is fine to edit CMakeLists.txt after it is generated, including changing the project name.

Chrysotile answered 30/10, 2019 at 23:59 Comment(0)
M
3

On Mac:

  1. Close CLion
  2. Rename your project folder, found at ~Users/Your_User/ClionProjects
  3. Open CLion
  4. Click "Open Project"
  5. Browse for your renamed project
  6. Wait for your project to fully load and update
Mindymine answered 9/9, 2016 at 23:30 Comment(0)
F
1

If your are running Clion on a Mac, all you have to do is rename the directory that contains your .cpp and .h and CMake files then in Clion go to open then to the new name of the directory and Clion automatically figures everything else out.

That is what I did. However before you open the new project which is the project you renamed. Clion will create a project directory with the original name and it will be blank so you will have to Delete that directory.

However, if you are using windows or other machines it may not be the same. Because, now that i look, i don't have and .idea file.

Now that i think about it. Maybe this is a new feature since the new update. I am not sure when the new update for jetbrain IDEs was released. So, maybe that is a new feature that was not around at the time of your original post.

Fruiter answered 29/12, 2015 at 5:46 Comment(0)
R
1

I did that in Linux. Grep oldProjectName in my project dir by cmd:

grep -rn oldProjectName

CMakeLists.txt, cmake-build-debug/ .idea/ have that str, so I replace all by cmd:

sed -i "s/oldProjectName/newProjectName/g" `grep -rl "oldProjectName" .`
Resound answered 4/3, 2021 at 3:8 Comment(1)
That's an ugly hack, so I filed a bug report against CLion.Anomalistic
P
0

Easier Answer:

Why are you making it so hard? I have done this by either editing or adding a .name file to the .idea directory. I have done this several times and it works:

  1. Edit or create your .name file in the .idea directory
  2. Change or add file name.
  3. Save file
  4. Reopen project and voila, the new project name.
Phyfe answered 12/4, 2016 at 20:38 Comment(1)
That's an ugly hack, so I filed a bug report against CLion.Anomalistic

© 2022 - 2024 — McMap. All rights reserved.