How to explicitly specify a source outside the tree in CMake?

I looked at this post: Using CMake to Statically Link to a Library Outside of a Project . But it’s still hard for me to understand what this means:

add_subdirectory(/path/to/the/library/source/directory subproject/grzeslib) 

I assume that "/ path / to / the / library / source / directory" means the path from the hard drive, but I do not understand what "subproject / grzeslib" means. Now I tried:

 include_directories(../path/to/dir) add_subdirectory (../path/to/dir .) 

But I get a detailed warning. Is there a better way to do this?

+7
source share
2 answers

The second parameter is the output directory for target results from this subdirectory.

From the documentation here: https://cmake.org/cmake/help/v3.3/command/add_subdirectory.html

add_subdirectory

Add a subdirectory to the assembly.

 add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL]) 

Add a subdirectory to the assembly.

  • Source_dir indicates the directory in which the source CMakeLists.txt file and code files are located. If this is a relative path, it will be evaluated relative to the current directory (typical use), but it can also be an absolute path.
  • The binary_directory specifies the directory in which to put the output files. If this is a relative path, it will be evaluated relative to the current output directory, but it can also be an absolute path. If binary_dir is not specified, the value of source_dir will be used before extending any relative path (normal use).
  • The CMakeLists.txt file in the specified source directory will be immediately processed by CMake before continuing processing in the current input file after this command.
  • If the argument EXCLUDE_FROM_ALL is specified, then the targets in the subdirectory by default will not be included in the ALL target of the parent directory and will be excluded from IDE project files. Users must explicitly create goals in a subdirectory. This is intended to be used when the subdirectory contains a separate part of the project, which is useful but not required, for example, a set of examples. Typically, a subdirectory should contain its own call to the project () command so that a complete build system is generated in the subdirectory (for example, a VS IDE solution file). Note that inter-target dependencies are superior to this exception. If the target created by the parent project depends on the target in the subdirectory, the target of the dependent will be included in the build system of the parent project to satisfy the dependency.
+13
source

From the documentation

Add a subdirectory to the assembly. Source_dir indicates the directory in which the source CMakeLists.txt file and code are located. If this is a relative path, it will be evaluated relative to the current directory (typical use), but it can also be an absolute path. Binary_dir indicates the directory in which to place the output files. If this is a relative path, it will be evaluated relative to the current output directory, but it can also be an absolute path. If binary_dir is not specified, the value of source_dir will be used before extending any relative path (typical use). The CMakeLists.txt file in the specified source directory will be processed immediately by CMake before processing into the current input file continues beyond this command

In your example, all binaries created in the directory "/ path / to / the / library / source / directory" will be placed in "subproject / grzeslib", it is good to "clear" the source files.

+2
source

Source: https://habr.com/ru/post/1242501/


All Articles