当前位置:网站首页>Target of cmake command_ compile_ options

Target of cmake command_ compile_ options

2022-06-24 09:16:00 Things turn at will

One 、 Introduce

This command is to add compilation options for a target that needs to be compiled

Command format :

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 .
 

Two 、 Use

cmake_minimum_required(VERSION 3.10)

project(cmake_gcc_options_try_c C)

set(CMAKE_C_STANDARD 11)

set(CMAKE_C_STANDARD_REQUIRED ON)

add_executable(cmake_gcc_options_try_c main.c)

target_compile_options(cmake_gcc_options_try_c
                       PUBLIC -W -Wall -Wextra -pedantic -pedantic-errors)

Reference resources :

target_compile_options — CMake 3.0.2 Documentation

原网站

版权声明
本文为[Things turn at will]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240752029212.html