target_compile_features can fillĬOMPILE_FEATURES and INTERFACE_COMPILE_FEATURES, just like directories in example 1.Ĭmake_minimum_required (VERSION 3.15.3.25 ) project (MyExample01 LANGUAGES CXX ) # This is the library Including the headers is not required, but is nice for # users add_library (simple_lib simple_lib.cpp simple_lib.hpp ) # The above line *did not* set the includes - we need to We can also set. Will compile with at least the highest level specified, unless CXX_STANDARD is set (and that’sĪ nice, clear error if you set CXX_STANDARD too low). To compile a target the cxx_std_11 and similar meta-features are perfect for this - your target What would youĭo if you had a C++11 interface target and a C++14 interface target and linked to both?īy the way, there is a way to handle this - you can specify the minimum compile features you need Properties in CMake, it gets it’s default value from a CMAKE_CXX_STANDARD variable if it is set,īut there is no INTERFACE version - you cannot force a CXX_STANDARD via a target. There is a C++ standard property - CXX_STANDARD. PUBLIC, then both properties are appended to at the same time. INTERFACE instead, then INTERFACE_INCLUDE_DIRECTORIES is appended to, instead. The INCLUDE_DIRECTORIES property of TargetA has mydir appended. When you run target_include_directories(TargetA PRIVATE mydir), then The PUBLIC keyword fills both propertyįields at the same time. Tell targets linked to this one what to do when building. “private” properties control what happens when you build that target, and the “interface” properties There are two collections of properties on every target that can be filled with values the Sees through mylibrary the private library will not affect it. myprogram will build the three libraries it P(Public Library) - > |PUBLIC| M((Main Library))įigure 1: Example of PUBLIC, PRIVATE, and INTERFACE. Maybe you do require users have C++14, but your library can compile with any version of C++. users don’t need to be forced into C++14 mode.Only the implementations inside my_lib.cpp require C++14, then this is a PRIVATE requirement However, if the header is valid in all versions of C++, and If the header contains C++14, this is a PUBLIC requirement - both If you then add my_exe, and it needs my_lib, should that force my_exe to compile You have a library, my_lib, made from my_lib.hpp and my_lib.cpp. This keyword when making a library! CMake goes into an old compatibility mode for this target that Target_link_libraries and a keyword one of PUBLIC, PRIVATE, and INTERFACE. Once you have several targets, you can describe the relationship between them with More on that later, once we see what we can do with targets. To make the default is sort-of an “auto” library that is user selectable with BUILD_SHARED_LIBS. See ot-efr32 and ot-nrf528xx.You can add the keywords STATIC, SHARED, or MODULE if you know what kind of library you want Support for multiple platforms in a single repository is possible and several platform repositories can be used as reference. A good example of this file for a repository which supports only a single platform is from ot-cc2538. This is where you define the source files, include paths, and compiler flags for your platform library. A good starting point would be to copy the ot-efr32 version of this file and modify it to fit your platform. This is a toolchain file which defines some variables that CMake uses in the build process. It also contains a few other required files. This is the heart of the repository and is where the platform abstraction layer is implemented. If you would like to include sample applications in the repo, create an examples folder and add it to the build tree as well. The third_party folder contains any third-party code. The src folder is where the platform-abstration layer source code is located. Now that the top-level configuration is defined, it's time to add other subdirectories to the build tree. set_property(CACHE EFR32_PLATFORM PROPERTY STRINGS $/crypto The CMakeLists.txt file includes a check that aborts builds launched for unsupported platforms. For the sake of this example, we've defined multiple platforms, but having a single platform for the _PLATFORM_VALUES variable is fine as well. We also define a variable EFR32_PLATFORM_VALUES which is a list of efr32 platforms supported by ot-efr32. In this example, we set the project name to ot-efr32 with a version of 0.0.1. The very first values to define are the project name and the supported platforms. The CMakeLists.txt at the root of your repository is the top of the build tree and is a good place to start defining the various targets, options, and macros used in the build process. The CMake build system relies on CMakeLists.txt files which define build targets.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |