3

I have a question about starting the ctest. As I can understand that ctest uses CTestTestfile.cmake for the beginning of the unit test. What is the executable file? Why does ctest find it as *.exe if it is a CTestTestfile.cmake? What is wrong in my actions?

I have a folder Prj:

Prj folder picture

and folder /build with cmake output (CTestTestfile.cmake is here) as well as all ctest,cmake, etc. programs with their dll (is it right?).

Here is the text of CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
project(MyTest C)
enable_testing()
include(CTest)

set(SOURCE_EXE simple_test.c)
include_directories(include)

### The most simple test
add_executable(simple_test ${SOURCE_EXE})
add_subdirectory(src)
target_link_libraries(simple_test "./src")

add_test(NAME simple_test COMMAND simple_test)

I have received the result in Windows cmd:

cmd screen after ctest cmd

halfer
  • 19,824
  • 17
  • 99
  • 186
Koder
  • 31
  • 1
  • 2
  • 2
    Looks like you forgot to **build** the project before testing it. This would explain that ctest cannot find your executable. Also, `target_link_libraries(simple_test "./src")` seems weird: linking is performed with library **file**, but according to `add_subdirectory(src)`, `./src` is **directory**, not a *file*. – Tsyvarev Sep 19 '17 at 19:25
  • Hm..so strange. I have built project with cmake-GUI and used mingw64 compiler (64-bit Windows). Ok. After "build" should I get this executable file *.exe? Thanks! – Koder Sep 19 '17 at 21:26
  • 1
    cmake-GUI doesn't **build** the project, it just **configures** it. *Building* is performed by other system, like Make. – Tsyvarev Sep 19 '17 at 21:31
  • sorry, I can't understand, could you explain what is the sequence of this process? I should have done the procedures one by one as: configuring project with cmake-GUI (there is making of the project) --->built with Make (use Makefile in build/ directory)-----> execute tests with CTest (use *.exe file after build) in the cmd window and that's all. Is it right? – Koder Sep 19 '17 at 23:27
  • Yes, exactly this sequence. – Tsyvarev Sep 19 '17 at 23:29
  • Ok.Thanks! unfortunately, I am looking for a solution for the "build" from Makefile (I have already got a Makefile in built/ directory). A lot information for theLinux platform but for Windows I can't find a simple realization. What are the ways for that are existing? – Koder Sep 20 '17 at 00:31
  • Which [generator](https://cmake.org/cmake/help/v3.7/manual/cmake-generators.7.html) do you provide for CMake? It should be reflected at the bottom of cmake-GUI window. For build the project you should use a build tool corresponded to the generator. – Tsyvarev Sep 20 '17 at 07:31
  • I used "MinGW makefiles" and than I choose "Specify native compiler" as "x86_64-w64-mingw32-gcc.exe". After the "configure" procedure I receive an error - CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". After that I choose a make program from installed folder MinGW/mingw64/bin/mingw32-make.exe. Further I repeat the "Configure" and receive "Configuring done". I press the "Generate" button and receive "Generating done". – Koder Sep 24 '17 at 07:00
  • I receive a lot of files in build/ folder. There is "CTestTestfile.cmake" too. After this procedure I tried to build this file with Window nmake.exe utility, but I haven't got I successfull result (I can show this one). Is it right way or not? Please, if it is possible could you explain to me what are the next manipulations I should do for the "build" program and run the test. – Koder Sep 24 '17 at 07:13
  • As you have `mingw32-make.exe` specified as make program, use it for build the project. For build with `nmake.exe` you need to specify [NMake Makefiles](https://cmake.org/cmake/help/v3.7/generator/NMake%20Makefiles.html) generator. – Tsyvarev Sep 24 '17 at 07:38
  • I have done it! I tried to do the next: after getting the Makefile (with cmake-gui.exe) I copied the mingw32-make.exe into the build/ folder and from the Window cmd wrote a command "mingw32-make.exe". After that I received an expecting simple_test.exe in the same folder built/. Further, I had executed Windows cmd command "simple_test.exe" and received the results of the unit tests. That's all! – Koder Sep 26 '17 at 19:04
  • A lot of thanks for Tsyvarev, who helped me to find the way of desicion. Hats off for your work! – Koder Sep 26 '17 at 19:17

0 Answers0