![]() So we can use this configuration not only to debug or run our target but also to perform the build. To learn more about various build actions available in CLion, see Build actions. Now let’s add another source file calc.cpp and create a new executable target from it. ![]() 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. 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. 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. 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. Up to this point, the targets we added were executables, and we used add_executable to declare them. 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. 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. To obtain the library file, we need to build the test_library target. For this, we can switch to the corresponding configuration and press, or call Build | Build "test_library". The libtest_library.a file will appear in the cmake-build-debug folder. Build types and CMake profilesĪll the Run/Debug configurations created by far were Debug configurations, which is the default build type of the CMake profile that was automatically configured for our project. It specifies the toolchain, build type, CMake flags, path for storing build artifacts, make build options, and environment variables.įor example, to separate the Debug and Release builds, we can add a new CMake profile in Settings / Preferences | Build, Execution, Deployment | CMake and set its build type to Release: CMake profile is a set of options for the project build. Notice the Build directory field that specifies the location of build results. The default folders are cmake-build-debug for Debug profiles and cmake-build-release for Release profiles. You can always set other locations of your choice. Now the Run/Debug configuration switcher shows two available profiles: Switching configurations or CMake profiles may affect preprocessor definitions used while resolving the code. For example, when there are separate flags for Debug and Release builds, or when there are some variables that take different values depending on the build type. Resolve context defines how CLion performs syntax highlighting and other code insights like Find Usages, refactorings, and code completion. When you switch between configurations, the resolve context for the current file is changed automatically. ![]() > Follow this link to subscribe/unsubscribe:Also, you can select it manually in the context switcher ( restores the automatic selection): 5. > CMake Support: > CMake Consulting: > CMake Training Courses: > Visit other Kitware open-source projects at > information on each offering, please visit: > Kitware offers various services to support the CMake community. > Powered by > Please keep messages on-topic and check the CMake FAQ at: > add_custom_command( OUTPUT $ -E touch aaa_file.c So I used the following, it seems not working: I forgot to say my CMakeList.txt is not located together with the
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |