sudo python setup.py install
command. If you do not want to install GYP globally with administrator rights, you can simply add a directory with GYP sources in the PATH environment variable.gyp
package in the standard repository (perhaps not the latest version).build
subdirectory and use this version to generate Makefiles for various platforms. { 'targets': [ # <- # { 'target_name': 'gtest', # <- 'cflags': ['-pthread'], # <- 'link_settings': { # <- 'libraries': ['-lpthread'] # <- }, 'type': 'static_library', # <- , static_library, # shared_library, executable, none 'standalone_static_library': 1, # <- thin archive # GYP 'sources': [ # <- 'include/gtest/gtest-death-test.h', 'include/gtest/gtest-message.h', 'include/gtest/gtest-param-test.h', 'include/gtest/gtest-printers.h', 'include/gtest/gtest-spi.h', 'include/gtest/gtest-test-part.h', 'include/gtest/gtest-typed-test.h', 'include/gtest/gtest.h', 'include/gtest/gtest_pred_impl.h', 'include/gtest/internal/gtest-death-test-internal.h', 'include/gtest/internal/gtest-filepath.h', 'include/gtest/internal/gtest-internal.h', 'include/gtest/internal/gtest-linked_ptr.h', 'include/gtest/internal/gtest-param-util-generated.h', 'include/gtest/internal/gtest-param-util.h', 'include/gtest/internal/gtest-port.h', 'include/gtest/internal/gtest-string.h', 'include/gtest/internal/gtest-tuple.h', 'include/gtest/internal/gtest-type-util.h', 'src/gtest-all.cc', 'src/gtest-death-test.cc', 'src/gtest-filepath.cc', 'src/gtest-internal-inl.h', 'src/gtest-port.cc', 'src/gtest-printers.cc', 'src/gtest-test-part.cc', 'src/gtest-typed-test.cc', 'src/gtest.cc', ], 'sources!': [ # <- , 'src/gtest-all.cc', # ], # conditions 'include_dirs': [ # <- '.', './include', ], 'conditions': [ # <- , ['OS == "linux"', { # 'defines': [ 'GTEST_HAS_RTTI=0', ], 'direct_dependent_settings': { 'defines': [ 'GTEST_HAS_RTTI=0', ], }, }], ['OS=="win" and (MSVS_VERSION=="2012" or MSVS_VERSION=="2012e")', { 'defines': [ '_VARIADIC_MAX=10', ], 'direct_dependent_settings': { 'defines': [ '_VARIADIC_MAX=10', ], }, }], ], 'direct_dependent_settings': { # <- , , # gtest , . . 'defines': [ # <- 'UNIT_TEST', ], 'include_dirs': [ # <- include 'include', # , ], # , # </path/to/this/gypfile>/include 'msvs_disabled_warnings': [4800], }, }, # { 'target_name': 'gtest_main', 'type': 'static_library', 'standalone_static_library': 1, 'dependencies': ['gtest'], # <- , # 'sources': [ 'src/gtest_main.cc', ], }, ], }
GLOB
analog from CMake; moreover, this feature was not consciously realized. According to the developers, the lack of GLOB
reduces the likelihood of errors and increases the "tightness" and reproducibility of assemblies. gyp --depth=. gtest.gyp # Makefile make # make
make
started. GYP_GENERATORS=make,scons,eclipse gyp --depth=. gtest.gyp
conditions
section are calculated, and the variables declared with the quantifier <
; on “late” - calculation of conditions of the section target_conditions
and variables with the quantifier >
, as well as substitution of the output of external commands<(var)
- the early phase (the arrow points to the left, ie, the calculation occurs earlier on the time scale), >(var)
- the late phase (the arrow points to the right).<(var)
, >(var)
) - the value of the variable is substituted as is.<@(var)
, >@(var)
) - the value of a variable is embedded in the list in which it is calculated (such calculation must necessarily occur inside the list). { 'variables': { 'component_type': 'shared_library', 'public_api_headers': [ 'include/mylib.h', 'include/mylib_extra.h', ], 'private_headers': [ 'internals.h', ], }, 'targets': [ { 'target_name': 'mylib', 'type': '<(component_type)', # <- 'include_dirs': ['include'], 'sources': [ '<@(public_api_headers)', # <- public_api_headers '<@(private_headers)', # private_headers 'src/impl.cc', # sources ], }, ], }
<!(cmd)
and <!@(cmd)
: 'variables' : [ 'foo': '<!(echo Build Date <!(date))', ],
{ 'variables': { 'component_type%': 'shared_library', # <- % # } #... }
make
you can use the $ sign (for example, $(INCLUDES)
). Unfortunately, the use of such variables makes the assembly less portable.conditions
section allows you to declare parts of the configuration, depending on factors external to the module being assembled. For example, depending on the target operating system or the desired type of component to be assembled (a statically or dynamically linked library), it is required to change the compilation flags or add / exclude files with source code.target_conditions
section). { 'target_name': 'mylib', 'type': 'static_library', # ... 'conditions': [ ['OS=="linux"', { 'sources': ['linux_extra.cc'], # <- 'defines': ['UNIX=1'], # <- UNIX 1 }], ], }
eval()
function with the __builtin__
dictionary disabled, therefore, they obey the syntax adopted in Python for evaluating Boolean expressions. For example, several conditions can be combined with the operators and
and or
. A list of predefined variables and more detailed examples can be found on the wiki .#include
directive. In GYP, such a mechanism is implemented as a top-level list of includes
: { 'includes': ['common.gypi', 'other.gypi'], # ... }
gypi
extension and contain declarations of common variables, build configurations, header files, etc. All these declarations will be combined with the declarations of the GYP file, which will include the gypi file. Relative paths used inside the include file are calculated relative to the included file, not the including file.configurations
subsection. { 'target_defaults': { 'configurations': { 'Release': { 'conditions': [ ['OS=="linux"', { 'cflags': ['-O2'], # }], ], }, 'Debug': { 'conditions': [ ['OS=="linux"', { 'cflags': ['-g', '-O0'], # , }], # ], }, }, }, 'targets': [ # ... ], }
configurations
section should be nested in the target_defaults
section. If you forget about this, then error messages will most likely not follow, but the configuration will not work.make
, it suffices to define the BUILDTYPE
parameter. For debugging, it is also often useful to see the real commands executed by the build system. The V
(verbose) flag is responsible for this: make BUILDTYPE=Release V=1
examples
directory has two subdirectories: gtest-1.6
(component for writing unit tests, discussed above) and mini-regex
, our micro-library, which needs independent development and testing. Here is a GYP file for building the libminiregex.a
library, depending on the gtest
component: { 'includes': ['../conf.gypi'], # <- 'targets': [ { 'target_name': 'miniregex', 'type': 'static_library', 'include_dirs': ['include'], 'sources': [ 'include/miniregex.hpp', # <- 'src/miniregex.cpp', # <- ], 'direct_dependent_settings': { 'include_dirs': ['include'], }, }, { 'target_name': 'miniregex_test', 'type': 'executable', # <- 'dependencies': [ '../gtest-1.6/gtest.gyp:gtest', # <- '../gtest-1.6/gtest.gyp:gtest_main', # libminiregex, 'miniregex', ], 'sources': [ 'src/test/test_miniregex.cpp', # <- ], }, ], }
Debug
, Release
, etc.). In the absence of the required configuration, no warnings will be displayed at the design file layout stage, but when attempting to build, mysterious error messages will most likely be displayed.svn:externals
or git submodule
).mini-regex
module, go to the examples
directory and execute the familiar commands: gyp --depth=. mini-regex/miniregex.gyp make
gtest
module libraries will be gtest
, then the libminiregex.a
library, then the libminiregex.a
executable file, which can be found in the out / Debug directory, will be built. If everything is done correctly, when you run this executable file on the console should appear positive green output GTest.actions
, and the rules
section is used to define transformations. Rules can be used to build chains of transformations, in the same way as is implemented in GNU make. Rules can also be thought of as action patterns. { 'target_name': 'install', 'type': 'none', 'dependencies': ['gtest', 'gtest_main'], # <- # 'actions': [ { 'inputs': [], 'outputs': ['$(LIBRARIES)/libgtest.a', '$(LIBRARIES)/libgtest_main.a'], 'action_name': 'copy_libs', 'action': ['cp', '<(PRODUCT_DIR)/libgtest.a', '<(PRODUCT_DIR)/libgtest_main.a', '$(LIBRARIES)'], 'message': 'Copying libraries', }, { 'inputs': [], 'outputs': ['$(INCLUDES)/gtest', '$(INCLUDES)/gtest/internal'], 'action_name': 'copy_headers', 'action': ['cp', '-R', 'include/gtest', '$(INCLUDES)'], 'message': 'Copying header files', } ], }
make
will receive the INCLUDES
and LIBRARIES
via the environment or command line arguments: gyp --depth=. gtest.gyp # sudo make install INCLUDES=/usr/include LIBRARIES=/lib64
rst2html
rule, which I use to compile documentation from the RST format to the HTML format: { 'target_name': 'docs', 'type': 'none', 'sources': [ 'doc/Build.rst', 'doc/Dictionary.rst', 'doc/README.rst', ], 'rules': [{ 'rule_name': 'rst2html', 'extension': 'rst', 'inputs': ['doc/css/code.css'], 'action': ['rst2html.py', '--stylesheet-path=doc/css/code.css', '--embed-stylesheet', '<(RULE_INPUT_PATH)', '<(PRODUCT_DIR)/Doc/<(RULE_INPUT_ROOT).html'], 'outputs': ['<(PRODUCT_DIR)/Doc/<(RULE_INPUT_ROOT).html'], 'message': 'Compiling RST document <(RULE_INPUT_PATH)' \ 'to HTML <(PRODUCT_DIR)/Doc/<(RULE_INPUT_ROOT).html', }], },
extension
property specifies the extension of files that fall under the rule, and the list of inputs
defines files that are additional dependencies (that is, if they change, you must reapply the rule). The variable RULE_INPUT_PATH
bound to the absolute path of the input file of the action RULE_INPUT_ROOT
- to the base of the path of the input file (that is, without an extension). The rest I think should not cause questions.make
code (of course, this is not the code that GYP generates): BUILDTYPE ?= Debug PRODUCT_DIR ?= out/$(BUILDTYPE) HTML_OUT := $(PRODUCT_DIR)/Doc RST_DOCS := doc/Build.rst doc/Dictionary.rst doc/README.rst HTML_DOCS := $(patsubst doc/%.rst,$(HTML_OUT)/%.html,$(RST_DOCS)) .PHONY: docs docs: $(HTML_DOCS) # , $(HTML_OUT)/%.html: doc/%.rst doc/css/code.css mkdir -p $(HTML_OUT) rst2html.py --stylesheet-path=../doc/css/code.css \ --embed-stylesheet $< $@
make
, but perhaps more readable for people not experienced in GNU make
.--generator-output
option and run make
from the directory specified by the option: gyp --depth=. --generator-output=./out gtest.gyp make -C out
Source: https://habr.com/ru/post/171697/
All Articles