[C/C + + basic advanced series] actual combat record -- C + + application project structure construction (GYP)
[1] Keyword overview in GYP
- conditions: condition definition
- Includes: includes List of gypi files
- target_defaults: the default project configuration. The configuration of each project (targets) needs to be inherited from this configuration
- targets: Project List
- variables: defines key value pairs, which can be referenced in the form of < (Varname) elsewhere
- targets: Project List
- target_name: Specifies the name of the defined target
- Type: the type of target
- Support executable and static_library,shared_library and none
- The none type is also useful as a type for processing special items such as resources and documents
- Support executable and static_library,shared_library and none
- product_extension: Specifies the extension of the target generation target, excluding '.'
- product_name: Specifies the file name of the tareget generation target, which is the same as product_extension forms a full file name
- dependencies: specify other targets that target depends on
- Definitions: defines preprocessing macros. Similar to the - D or / D option in C/C + + command line compilation
- include_dirs: Specifies the lookup directory containing the files. Similar to the - I or / I option in C/C + + command line compilation
- sources: lists the code files in the project and some project related files. sources! The excluded files can be specified in the section
- Configurations: a set of build configurations defined for targets
- You can select targets and targets_ In the defaults section, configurations cannot be overridden by target_ The item specified in defaults
- link_settings: specify the libraries that target needs to link, executable and shared_ The target of library type needs to specify the link library
- direct_dependent_settings: Specifies the target settings that depend on this target
- libraries: Specifies the library that target depends on
- Actions: defines a set of custom build actions for the input file
- action_ Name: the name of the action. Some platforms may ignore this field
- inputs: input information, used for incremental build
- outputs: output information, used as an incremental build
- action: build command
- message: information displayed at build time
- copies: defines a set of copy actions
- Destination: destination folder for the copy
- Files: list of files to be copied
- conditions: condition judgment
- target_conditions: condition judgment
[2] GYP profile example
{ 'variables': { # Key value pairs are defined # It can be referenced in the form of < (Varname) elsewhere 'pi': 'import math; print math.pi', 'third_letters': "<(other_letters)HIJK", 'letters_list': 'ABCD', 'other_letters': '<(letters_list)EFG', 'check_lists': [ '<(third_letters)', ], 'check_int': 5, 'check_str_int': '6', 'check_list_int': [ 7, '8', 9, ], 'not_int_1': ' 10', 'not_int_2': '11 ', 'not_int_3': '012', 'not_int_4': '13.0', 'not_int_5': '+14', 'negative_int': '-15', 'zero_int': '0', }, 'target_defaults': { # Default project configuration # The configuration of each project (targets) needs to be inherited from this configuration 'defines': [ 'U_STATIC_IMPLEMENTATION', ['LOGFILE', 'foo.log',], ], 'include_dirs': [ # Specifies the lookup directory containing files, similar to the - I or / I option in C/C + + command-line compilation '..', ], 'target_conditions': # After processing all dependencies # Can appear in Anywhere in the gyp file [ # Ensure target and host have different shared_library names ['_toolset=="host"', {'product_extension': 'host'}], ], 'conditions': # Condition definition # Loading The gyp file is processed as soon as it is # Can appear in Anywhere in the gyp file [ [ 'target_arch == "ia32"', { # The CPU architecture is ia32 'cflags': [ '-m32' ], # gcc compilation options 'ldflags': [ '-m32' ] # gcc link options }], [ 'target_arch == "x64"', { # The CPU architecture is x64 'cflags': [ '-m64' ], # gcc compilation options 'ldflags': [ '-m64' ] # gcc link options }] ] 'configurations': # A set of build configurations defined for targets # Preprocessing macros and compilation options under Release / Debug configuration are specified here # Can be in targets and target_ In the defaults section # configurations cannot be overridden by target_ The item specified in defaults { 'Release': { # gcc compilation options 'cflags': [ '-O3', '-Wno-unknown-warning-option', '-fPIC' ] }, 'Debug': { # Preprocessing macros are defined, similar to the - D or / D option in C/C + + command-line compilation 'defines': [ 'DEBUG', 'MS_LOG_TRACE', 'MS_LOG_FILE_LINE' ], # gcc compilation options 'cflags': [ '-g', '-O0', '-Wno-parentheses-equality', '-Wno-unknown-warning-option', '-fPIC' ], } }, }, 'targets': [ # Item list { 'target_name': 'hello1', # Specifies the name of the defined target 'product_extension': '_bin', # Specifies the extension of the target build target, excluding '.' 'product_name': 'hellow_1_', # Specify the file name of the tareget generation target, which is the same as product_extension forms a full file name 'type': 'executable', # Type of target # Supports executable and static_ Library (static library) # shared_ Library and none 'dependencies': [ # Specify other targets that target depends on # There can be more than one dependency member, which can only depend on the target in the current gyp or other gyp files 'b/b.gyp:b', 'c/c.gyp:*' ], 'defines': [ # Preprocessing macros are defined, similar to the - D or / D option in C/C + + command-line compilation 'FOO', 'VALUE=1', 'PAREN_VALUE=(1+2+3)', 'HASH_VALUE="a#1"', ], 'include_dirs': [ # Specifies the lookup directory containing files, similar to the - I or / I option in C/C + + command-line compilation '.', 'inc1', 'subdir/inc2', ], 'sources': [ # Lists the source files in the project # sources! The excluded files can be specified in the section 'hello.h' 'hello.c', ], 'link_settings': { # Specify the library that target needs to link # executable and shared_ The target of library type needs to specify the link library 'libraries': [ # Specifies the library that target depends on 'libiconv.dylib', 'subdir/libminizip.a', ], 'ldflags': [ '-pthread' ], # gcc link options }, 'direct_dependent_settings': { # Specifies the target setting that depends on this target 'defines': [ # Preprocessing macros are defined, similar to the - D or / D option in C/C + + command-line compilation 'UNIT_TEST', ], 'include_dirs': [ # Specifies the lookup directory containing files, similar to the - I or / I option in C/C + + command-line compilation 'foo', 'foo/include', ], }, 'actions': [ # Provides the ability to customize input and output processing # The build system will compare whether the files in inputs and outputs have been modified, # action can only be run if it has been modified { 'variables': { # Key value pairs are defined # It can be referenced in the form of < (Varname) elsewhere 'core_library_files': [ 'src/runtime.js', 'src/v8natives.js', 'src/macros.py', ], }, 'action_name': 'js2c', # action, which may be ignored by some platforms 'inputs': [ # Enter information for use in incremental builds 'tools/js2c.py', '<@(core_library_files)', ], 'outputs': [ # Output information for incremental build '<(INTERMEDIATE_DIR)/libraries.cc', '<(INTERMEDIATE_DIR)/libraries-empty.cc', ], 'action': ['python', 'tools/js2c.py', '<@(_outputs)', 'CORE', '<@(core_library_files)'], # Build command }, ], }, { 'target_name': 'copies1', # Specifies the name of the defined target 'type': 'none', # Type of target # Supports executable and static_ Library (static library) # shared_ Library and none 'includes': [ # Includes: includes List of gypi files '../common.gypi', './thread.gypi', ], 'copies': [ # Defines a set of copy actions # copies creates a file with the same name at destination { 'destination': 'copies-out', # Destination folder for copy 'files': [ # List of files to be copied 'file1', ], }, ], }, # replica catalog { 'target_name': 'copies3', # Specifies the name of the defined target 'type': 'none', # Type of target # Supports executable and static_ Library (static library) # shared_ Library and none 'copies': [ # Defines a set of copy actions # copies creates a file with the same name at destination { 'destination': '<(PRODUCT_DIR)/copies-out', # Destination folder for copy 'files': [ # List of files to be copied 'directory/', ], }, ], }, { 'target_name': 'program', # Specifies the name of the defined target 'type': 'executable', # Type of target 'sources': [ # Lists the source files in the project # sources! The excluded files can be specified in the section 'main.c', 'prog1.in', 'prog2.in', ], 'rules': [ # Provides the ability to customize builds # The following variables can be accessed in outputs, action, and message # RULE_INPUT_PATH: the full path currently entered # RULE_INPUT_DIRNAME: Directory currently entered # RULE_INPUT_NAME: the name currently entered # RULE_INPUT_ROOT: the currently entered extension # RULE_INPUT_EXT: extension currently entered { 'rule_name': 'make_sources', # The name of the rule, which may be ignored by some platforms 'extension': 'in', # In this target, all source files with this extension are built using this rule 'inputs': [ # Dependent build rules 'make-sources.py', ], 'outputs': [ # Output information for incremental build '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).c', '<(INTERMEDIATE_DIR)/<(RULE_INPUT_ROOT).h', ], 'action': [ # Build command 'python', '<(_inputs)', '<(RULE_INPUT_NAME)', '<@(_outputs)', ], }, ], }, ], }
Reference and thanks
This blog is a summary of the bloggers' learning and practice, and has referred to the blogs of many bloggers. I would like to express my gratitude here. If the bloggers have any shortcomings, please criticize and correct them.
[1]Use of Gyp syntax rule reference & Tool