lollancf37
lollancf37

Reputation: 1125

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

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?

Upvotes: 3

Views: 2693

Answers (2)

DLRdave
DLRdave

Reputation: 14280

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.

Upvotes: 3

Tobias Schlegel
Tobias Schlegel

Reputation: 3970

if (APPLE)
....
endif(APPLE)

more information: http://cmake.org/Wiki/CMake_Useful_Variables#System_.26_Compiler_Information

Upvotes: 1

Related Questions