当前位置:网站首页>[cmake command notes]target_ compile_ options

[cmake command notes]target_ compile_ options

2022-06-23 01:25:00 Blue area soldier

compile basalt Encountered this command when ,basalt Third party libraries used pangolin Always report mistakes :

CMake Error at thirdparty/CMakeLists.txt:67 (target_compile_options):
  Cannot specify compile options for target "pangolin" which is not built by
  this project.


CMake Error at thirdparty/CMakeLists.txt:118 (get_target_property):
  get_target_property() called with non-existent target "pangolin".


CMake Error at thirdparty/CMakeLists.txt:134 (get_target_property):
  get_target_property() called with non-existent target "pangolin".


CMake Error at thirdparty/CMakeLists.txt:142 (set_target_properties):
  set_target_properties Can not find target to add properties to: pangolin

But this has nothing to do with the command , This error seems to be caused by downloading the third-party library , It's not used git clone --recursive, Instead, manually download third-party libraries to thirdparty Under the table of contents , So you may not be aware of pangolin The existence of , Then I am basalt Use... Under the project root directory git submodule init and git submodule update, The problem was happily solved .

Record here target_compile_options command reference

cmake Original document address
This command is to add compilation options for a target that needs to be compiled , For example, the one added above add_executable() perhaps add_library(), These two commands indicate that you want to compile an executable file or a library , This is the compilation target (target).
The parameter options of the command are as follows :

target_compile_options(<target> [BEFORE]
  <INTERFACE|PUBLIC|PRIVATE> [items1...]
  [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])

target_compile_options Will add options (options) To COMPILE_OPTIONS perhaps INTERFACE_COMPILE_OPOTIONS Target properties ( This means adding compilation options ). These options are used when compiling a given target (<target>) When using , A given goal must have passed add_executable() perhaps add_library() This command is added to the project , And cannot be an alias target .

Here are the optional parameters

If you specify BEFORE, The options in this command will be placed before all attributes (prepended) Not after (appended).
INTERFACE, PUBLIC and PRIVATE Keywords are used to specify the scope of subsequent parameters .
PRIVATE and PUBLIC Items will be populated <target> Of COMPILE_OPTIONS attribute .
PUBLIC and INTERFACE Items will be populated <target> Of INTERFACE_COMPILE_OPTIONS attribute .
The following parameters are the specified compilation options .
The compilation options are CMAKE Compile parameters when calling the compiler , Every compiler has some compilation parameters , Some are common , Some are compiler related , In fact, I think all the building tools , Compiler tools , It's all about getting a compiler command line , The execution command of this command line is the compiler of the compiler , Command parameters are just these compilation parameters . Use VisualStudio You can view the attribute configuration -C/C+± Command line , It's inside VS Compiler parameters for .

原网站

版权声明
本文为[Blue area soldier]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220917246027.html