Open zosrothko opened 7 years ago
Thanks for opening this issue @zosrothko. Could you clarify what you mean by "cannot specify"? You can pass the compiler flag directly at the binary level. If you need are talking about mixing the dependency, unfortunately, variant needs to match each other. For example, linking debug with release variant isn't easily achievable.
On Poco for example, the static libraries are coming with 2 link modes (or variant?) together with release/debug variants
Poco/lib/PocoCppParserMD.lib
Poco/lib/PocoCppParserMDd.lib
Poco/lib/PocoCppParserMT.lib
Poco/lib/PocoCppParserMTd.lib
Thus, it seems to me there no way to have both. With a compiler flag, one can get either the MD one, either the MT one.
Right, in this case, you want to create an additional variant of your binaries. On the top of my head, you can either use flavors, platform or build type to map a new variant and use extended properties to register some modeling information around this linkage type. Since this is windows specific, I would use a second set of Windows platform definition that explicitly model MD vs MT, like:
platforms {
winMD {
operatingSystem 'windows'
ext.isMD = { true }
}
winMT {
operatingSystem 'windows'
ext.isMD = { false }
}
}
// later you can use
binaries.all {
if (targetPlatform.operatingSystem.windows && targetPlatform.isMD()) {
// ...
}
}
A deeper model can be created. It really depends on how it's used.
OK that's a solution which seems more a workaround . It will overbloat the top level build.gradle script with multiple platforms definition. There will be
platforms {
win32MD
win32MT
win64MD
win64MT
}
...
targetPlatform "win32MD"
targetPlatform "win32MT"
targetPlatform "win64MD"
targetPlatform "win64MT"
which will double the overall build time.
I would have prefered an integrated solution by adding the specification of a StaticDynLibraryBinarySpec so the script could be
binary {
withType(StaticLibraryBinarySpec) { // static library with static runtime
cppCompiler.args "/MT"
}
withType(StaticDynLibraryBinarySpec) { static library with dynamic runtime
cppCompiler.args "/MD"
}
}
Hi
Unless I am missing something, one cannot specify to build a StaticLibraryBinarySpec linking the C++ runtime as a shared library or linking the C++ runtime as a static library. For Windows, Here the compiler flags to set for VisualStudio
As use case, both Poco and Boost are providing this feature (both in building from source or as a packaged product)