Overriding a default option(.) value in CMake from a parent CMakeLists.txt.Change default value of CMAKE_CXX_FLAGS_DEBUG and friends in CMake.Or you could just put the flag in a toolchain/preset where you already know what compiler you're using. ![]() Target_compile_options(lib private -wsuggest-override) If (cmake_cxx_compiler_id matches "gnu" and cmake_cxx_compiler_version version_greater_equal 5.1) must use a genex for interface/public because the whole genex gets exported, whereas this flag will get exported verbatim. you can work around this with generator expressions and/or complex logic (like the _undef trick above), but it's generally just easier and more convenient to use a toolchain or these new presets.įor instance, to correctly add -wsuggest-override, you would need to write: target_compile_options(lib private $,5.1>,$>:-wsuggest-override>) if someone tries to compile your library with a different compiler (or even a different version of the same compiler) they could run into issues if, for example, you add a warning flag that's too new or not supported. presets are opt-in for the user, which is important if you're distributing a library.Įxpanding on points 4 and 5: it is a bad idea to add flags unless they absolutely must be there to compile correctly and there isn't a built-in feature for reaching those flags (eg.you don't have to write awkward logic in your cmakelists.txt.it can override flags that are usually unconditionally added to the *_init flags.it's compatible with other toolchain files (like vcpkg's in the second preset).it makes the command line a lot simpler. ![]() Then, from the source directory, your cmake command line would just become: $ cmake -preset=default You can try to determine the compiler by checking cmake_generator (which is valid before the project() command):Ĭmakelists.txt if("$/scripts/buildsystems/vcpkg.cmake" Gnutoolchain.cmake set(cmake_cxx_flags_debug "-ggdb3 -o0" cache string "")Īnd then use it with cmake -dcmake_toolchain_file:string=gnutoolchain.cmake. Having your own toolchain files containing the presets for each compiler you support like: I just wanted to add the four possibilities i see:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |