![]() ![]() 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.Ģ. 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. Old ways of doing this were quite cumbersome.Specifies the minimum required version of CMake, as set in the default toolchain. I hope this helps everybody as much as it has helped me. ![]() If it has been installed in a non-standard path, it is also easy, just tell CMake where to find MyLibConfig.cmake using: cmake -DMyLib_DIR=/non/standard/install/path. That's it, if it has been installed in a standard directory it will be found and there is no need to do anything else. #No need to perform include_directories(.) Set VERSION property (optional but it is a good practice): set_target_properties(mylib PROPERTIES VERSION $ FILE MyLibConfig.cmake)Īfter running CMake and installing the library, there is no need to use Find***.cmake files, it can be used like this: find_package(MyLib REQUIRED) If you are lazy, copy-paste output of ls -1 sources/*.cpp : add_library(mylib SHARED This feature does not provide attended mastery of the compilation process. cmake says it is mandatory and it will define convenient variables PROJECT_NAME, PROJECT_VERSION and PROJECT_DESCRIPTION (this latter variable necessitate cmake 3.9): project(mylib VERSION 1.0.1 DESCRIPTION "mylib description")ĭeclare a new library target. Always specify the minimum required version of cmake cmake_minimum_required(VERSION 3.9) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |