The top-level CMakeLists.txt contains:
include(CTest)add_subdirectory(lib)add_subdirectory(demo)add_subdirectory(test)lib/CMakeLists.txt is essentially:
add_library(MyLib <sources>)demo/CMakeLists.txt is essentially:
add_executable(Demo demo.c)target_link_libraries(Demo MyLib)test/CMakeLists.txt is just:
add_test(NAME Demo COMMAND Demo)From a gitlab-runner, we execute:
cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX=C:\opt\x64 -B. ..cmake --buildctest --output-on-failureThe first two steps succeed; the third one fails with:
Start 1: Demo1/1 Test #1: Demo .......................Exit code 0xc0000135***Exception: 0.03 secIf I retry:
cmake --installctestthen the test succeeds. So the sole problem is that build/lib/mylib.dll is not found when running ctest. Whereas C:\opt\x64\lib is in PATH, and therefore the DLL is found after cmake --install. Which, however, is not what we want: ctest shall always use the fresh DLL from the current build, not the installed version.
Under Linux, everything works correctly. Why doesn't it for Windows and MinGW? Is this a bug in CMake? How can we work around this so that ctest executes correctly on all platforms?