3

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?

Matthias
  • 4,481
  • 12
  • 45
  • 84
lollancf37
  • 1,105
  • 3
  • 15
  • 27
  • *"Windows (using visual studio 2010) x86 and x64"* - Clang can be used for Windows VS toolchain, too. See [Getting Started with the LLVM System using Microsoft Visual Studio](http://llvm.org/docs/GettingStartedVS.html). – jww Jun 18 '16 at 00:04

2 Answers2

3

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.

DLRdave
  • 13,876
  • 4
  • 53
  • 70
  • I got the point on windows, I came to discover that WIN64 does not the trick, so I used CMAKE_CL_64. However I must say that I didn't get what you were saying for mac os. I will dig into it. Thanks – lollancf37 Aug 19 '11 at 14:32
1
if (APPLE)
....
endif(APPLE)

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

Tobias Schlegel
  • 3,970
  • 18
  • 22