Search code examples
visual-studio-2010xcode4cmake

Building for x86 and x64 platform with CMake with Xcode and Visual studio


I started using CMake pretty recently. It is a really easy script language but there are many tricks to learn and tutorials on the cmake website is not much help.

Basically I want to build my project for

  • Windows (using visual studio 2010) x86 and x64
  • Mac os (using Xcode 4) x86 and x64

Dependending on the OS and plateforme I want to link certain libraries.

I figured out for Windows that I can use WIN32 or WIN64 to set this up. But I can't find the equivalence for mac os. Can someone point me in the right direction?


Solution

  • In addition to the "if(APPLE)" and other variables that Tobias pointed you to in his answer, you can also inspect what generator you're using to make decisions on a per-generator basis if necessary.

    if(CMAKE_GENERATOR MATCHES "Xcode")
      ...
    elseif(CMAKE_GENERATOR MATCHES "Win64")
      ...
    endif()
    

    On the Mac, you can build universal binaries by setting the target property OSX_ARCHITECTURES, or the variable CMAKE_OSX_ARCHITECTURES: http://cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:OSX_ARCHITECTURES

    Alternatively, you can build two single-architecture binaries using two separate build trees with a single value in CMAKE_OSX_ARCHITECTURES for each build tree.

    On Windows, you should simply have two separate build trees, on for your 32-bit build and one for your 64-bit build.