CPP plugin issues with gradle 1.11

Hi gradle expert,

I am using gradle 1.11(1.11-20131217230034+0000) to build our visual studio projects.

Environment: Windows 7, visual studio 2012 professional,

I have the following issues with building: 1. In build/tmp/…/options.txt file I see the default include path and lib path for vcinstall and windowsSDk are

“/IC:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include”

“/IC:\Program Files (x86)\Windows Kits\8.0\Include\shared”

“/IC:\Program Files (x86)\Windows Kits\8.0\Include\um”

“/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib”

“/LIBPATH:C:\Program Files (x86)\Windows Kits\8.0\lib”

but for the building, I still need to add include path “C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/atlmfc/include” for compilation, and path “C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x86” for lib linking, why these paths are not included? As I know, visual studio include these paths.

  1. How can I get vcinstallDir and windows sdk dir at gradle configuration time? I have visulCpp toolchain, but I always get null of its installDir and WindowsSdk dir. I am trying to add some other paths like 1 mentioned which gradle doesn’t include.

  2. How can I get the output path of object files at gradle configutaion time in binaries.all{} block. If configuration with buildtypes and platforms, the output path is different, how to locat path “build\objectFiles\mainSharedLibrary\x86Release\mainCpp”?

How can I get vcinstallDir and windows sdk dir at gradle configuration time? I have visulCpp toolchain, but I always get null of its installDir and WindowsSdk dir. I am trying to add some other paths like 1 mentioned which gradle doesn’t include.

This is a limitation of the current implementation. It’s on the list of things to add.

How can I get the output path of object files at gradle configutaion time in binaries.all{} block. If configuration with buildtypes and platforms, the output path is different, how to locat path “build\objectFiles\mainSharedLibrary\x86Release\mainCpp”?

This will be different for each source set in a binary. What do you want to do with this path?

Hi Deboert,

I want to add the precompiled header output file to objecFiles path too.

Adding these files to the ‘objectFiles’ directory would effectively make them inputs to the linker. If that’s what you want, you’re probably better off adding these as additional inputs to the link task, rather than just putting them in the same directory.

myBinary.tasks.link.source "path/to/precompiled/headers"

It looks like the ‘tasks’ property is not yet in the DSL reference: fixing that now and will post a link when it’s available.

Out of interest, how are you creating the precompiled headers?

I mean the pch file created to objectFiles path, like configured in vs C/C+±>Precompiled Headers->$(IntDir)\Logging.pch,

I want to add args to cppCompiler like:

binaries.all {
....
  if(file('Private/PrecompiledHeaders.h').exists())
{
      cppCompiler.args "/FIPrivate/PrecompiledHeaders.h"
      cppCompiler.args '/Yu"Private\PrecompiledHeaders.h"'
      cppCompiler.args '/Fp"${objectFilesPath}\Logging.pch"'
}
  ...
}

Anyway this part doesn’t work currently, it will perfect if you have DSL like myBinary.tasks.link or myBinary.tasks.compile to get the compile and link task for a binary, then I think I can get objectFileDir from compile task.

By the way, how about my first question, how to get the vc install path and sdk path, now I have hard code like:

cppCompiler.args "/IC:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/atlmfc/include"
linker.args "/LIBPATH:C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x86"

The DSL reference has been updated to include the tasks for a binary.

Note that there may be multiple compile tasks for a binary. ‘NativeBinaryTasks’ extends ‘DomainObjectSet’, meaning that you can do:

myBinary.tasks.withType(CCompile) {
    .. configure each C compile task here.
}

Here’s the DSL reference for the CCompile task (others are there too): http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.language.c.tasks.CCompile.html