CMake Four commands: Add_compile_options () add_definitions () target_compile_definitions () Build_command ()

Source: Internet
Author: User

*add_compile_options ()
Adds options to the compilation of source files. Increase the compilation option for the source file.
Add_compile_options (<option> ...)
Adds options to the compiler command line for targets in the current directory and below that is added after this command is invoked. See documentation of the directory and target compile_options properties. Adds compiler command-line options for the target of the current and downlevel paths, and the option to add after this command is called. View the compilation options properties for paths and targets in the document. This command can is used to add any options, but alternative commands exist to add preprocessor definitions (target_compile _definitions () and add_definitions ()) or Include Directories (Target_include_directories () and Include_directories ()). This command can be used to add any option, but there are alternative commands to add preprocessing definitions or include paths. Arguments to Add_compile_options could use "generator expressions" with the syntax $<...>. See the Cmake-generator-expressions (7) Manual for available expressions. See the Cmake-buildsystem (7) Manual for more on defining Buildsystem properties.add_compile_options parameters can be used with syntax $< "Build expression" for >. For a valid expression, you can view the Cmake-generator-expressions (7) manual. For more information on the definition of system properties, you can view the Cmake-buildsystem (7) assistant.
*add_definitions ()
Adds-d Define flags to the compilation of source files. Adds a flag defined by-D to the compilation of the source file.
Add_definitions (-dfoo-dbar ...)
ADDS definitions to the compiler command line for targets in the current directory and below (whether added before or afte R This command is invoked). This command can being used to add any flags, but it's intended to add preprocessor definitions (see the Add_compile_options () command to add the other flags). Flags beginning in-d or/d that look like preprocessor definitions is automatically added to the Compile_definitions dir Ectory property for the current directory. Definitions with non-trivial values could be left in the set of the flags instead of being converted for reasons of backwards Co Mpatibility. See documentation of the directory, target, source file Compile_definitions properties for details on adding preprocessor Definitions to specific scopes and configurations. Join the compiler command-line definition for the target of the current path and the underlying path (the definition is added before or after the command call, note: that is, indeterminate). This command can be used to add any flags, but it is intended to increase the preprocessor definition (see the add_compile_options () command to add additional definitions). Flags that start with-D or/d and that look like a preprocessor-defined flag are automatically added to the Compile_definitions property of the current path. For back compatibility, non-simple values (non-trival, what is the point?) The definition will be left in the FLAThe GS Group (flags set) without being converted. For more details on adding preprocessor definitions to specific domains and configurations, refer to the path, destination, and compile_definitions properties of the source file. See the Cmake-buildsystem (7) Manual for more on defining Buildsystem properties. You can view the Cmake-buildsystem (7) assistant for a more defined definition of the system attributes.
*target_compile_definitions ()
Add compile definitions to a target adds a compilation definition for the goal.
Target_compile_definitions (<target>                           <interface| public| private> [items1 ...]                           [<interface| public| private> [Items2 ...]
Specify compile definitions to use when compiling a given <target>. The named <target> must has been created by a command such as add_executable () or add_library () and must not being an Imported Target. Compile the given <target> using the specified compilation definition. <target> must be created by add_executable () or add_library () and is not an input target. The INTERFACE, public and PRIVATE keywords is required to specify the scope of the following arguments. PRIVATE and public items would populate the Compile_definitions property of <target>. Public and INTERFACE items would populate the Interface_compile_definitions property of <target>. The following arguments specify compile definitions. Repeated calls for the same <target> append items in the order called. The keyword Interface,public and private are used to specify the scope of subsequent arguments. The private and public entries will produce the Compile_definitions property of <target>. The public and interface entries will produce the <target> Interface_compile_definitions property. Subsequent arguments specify the compilation definition. Repeated calls to the same target are appended (defined) in the order in which they are called. Arguments to Target_compile_definitions could use "generator expressions" With the syntax $<...>. See the Cmake-generator-expressions (7) Manual for available expressions. See the Cmake-buildsystem (7) Manual in defining Buildsystem properties.target_compile_definitions parameters can be used with syntax $ "Build expression" for <...>. For a valid expression, you can view the Cmake-generator-expressions (7) manual. For more information on the definition of system properties, you can view the Cmake-buildsystem (7) assistant.
*build_command ()
Get a command line to build the current project. This was mainly intended for internal use by the CTest module. Gets the command line that builds the project. It is usually used for internal use of ctest modules. Note: The author gives a simple example at the end of the document.
Build_command (<variable>                  [CONFIGURATION <config>]                  [TARGET <target>]                  [project_name <PROJNAME&GT] # Legacy, causes warning                  )
Sets the given <variable&gt to a command-line string of the form:--build. [--config <config>] [--target <target>[---I]where is the location of the CMake (1) command-line tool, and <config> and <target > is the values provided to the CONFIGURATION and TARGET options, if any. The trailing---I option is added for Makefile generators if policy CMP0061 are not set to NEW. When invoked, this cmake--build command line would launch the underlying build system Tool.build_command () This second sig Nature is deprecated and still available for backwards compatibility. Use the first signature instead. It sets the given to a command-line string as above but without the--target option. The is ignored but should being the full path to Msdev, Devenv, NMAKE, make or one of the end user build tools for legacy in Vocations. Note in CMake versions prior to 3.0 This command returned a command line it directly invokes the native build tool for t He current generator. Their impLementation of the PROJECT_NAME option had no useful effects, so CMake now warns on use of the Option.example 
Cmake_minimum_required (VERSION  2.8) Project (cmaketest) #set (cmake_cxx_compiler "g++") add_compile_options (-std =C++11-W) #add_definitions (-std=c++11) build_command (build_command_line CONFIGURATION ${cmake_build_type}              Project_Name cmaketest TARGET All) message ("Build Command:${build_command_line}") Message ("Using compiler ${cmake_cxx_ COMPILER} ") add_executable (Test main.cpp)
Build Command:/usr/bin/make-i "All" using compiler/usr/bin/c++
Main.cppint Main (int argc, char *argv[]) {    int n = 5.5f;    Auto Func = [&] (int n) {return n < 5;};    return 0;}

CMake Four commands: Add_compile_options () add_definitions () target_compile_definitions () Build_command ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.