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.
#Cygwin tutorial pdf update
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.