Search code examples
c++visual-studiovisual-c++cmakewindows-store-apps

CMake VS different binaries for different configs


I'm sorry if this might be a stupid question but I am very new to CMake and I trying to figure out how to do something that does not appear to be very straight forward or really documented (directly at least...).

I am trying to use CMake to create a cross-platform GLES application and I am planning on using ANGLE (https://github.com/MSOpenTech/angle) in order to support Windows Store and Windows Phone. I am currently stuck at trying to get the following bit of the template provided by the template ported to a CMake file:

<AngleBinPath Condition=" '$(AngleBinPath)' == '' ">$(AngleRootPath)\winrt\8.1\windows\src\$(Configuration)_$(Platform)\</AngleBinPath>

This variable is then used later on as follows in order to link to the libraries:

<Link>
  <AdditionalDependencies>$(AngleBinPath)lib\libGLESv2.lib;$(AngleBinPath)lib\libEGL.lib;%(AdditionalDependencies)</AdditionalDependencies>
...

And then finally to copy the DLL files:

<ItemGroup Label="ANGLE">
    <None Include="$(AngleBinPath)libEGL.dll">
      <DeploymentContent>true</DeploymentContent>
    </None>
    <None Include="$(AngleBinPath)libGLESv2.dll">
      <DeploymentContent>true</DeploymentContent>
    </None>
</ItemGroup>

Now of course there is a decent amount of info regarding how one should go about using external libraries with CMake but I could not find any information regarding how I should go about implementing something like this where there are different binaries for each architecture as well as for Debug and Release. I guess that this must be a common problem but it has me stumped. Any ideas?

PS. I guess having flags on the CMake side to generated different VS projects for each configuration would work as a last resort but it will probably be a real pain having to have so many projects when a single one can do under normal circumstances.


Solution

  • Since version 3.0 CMake has generator-expressions, which is actually a nice thing for express config-specific logic for multiconfig IDE like VS.

    Linking:

    target_link_libraries(your_target
        ${AngleRootPath}\winrt\8.1\windows\src\$<CONFIG>_$<PLATFORM_ID>\lib\libGLESv2.lib)
    

    Installing:

    install(FILES
        ${AngleRootPath}\winrt\8.1\windows\src\$<CONFIG>_$<PLATFORM_ID>\lib\libGLESv2.lib
        ...)