0

I am on a pi trying to teach myself cmake for a pico project. I'm following the CMAKE tutorial on cmake.org.

I'm confused by the results at Step 4 Installing and Testing. After I build the project, I can run ctest -N and ctest -VV in the build directory and all tests run and pass 100%. After I cmake --install . --prefix "../install" I can run ctest -n ../install/bin and the tests will run and pass. However the tutorial says to cd into the bin directory and run the tests. If I do that, no tests are found.

Part of me is satisfied that the tests are working, but I do not get how running the tests in /install/bin would find no tests to run.

cmake version: 3.18.4 raspberry pi4: bullseye

Mon

MechMon
  • 3
  • 2
  • As a side note, you don't need to learn too much cmake to work with the pico. just understanding the build flow i.e. mkdir build; cd build; cmake ..; make; is sufficient. You can copy the CMakeLists.txt from any of the examples and edit them to what you need. You won't be using cmake --install with the pico. – Daniel Garcia Aug 28 '22 at 02:35
  • @DanielGarcia I like to know the tools I'm using. I should have realized to check the **DEFINITION** when I did not get the expected behavior, instead of assuming... Thanks! – MechMon Aug 28 '22 at 14:22
  • 1
    @JamesRisner I like using relative paths because my terminal window is small, and my path is long... – MechMon Aug 28 '22 at 14:34
  • the docs say: "_and then cd to the **binary** directory_". Not- "_cd into the **bin** directory_". What you call the "build" directory, CMake official terminology calls the "binary" directory. The binary directory is [whatever you pass to `-B`](https://cmake.org/cmake/help/latest/manual/cmake.1.html#generate-a-project-buildsystem) when invoking cmake to generate your buildsystem. Let me know if this is an appropriate answer and I write it as an answer. – starball Sep 03 '22 at 23:28

1 Answers1

2

cmake --install is not going to copy the CMakeLists.txt to ../install. It copies the files you tell it to install with the install() directive.

CMakeLists.txt is what tells ctest what tests there are to run. So when you're in your source folder, ctest sees what tests to run. When you're in your install directory, it won't find any tests to run.

Daniel Garcia
  • 462
  • 3
  • 8
  • That makes sense, kinda. I was thinking the cmake file was integrating the tests into the binary so the end user would be able to run the tests as well. From the tutorial, "Rebuild the application and then cd to the binary directory and run the ctest executable: ctest -N and ctest -VV. For multi-config generators (e.g. Visual Studio), the configuration type must be specified with the -C flag." I can accept that answer, it is how the system is behaving, just wish the documentation matched. – MechMon Aug 28 '22 at 02:00
  • I was looking at that too. The statement "Rebuild the application and then cd to the binary directory" doesn't make much sense. They don't really make it clear what the binary directory is, but according to this line in the cmake example: `install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"` the binary directory (PROJECT_BINARY_DIR) is the one with your source code in it. – Daniel Garcia Aug 28 '22 at 02:33