cmake指定编译器版本及路径(Cmake specifies the compiler version and path)

CMAKE_C_COMPILER:指定C编译器CMAKE_CXX_COMPILER:指定C++编译器CMAKE_C_FLAGS:指定编译C文件时编译选项,也可以通过add_definitions命令添加编译选项

在cmake脚本中,设置编译选项(配置编译器)有如下三种方法:(1)add_compile_options命令

add_compile_options(-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes)

(2)add_definitions命令

ADD_DEFINITIONS(“-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes)

(3)set命令修改CMAKE_CXX_FLAGS或CMAKE_C_FLAGS

set(CMAKE_C_FLAGS “-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes)使用这三种方式在有的情况下效果是一样的,但请注意它们还是有区别的:add_compile_options命令和add_definitions添加的编译选项是针对所有编译器的(包括c和c++编译器),而set命令设置CMAKE_C_FLAGS或CMAKE_CXX_FLAGS变量则是分别只针对c和c++编译器的。————————————————版权声明:本文为CSDN博主「guanghma」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/dreamback1987/article/details/103698524

————————

CMAKE_ C_ Compiler: Specifies the C compiler cmake_ CXX_ Compiler: Specifies the C + + compiler cmake_ C_ Flags: Specifies the compilation options when compiling C files, or through add_ The definitions command adds compilation options

In cmake script, there are three methods to set compilation options (configure compiler): (1) add_ compile_ Options command

add_compile_options(-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes)

(2)add_definitions命令

ADD_DEFINITIONS(“-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes)

(3)set命令修改CMAKE_CXX_FLAGS或CMAKE_C_FLAGS

Set (cmake_c_flags “- wall – error – wstrict prototypes – wmissing prototypes) the effects of using these three methods are the same in some cases, but please note that they are different: the add_compile_options command and add_definitions add compilation options for all compilers (including C and C + + compilers) The cmake_c_flags or cmake_cxx_flags variables set by the set command are only for C and C + + compilers, respectively. ———————— — copyright notice: This article is “guanghma” of CSDN blogger The original article of follows CC 4.0 by-sa copyright agreement. For reprint, please attach the original source link and this statement. The original link: https://blog.csdn.net/dreamback1987/article/details/103698524