1

So far this is my command line to start a Cmake build:

cmake .. --build .. -DCMAKE_BUILD_TYPE:STRING=release

This is good and works, and it generates a

Project.sln

and

tests/ProjectTests.sln

solution files.

I could open solution files with visual studio and build them and run tests from Visual Studio, however I'm running the script from a Continuos Integration server and hence I need to also start the build and run the tests from command line: how can I do that?


I need to

  1. Build the library (Project.sln)
  2. Build the test executable (tests/ProjectTests.sln)
  3. Run the tests (calling CTest from the same folder in wich Tests.exe is located)

Until now I tried to build using the command

msbuild Infectorpp2.sln

But that is failing (error log just to long to post), if that can helps here's the script on github. The main problem is that I'm not able to finally generate the Tests.exe file, once that is done calling CTest on it is trivial. Thanks in advance.

CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69

2 Answers2

6

As mentioned in the documentation, the general syntax for building a target (i.e. after generating the .sln files with cmake -G) using CMake is:

cmake --build . [--config <config>] [--target <target>] [-- -i]

It will invoke the appropriate compiler/toolchain commands for you.

See cmake(1) for the full list of arguments accepted by the cmake command.

maddouri
  • 3,737
  • 5
  • 29
  • 51
  • When I add something as "config" or "target" options, cmake insist at saying that he don't find the source directory inside "build/ALL_BUILD" folder or inside the "build/Release" folder. I think just the --build command is bugged. I already tried that part of the documentation without success – CoffeDeveloper Oct 11 '15 at 22:58
  • I've noticed that you've used `..` (i.e. parent directory), but I think it should be `cmake --build .` (i.e. current directory, i.e. where the _generated_ cmake files are). – maddouri Oct 11 '15 at 23:12
  • thanks, now I'm able to build the library, but still the tests executable is not generated :/ – CoffeDeveloper Oct 11 '15 at 23:33
  • Is this related to the issue raised by [CMake & CTest : make test doesn't build tests](http://stackoverflow.com/q/733475/865719) ? – maddouri Oct 11 '15 at 23:38
  • I do `--build . --target ALL_BUILD` wich should be equivalent to `make all` wich also build test files, anyway I'll try now to workaround that, in case it works it's definitely a Cmake bug. Thanks – CoffeDeveloper Oct 11 '15 at 23:42
  • Definitely a Cmake bug, I have to refactor the project to use `philsquared/Catch` framework. Thanks for your help – CoffeDeveloper Oct 12 '15 at 00:00
0

To complete the information for random browsers, the problem was finally wrong signature of functions.

CMake test driver requires signature like these:

int filename(int, char*[])

GCC/Clang accept this signature

int filename(int, char**)

while Visual studio require

int filename(int char**const) //still works with GCC/Clang luckily
CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69