Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins + Windows + CMake + multiple build types (Debug, Release)

How can I make Jenkins do the following?

Checkout trunk/ from SVN, then build configurations Debug and Release using CMake, without having duplicate jobs for the configurations.

like image 842
Andreas Haferburg Avatar asked May 23 '12 10:05

Andreas Haferburg


People also ask

How do you build in debug mode Cmake?

Building in debug modeFor single-configuration generators, you can build your code with -DCMAKE_BUILD_TYPE=Debug to get debugging flags. In multi-configuration generators, like many IDEs, you can pick the configuration in the IDE.

What is Cmake_build_type?

Specifies the build type on single-configuration generators (e.g. Makefile Generators or Ninja ). Typical values include Debug , Release , RelWithDebInfo and MinSizeRel , but custom build types can also be defined.

What is the default Cmake build type?

Build typesDebug (the default build type) Release. RelWithDebInfo (Release with debugging information) MinSizeRel (Release optimized for size)


2 Answers

Took me a while to figure this out. Here's how I managed to do it.

  1. Create a free-style job "Checkout". This job is going to do all the stuff that doesn't depend on the configuration type (Debug/Release).
  2. Under "Source Code Management" select Subversion
  3. Fill in the Repository URL. Probably a good idea to make it point to /trunk.
  4. Set Local module dir to "." (no quotes)
  5. As Check-out Strategy "Emulate clean" is nice
  6. Build trigger Poll SCM, set Schedule to "5 * * * *" to check every 5 minutes.
  7. Now under Advanced Project Options check 'Use custom workspace' and set the dir to e.g. "c:/src". We don't want Jenkins to use its internal workspace, because we want other jobs to be able to access the source.
  8. Under Build add the following Windows batch command, which is used to clean the build dir. For some reason, CMake doesn't provide a way to do this.

    cd c:\
    rmdir /S /Q build
    mkdir build
    cd build
    
    cmake --version
    rem optionally: svn info c:\src
    cmake -G "Visual Studio 10" c:\src
    
  9. Create another job "Build", this time make it a "multi-configuration" job. This job is going to run for each configuration (Debug/Release).

  10. First, set the Build Triggers to build after job "Checkout"
  11. Now under Configuration Matrix add an axis "configuration" with values "Debug Release" (whitespace = separator). Unfortunately, the CMake builder plugin for Jenkins doesn't work with multi-configuration jobs. We can't even use cmake --build, because it always builds the Debug configuration. To build, we have to use another batch script:

    cd c:\build
    call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
    msbuild ALL_BUILD.vcxproj /verbosity:minimal /maxcpucount:1 /property:Configuration=%configuration%
    

If you want to build the entire solution, specify the .sln file instead of ALL_BUILD.vcxproj. If you only want to build a specific project, use

    msbuild <solution>.sln /target:<project>
like image 186
Andreas Haferburg Avatar answered Sep 27 '22 20:09

Andreas Haferburg


Use Jenkins Matrix job. Define one of the axes as build_mode with values Debug and Release. You then run CMake that will create both configurations for the compilation tool you'll be using (XCode, gcc, VisualStudio, etc.). You can then use build_mode as if it were an environment variable and pass it to build steps that do actual compilation.

like image 38
malenkiy_scot Avatar answered Sep 27 '22 21:09

malenkiy_scot