MantisBT - CMake
View Issue Details
0016084CMakeCMakepublic2016-04-27 06:412016-06-10 14:31
ranjak 
Kitware Robot 
normalmajoralways
closedmoved 
iPhoneiOSany
CMake 3.5.2 
 
0016084: try_compile incorrect behavior for iOS universal build (device + simulator) with CMAKE_IOS_INSTALL_COMBINED
When configuring an iOS Xcode project using CMAKE_IOS_INSTALL_COMBINED (introduced in CMake 3.5) to produce universal binaries that contain code for both iPhone (ARM) and simulator (x86) code, I would like try_compile to compile for both the device and the simulator. However, currently, try_compile only compiles for the device.

This causes projects that rely on try_compile to be possibly misconfigured for the simulator build (which can obviously lead to build failures and/or incorrect/non-existent values for architecture-dependent parameters set at configuration time).

This problem also arises without CMAKE_IOS_INSTALL_COMBINED, if you want to use Xcode to build for both device(s) and simulator(s) without re-running CMake every time you switch between the two.

Try_compile should instead call xcodebuild twice, one time with -sdk iphoneos and the other with -sdk iphonesimulator.
Configure a project with IOS_INSTALL_COMBINED set to TRUE, and use try_compile in this project.
No tags attached.
? TryCompileIOS.cmake (6,108) 2016-04-29 05:47
https://public.kitware.com/Bug/file/5685/TryCompileIOS.cmake
Issue History
2016-04-27 06:41ranjakNew Issue
2016-04-27 16:55Gregor JasnyNote Added: 0040943
2016-04-27 17:06Brad KingNote Added: 0040944
2016-04-28 04:16ranjakNote Added: 0040945
2016-04-29 05:47ranjakFile Added: TryCompileIOS.cmake
2016-04-29 05:54ranjakNote Added: 0040946
2016-05-04 08:02Ruslan BaratovNote Added: 0041022
2016-05-09 08:10ranjakNote Added: 0041036
2016-05-11 03:20Gregor JasnyNote Added: 0041045
2016-06-10 14:29Kitware RobotNote Added: 0042990
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
(0040943)
Gregor Jasny   
2016-04-27 16:55   
More of less the same problem arises when building fat binaries. There for example check_symbol_exists does not work reliable for symbols like __i386__ or __x86_64__.

The only way I see to handle those problems is to provide some special try_compile command where one can select SDK and ARCH.
(0040944)
Brad King   
2016-04-27 17:06   
There is an undocumented CMAKE_TRY_COMPILE_OSX_ARCHITECTURES variable that tells try_compile what CMAKE_OSX_ARCHITECTURES to pass to its test project. One can set this to choose the architecture to use for try_compile checks. There is currently no such option for SDK selection.

This all comes from a fundamental design limitation of CMake in that it is really only meant to target one architecture/platform at a time. Universal binary support works only because the native tools (compiler, linker, etc.) support multiple architectures in single files with single command lines. The only safe way to get per-architecture information in the case of universal binaries is to do preprocessor checks and not try_compile.
(0040945)
ranjak   
2016-04-28 04:16   
I have started working on a wrapper for try_compile that issues two calls to the actual try_compile with setting CMAKE_OSX_SYSROOT to iphoneos and iphonesimulator. I don't know if it's a very clean approach, but I'll share it if I manage to get it to work.
(0040946)
ranjak   
2016-04-29 05:54   
I've uploaded my wrapper. It's a try_compile "overload" that issues two try_compile calls (one for device and another for simulator) and should handle every use case. That fixes the problem for me, I hope it can for others as well.
(0041022)
Ruslan Baratov   
2016-05-04 08:02   
Just for the record behaviour not related to CMAKE_IOS_INSTALL_COMBINED at all. Either *_COMBINED=TRUE or *_COMBINED=FALSE you can choose sdk by '-sdk iphoneos'/'-sdk iphonesimulator'. Actually already said: "This problem also arises without CMAKE_IOS_INSTALL_COMBINED" so I'm just clarifying this fact.
(0041036)
ranjak   
2016-05-09 08:10   
You are correct, sorry for not being clearer about that.
(0041045)
Gregor Jasny   
2016-05-11 03:20   
Just selecting any ios SDK will break with xcode containing multiple ios sdks. Please have a look at the CMakeIOSInstallCombined.cmake/_ios_install_combined_detect_sdks.

What about CMAKE_SYSTEM_FRAMEWORK_PATH (set in Platform/Darwin.cmake). It contains paths relative to the selected SYSROOT.
(0042990)
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.