MantisBT - CMake
View Issue Details
0015835CMakeCMakepublic2015-11-05 16:442016-06-10 14:31
David Ryskalczyk 
Kitware Robot 
highmajoralways
closedmoved 
AppleMac OS X10.11
CMake 3.3.2 
 
0015835: Teach BasicConfigVersion to support Apple universal binaries
CMake currently hardcodes the bitness of a built package in the .cmake config file. As Mac OS X supports universal binaries, where a package can be compiled as both 32 and 64 bit, this is inaccurate, and causes problems when linking to libraries built as universal using CMAKE_OSX_ARCHITECTURES.
This affects all versions of Mac OS X.
Build a library as a universal binary (using -DCMAKE_OSX_ARCHITECTURES=x86_64;i386); then try compiling a program that uses that library as either x86_64 or i386. One of them will work, the other will not. If the Config .cmake file is opened in an editor, it is obvious that the bitness is recorded and checked, based on the value of CMAKE_SIZEOF_VOID_P — which is inaccurate when the binary is built as universal.
A better fix might be to store a list of architectures/bitness that the package is built as, but I'm unsure of how to do this in CMake.

A patch is attached which simply ignores the bitness section of the config .cmake files when building on OS X.
No tags attached.
diff cmake-osx-universal-patch.diff (2,026) 2015-11-05 16:44
https://public.kitware.com/Bug/file/5564/cmake-osx-universal-patch.diff
Issue History
2015-11-05 16:44David RyskalczykNew Issue
2015-11-05 16:44David RyskalczykFile Added: cmake-osx-universal-patch.diff
2015-11-06 08:36Brad KingNote Added: 0039841
2015-11-06 09:23David RyskalczykNote Added: 0039844
2015-11-06 09:24David RyskalczykNote Edited: 0039844bug_revision_view_page.php?bugnote_id=39844#r1948
2015-11-06 10:33Brad KingSummaryCMake hardcodes bitness in .cmake files for universal binaries => Teach BasicConfigVersion to support Apple universal binaries
2016-06-10 14:29Kitware RobotNote Added: 0042881
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0039841)
Brad King   
2015-11-06 08:36   
The purpose of the CMAKE_SIZEOF_VOID_P check is to guard against architecture mismatches, so on OS X this block should somehow check CMAKE_OSX_ARCHITECTURES instead, at least if the project was built with that set.
(0039844)
David Ryskalczyk   
2015-11-06 09:23   
(edited on: 2015-11-06 09:24)
This would require mapping from CMAKE_OSX_ARCHITECTURES to CMAKE_SIZEOF_VOID_P:

If a project is built with CMAKE_OSX_ARCHITECTURES set to i386;x86_64 (or likewise the equivalent for iOS), then it will be built in both 32-bit and 64-bit, and both 32-bit and 64-bit void pointers are acceptable. If a project then is built as single 32-bit or 64-bit and links against a universal package, CMAKE_OSX_ARCHITECTURES may not be set at all, so there may not be anything to compare to. The only solution I can see is one that would require a hardcoded list indicating that i386 is 32-bit, x86_64 is 64-bit, etc, unless there is something in the CMake internals that can be used here — and I'm not sufficiently familiar with that.

If there's a better way to do this, I'd like to know.

(0042881)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.