Reputation: 751
I have a CMake-based C++ project that I need to integrate into a CI/CD pipeline. The pipeline has two steps, one for building, the other for testing. Creating this environment in a Docker container works like a charm, but results in a 2GB container. So I am trying to implement a multi-stage Docker build where I copy the executables into an Alpine base image. All that works, except for the cmake/ctest functionality. I want to expose the command "make test" which will execute the CMake generate target.
This is the target that CMake has created for running ctest.
# Targets provided globally by CMake.
# Special rule for the target test
test:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
/usr/bin/ctest --force-new-ctest-process $(ARGS)
.PHONY : test
The problem I can't figure out is where ctest gets the test configuration from. When I issue
ctest -N
in the container it shows no tests.
Looking for an SME on CMake to educate me how this is supposed to work.
Upvotes: 0
Views: 882
Reputation: 751
Ok, I straced ctest in the container and discovered that it was hunting down a CTestTestfile.cmake file in each of the directories that have test executables. Adding that file to the deployment container along side the executables, basically where the file is found in the build container, solves the problem.
There is a CTestTestfile.cmake at the root of the build tree, and then individual CTestTestfile.cmake files along side the test executables.
strace is your friend, although I had to learn a new trick for docker, as strace is privileged. This was the command I used to strace ctest
docker run --rm --security-opt seccomp:unconfined strace ctest -N
Upvotes: 0