add_executable.rst 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. add_executable
  2. --------------
  3. Add an executable to the project using the specified source files.
  4. ::
  5. add_executable(<name> [WIN32] [MACOSX_BUNDLE]
  6. [EXCLUDE_FROM_ALL]
  7. source1 source2 ... sourceN)
  8. Adds an executable target called <name> to be built from the source
  9. files listed in the command invocation. The <name> corresponds to the
  10. logical target name and must be globally unique within a project. The
  11. actual file name of the executable built is constructed based on
  12. conventions of the native platform (such as <name>.exe or just
  13. <name>).
  14. By default the executable file will be created in the build tree
  15. directory corresponding to the source tree directory in which the
  16. command was invoked. See documentation of the
  17. RUNTIME_OUTPUT_DIRECTORY target property to change this location. See
  18. documentation of the OUTPUT_NAME target property to change the <name>
  19. part of the final file name.
  20. If WIN32 is given the property WIN32_EXECUTABLE will be set on the
  21. target created. See documentation of that target property for
  22. details.
  23. If MACOSX_BUNDLE is given the corresponding property will be set on
  24. the created target. See documentation of the MACOSX_BUNDLE target
  25. property for details.
  26. If EXCLUDE_FROM_ALL is given the corresponding property will be set on
  27. the created target. See documentation of the EXCLUDE_FROM_ALL target
  28. property for details.
  29. The add_executable command can also create IMPORTED executable targets
  30. using this signature:
  31. ::
  32. add_executable(<name> IMPORTED [GLOBAL])
  33. An IMPORTED executable target references an executable file located
  34. outside the project. No rules are generated to build it. The target
  35. name has scope in the directory in which it is created and below, but
  36. the GLOBAL option extends visibility. It may be referenced like any
  37. target built within the project. IMPORTED executables are useful for
  38. convenient reference from commands like add_custom_command. Details
  39. about the imported executable are specified by setting properties
  40. whose names begin in ``IMPORTED_``. The most important such property is
  41. IMPORTED_LOCATION (and its per-configuration version
  42. IMPORTED_LOCATION_<CONFIG>) which specifies the location of the main
  43. executable file on disk. See documentation of the IMPORTED_*
  44. properties for more information.
  45. The signature
  46. ::
  47. add_executable(<name> ALIAS <target>)
  48. creates an alias, such that <name> can be used to refer to <target> in
  49. subsequent commands. The <name> does not appear in the generated
  50. buildsystem as a make target. The <target> may not be an IMPORTED
  51. target or an ALIAS. Alias targets can be used as linkable targets,
  52. targets to read properties from, executables for custom commands and
  53. custom targets. They can also be tested for existance with the
  54. regular if(TARGET) subcommand. The <name> may not be used to modify
  55. properties of <target>, that is, it may not be used as the operand of
  56. set_property, set_target_properties, target_link_libraries etc. An
  57. ALIAS target may not be installed of exported.