![]() ![]() Use BUILD_INTERFACE and INSTALL_INTERFACE generator expressions as filters. Keep in mind to export the right information. See Daniel Pfeifer’s C++Now 2017 talk Effective CMake ( slide 24ff.) on how to do this. Export your library’s interface, if you are a library author. It’s possible to retrofit a find module that properly exports targets to an external package that does not support CMake. Write a find module for third-party libraries that do not support clients to use CMake. It’s a problem if a library author does not support CMake. If the library is an open-source project, consider sending a patch.ĬMake dominates the industry. Report it as a bug to third-party library authors if a library does not support clients to use CMake. Instead, CMake provides a find module to use Boost in CMake. For example, Boost doesn't support CMake. Use a find module for third-party libraries that do not support clients to use CMake.ĬMake provides a collection of find modules for third-party libraries. Use the exported targets via target_link_libraries instead. Use exported targets of external packages.ĭon’t fall back to the old CMake style of using variables defined by external packages. Starting with CMake 3.4, more and more find modules export targets that can be used via target_link_libraries. Modules Use modern find modules that declare exported targets. Don’t abuse usage requirements.Īs an example, don’t add -Wall to the PUBLIC or INTERFACE section of target_compile_options, since it is not required to build depending targets. So it’s much better to tell CMake the compile features so that it can figure out the appropriate compiler option to use. Setting the C++ standard via -std=c++14 in CMAKE_CXX_FLAGS will brake in the future, because those requirements are also fulfilled in other standards like C++17 and the compiler option is not the same on old compilers. Get your hands off CMAKE_CXX_FLAGS.ĭifferent compilers use different command-line parameter formats. This increases the chance of hidden dependencies. All targets defined on that level inherit those properties. Those commands operate on the directory level. ![]() Forget the commands add_compile_options, include_directories, link_directories, link_libraries. Defining such project properties globally makes it easier to manage the project with all its targets. Defining such properties globally in the top-level CMakeLists.txt file prevents scenarios where public headers of a dependent target causing a depending target not to compile because the depending target uses stricter compiler options. Define project properties globally.įor example, a project might use a common set of compiler warnings. Use the same principles for CMakeLists.txt and modules as for the rest of the codebase. Treat CMake code like production code.ĬMake is code. Modern CMake is only available starting with version 3.0.0. General Use at least CMake version 3.0.0. If you are interested in the history and internal architecture of CMake, have a look at the article CMake in the book The Architecture of Open Source Applications. This text is heavily influenced by Mathieu Ropert’s and Daniel Pfeifer’s talks. The next video that goes more into the details of modern CMake is Daniel Pfeifer’s C++Now 2017 talk Effective CMake ( slides). The modular design ideas in this talk are based on the book Large-Scale C++ Software Design by John Lakos. It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. Go read it now.Īfter that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design ( slides). LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. src/generated (supposed for the generated c and header files by protoc)ĬMakeLists-1 (project root) cmake_minimum_required (VERSION 2.For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. ![]() src/externals/protodef (from other repository, only contains. In general, before the build process starts the macro should have been run to generated the source files. Setting the file properties to generated seems also not to help. I can not add the sources to the target, because the files do not exist, they exist after generation, so this results in an error when CMake runs. It seems however the make file is not invoked because no sources are added to the target. This macro is invoked from the CMakeLists.txt in the subdirectory containing the. If the PROTOBUF_GENERATE_CPP macro is executed it generates the sources and the headers files. I have a project with subdirectories, where each subdirectory has its own CMakeLists.txt I am quite new to CMake and until now everything was easy except the integration with protocol buffers. I have seen a lot of similar questions and answers, but until now it seems not so obvious to get it working. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |