![]() To obtain the library file, we need to build the test_library target. However, this is a non-executable configuration, so if we attempt to run or debug it, we will get the Executable not specified error message. As an example, let's create a static library from the calc.cpp source file:Īdd_library(test_library STATIC calc.cpp)Īs well as for executables, CLion adds a Run/Debug configuration for the library target after reloading the project: For library targets, we need another command - add_library. Up to this point, the targets we added were executables, and we used add_executable to declare them. The option for enabling/disabling auto-reload is also available in Settings / Preferences | Build, Execution, Deployment | CMake.Īfter reloading the project, CLion adds a Run/Debug configuration for the new target: Library targets We can either reload the project once ( Reload changes) or enable automatic reload to let CLion silently apply all the changes in CMakeLists.txt. Note that CLion treats CMake scripts as regular code files, so we can use code assistance features like syntax highlighting, auto-completion, and navigation: When we make changes in CMakeLists.txt, CLion needs to reload it in order to update the project structure: Now let's declare a new target manually in the CMakeLists.txt. Accordingly, CLion notifies us that the new file currently does not belong to any target: Since our goal is to create a new target, we clear the Add to targets checkbox. CLion prompts to add the file to an existing target: ![]() Right-click the root folder in the Project tree and select New | C/C++ Source File. Now let’s add another source file calc.cpp and create a new executable target from it. To learn more about various build actions available in CLion, see Build actions. So we can use this configuration not only to debug or run our target but also to perform the build. Notice the Before launch area of this dialog: Build is set as a before launch step by default. The target name and the executable name were taken directly from the CMakeLists.txt: Upon the first project loading, CLion automatically adds a Run/Debug configuration associated with this target:Ĭlick Edit Configurations in the switcher or select Run | Edit Configurations from the main menu to view the details. You can define multiple build targets in a single script.įor now, our test project has only one build target, cmake_testapp. Target is an executable or a library to be built using a CMake script. Build targets and Run/Debug configurations Sets the CMAKE_CXX_STANDARD variable to the value of 14, as we selected when creating the project.Īdds the cmake_testapp executable target which will be built from main.cpp.Ģ. It is set to the version of CMake bundled in CLion (always one of the newest versions available).ĭefines the project name according to what we provided during project creation. Note that directories not selected in the Select Project Files pane are not presented in the User Include Directories list - select them first, and then the available include directories will appear in the list.Specifies the minimum required version of CMake. ![]() CLion includes a directory automatically when it contains at least one header file, if it is named include, or when it has subdirectories that contain header files only. User Include Directories - select the directories to be included in the project and specified in the CMake include_directories command. Use the subdirectories checkboxes to import their entire contents or clear the checkboxes to import the contents selectively. Select project files - select the files to be imported as project files. In the Import CMake Project dialog, specify the following: ![]() On the main menu, choose File | New CMake Project from Sources and select the path to the sources. To work with non-CMake sources in CLion, you can convert them into a CMake project structure. Note that currently, this setting does not apply to creating a project from sources ( CPP-17686). You can set up a CMake profile to be used for all new projects by default ( File | Other Settings | Settings for New Projects | Build, Execution, Deployment | CMake). Use the Library type control to select the library type ( shared in our example).Ĭlick Create to create a project and generate the corresponding CMakeLists.txt file: You can type the path in the text field or click to browse for the desired folder.Ĭlick the Language standard control and select the standard from the drop down list ( C++11 in our example). In the right pane, set the location and the name of your project. As an example, let's create a simple shared library assuming the C++11 standard.Ĭlick New Project from the Welcome screen or the File menu.
0 Comments
Leave a Reply. |