2

We run some extra commands around CMake for config, build, packaging, etc.

e.g. The build commands look like this on Windows:

mkdir build
cd build
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"

cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% ..
msbuild synergy-core.sln /p:Platform="x64" /p:Configuration=%CMAKE_BUILD_TYPE% /m

There are about 50 blocks of commands like this on our CI system for various platforms and configs, so maintaining them all is really hairy. What is the best way to simplify this and make it more universal? Is there a good practice way of moving these commands into source control?

e.g. A wrapper script? Previously, I implemented hm.py in Synergy for this purpose, which was later removed in favor of moving the commands to the CI system, but this makes it more tedious to test the build system locally.

Nick Bolton
  • 38,276
  • 70
  • 174
  • 242

1 Answers1

2

Not just a full answer but a first try:

You can condense that to two lines.

cmake -H. -Bbuild -G "Visual Studio 14 2015 Win64"

runs the configuration step and

cmake --build build --target ALL_BUILD --config %CMAKE_BUILD_TYPE% -- /nologo /verbosity:minimal /maxcpucount

runs the build. The -B option of CMake is not officially documented but it creates a build directory (it might not exist before, AFAIK you might give it absolute paths too).

After configuration CMakes build tool mode comes very handy. It selects the native build tool (MSBuild for Visual Studio projects) and run that for the given target/config combination. Targets can be INSTALL, ALL_BUILD, RUN_TESTS, ... There's no need to manually set the environment variables by calling vcvarsall.bat, CMake finds the compiler itself by the explicitly given -G option if it is installed on the build machine.

See also this question for the -H option.

vre
  • 6,041
  • 1
  • 25
  • 39