[CMake] Running test from cmake on windows

Federico Kircheis federico.kircheis at gmail.com
Tue Aug 6 03:18:51 EDT 2019


Hello, I'm having some trouble understanding how I can execute my test 
suite uniformly on all platforms.

On GNU/Linux (with `make`), I can execute

----
cmake -S "$PROJDIR" -B "$BUILDDIR" -DCMAKE_BUILD_TYPE="$build_type" 
-DBUILD_TESTING=ON
cmake --build "$BUILDDIR"
cmake --build "$BUILDDIR" --config "$build_type" --target test -- 
ARGS="--progress"
----

(PROJDIR points to the project directory, BUILDDIR the build directory 
and build_type to Release, Debug and so on)

If I try to execute on Windows (with msvc and msbuild) the same 
commands, I get following error:

--
MSBUILD : error MSB1008: Only one project can be specified.
Switch: ARGS=--progress
--

Which is very misleading.
Removing `-- ARGS="--progress"` from the invocation yields

--
MSBUILD : error MSB1009: Project file does not exist.
Switch: test.vcxproj
--

Looking at the generated projects, I realized there is a "RUN_TESTS" target:

----
cmake -S "$PROJDIR" -B "$BUILDDIR" -DBUILD_TESTING=ON
cmake --build "$BUILDDIR"
cmake --build "$BUILDDIR" --config "$build_type" --target RUN_TESTS -- 
ARGS="--progress"
----

still yields

--
MSBUILD : error MSB1008: Only one project can be specified.
Switch: ARGS=--progress
--

This time removing `-- ARGS="--progress"` finally runs the tests:

----
cmake -S "$PROJDIR" -B "$BUILDDIR"  -DBUILD_TESTING=ON
cmake --build "$BUILDDIR"
cmake --build "$BUILDDIR" --config "$build_type" --target RUN_TESTS
----

So there are 2 questions, I'm unsure if those are bugs.

1)
Is there a target that I can use on any platform for running the tests, 
or do I need to handle every platform/build-system differently? 
RUN_TESTS is not a valid target with `make`.

2)
How can I pass `ARGS="--progress"` on windows.
This parameter is accepted by `ctest` on windows too, so it should be valid.

Regards,

Federico


More information about the CMake mailing list