Reputation: 189
With CMake version 3.19.2 I can use --target
argument to build specific targets, instead of all
.
For example --target tests
to build tests.
However, with CMake 3.22.1 I'm getting an error like this:
CMake Error: Unknown argument --target
CMake Error: Run 'cmake --help' for all supported options.
You can see the manual of CMake here:
https://cmake.org/cmake/help/latest/manual/cmake.1.html
(There is a drop-down list for version selection)
It describes the --target
argument, and It doesn't seem any different from what it was earlier. Nonetheless, after switching from 3.19.2 to 3.22.1 it doesn't let me use --target
.
@EDIT thank you for your feedback, here's what I use:
cmake -G Ninja -DCROSS_COMPILER_PREFIX=<some_prefix> -Dsomeothervariables=1 --target tests $directory_with_cmake_project
It works with 3.19.2, but executing the same thing with cmake 3.22.1 causes the error.
I expect that the order of providing -G Ninja
, variables, target directory and --target
matters, but I haven't managed to get it to work in any order I could think of.
Upvotes: 6
Views: 10711
Reputation: 141010
CMake is composed of stages - first you configure the project, then you build it:
cmake <sourcedir> ...
https://cmake.org/cmake/help/v3.22/manual/cmake.1.html#generate-a-project-buildsystemcmake --build <builddir> ...
https://cmake.org/cmake/help/v3.22/manual/cmake.1.html#build-a-project--target
argument if for the build stage, and it is invalid for configuration stage, hence your error.
Upvotes: 7
Reputation: 82461
CMake prints this message, if you haven't specified a directory to build by passing --build <some dir>
first. (The --target
option only if mentioned in this usage version of the cmake command line tool, see the documentation.)
Wrong
cmake --target foo
CMake Error: Unknown argument --target
CMake Error: Run 'cmake --help' for all supported options.
Correct
(assuming in the subdirectory build
of the current working directory contains a configured cmake project with a target foo
).
cmake --build build --target foo
Upvotes: 6