![]() CMake presetsĬMake Presets are a way to configure and share CMake options using two files:ĬMakePresets.json for project-wise builds. The major difference is that profiles reference CLion toolchains, which contain information that is not present and not needed in CMake presets (like the debugger or environment settings). To configure and share CMake options for your project, you can use CMake presets, CLion's CMake profiles, or both.ĬMake Profiles have many settings in common with CMake Presets and are also shareable via VCS. If you prefer CLion to reload the project silently on every change in CMakeLists.txt, go to Settings | Build, Execution, Deployment | CMake and enable auto-reload: 6. When we make changes in CMakeLists.txt, CLion shows the icon suggesting to reload the project. For example, add STATIC to the declaration of library target: Let's introduce some changes in CMakeLists.txt manually. Select it in the switcher and press or press Control+F9:Īs the result, the libcmake_testapp_lib.a file will appear in the cmake-build-debug folder. To get the library file, we need to build this configuration. However, this is a non-executable configuration, so if we try to run or debug it, we will get the Executable not specified error message: Similarly to the case of executable targets, CLion automatically creates configurations for library targets: Set the target name ( cmake_testapp_lib) and click Add.Ĭlear the other targets' checkboxes and click OK:ĬLion will add a add_library command to CMakeLists.txt and reload the project: In this drop-down, you can find the commands for adding CUDA and Qt targets. In the drop-down list, select add_library: Provide the file name ( calc_lib) and click Add new target. Let's clear the checkbox next to it and leave only the cmake_testapp_calc selected:ĬLion will add a new add_executable command to CMakeLists.txt and reload the project:Īfter reload, a new configuration will appear in the configuration switcher: The first target, cmake_testapp, is still selected. The newly created target will appear in the list. Specify the target name ( cmake_testapp_calc) and click Add: Set the file name ( calc in our example). Right-click the root folder in the Project tree and select New | C/C++ Source File again. Now let's add two more files and create an executable and a library target for them. When you add a file to a target this way, without manually editing the CMakeLists.txt script, CLion reloads the project automatically in the background. Right-click the root folder in the Project tree and select New | C/C++ Source File:Ĭlick OK, and the new file will be added to the add_executable command: Let’s create a new source file general.cpp and add it to the cmake_testapp target. To learn more about various build actions available in CLion, check out Build actions. So we can use this configuration not only to debug or run our target, but also to perform the build. Build is set as a before launch step by default. Notice the Before launch area of this dialog. The target name and the executable name are the same as specified in 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. The CMake tool window opens up automatically in case of load failure.Ģ. #Cmake create list windows#To access it, call View | Tool Windows | CMake or switch to it in the tool windows bar: ![]() ![]() In the CMake tool window, you can check the progress and status of project load. Sets the CMAKE_CXX_STANDARD variable to the value of 17, as we selected when creating the project.Īdds the cmake_testapp executable target to be built from main.cpp. For most cases, if CMake executable was not changed intentionally, this is the bundled CMake version.ĭefines the project name according to what we provided during project creation. Specifies the minimum required version of CMake, as set in the default toolchain. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |