Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to create Eclipse project from CMake project

📅 2014-Jan-15 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cmake, eclipse, eclipse cdt, makefile, makefile project ⬩ 📚 Archive

CMake is a popular way to create and maintain C++ projects that are easy to build on different platforms. While CMake can be used to easily generate Visual Studio solutions, it does not work well at creating Eclipse CDT projects. One method to get around this is to create a Makefile project in Eclipse for an existing CMake project.

  1. Go to: File > New > Makefile Project with Existing Code

  2. In the Import Existing Code dialog, provide a Project Name and in the Existing Code Location give the directory containing your CMake project.

  3. The project is created and all the files and directories in your CMake project appear in the Project Explorer. Fear not, Eclipse has not made copies of these files (as it does for most types of imports). Instead, it is working directly from the location of your CMake project.

  4. To be able to build your project, run CMake from the terminal to generate its Makefile. Next, when you choose Project > Build Project, Eclipse runs make in the project directory, thus using the generated Makefile.

  5. The common CMake convention is to generate Makefile and other files in a separate subdirectory. If you would like Eclipse to work with this setup, configure your project to use that make location.

  6. This project can compile one or more target executables, but you cannot Run or Debug them. To be able to do that, create one or more Launch Configurations for the project. You can do this in Project > Properties > Run-Debug Settings. In a launch configuration, at a bare minimum you should at least provide the path to the target executable in the C/C++ Application field.

Now you can compile, run or debug your application from Eclipse itself! 😊

You will find that Eclipse has not created any directory or files in your Workspace directory nor in the existing source code base directory. So, where is it storing the config files for your project?

These are just some of the files and directories, Eclipse uses for such a project:

Tried with: Eclipse 4.4.2, NVIDIA Nsight 5.5.0 and Ubuntu 14.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧