I work for a company that is considering porting one of its major software products to CMake. In the course of developing a CMake based build system for the Mac port of the product the following issue came up. What follows is a description of the problem and a proposed solution for the problem. I have submitted this problem as bug (feature) # 8725 to the cmake bug tracker.
Thanks, Steve Consider the following source tree on OSX: TopDir/ - CMakeLists.txt - src1.c - src2.c Where src1.c is compiled into a 32-bit(i386) binary that links with libExample1.a a non-Universal i386 architecture library. Where src2.c is compiled into a 64-bit(x86_64) binary that links with libExample2.a a non-Universal x86_64 architecture library. libExample1.a and libExample2.a exist outside of the scope of the source tree and cannot be rebuilt to be Universal libraries. Here are the basic entries in CMakeLists.txt: add_executable(src1 src1.c) target_link_libraries(src1 Example1) set_target_properties(src1 PROPERTIES COMPILE_FLAGS "-arch i386" LINK_FLAGS "-arch i386") add_executable(src2 src2.c) target_link_libraries(src2 Example2) set_target_properties(src2 PROPERTIES COMPILE_FLAGS "-arch x86_64" LINK_FLAGS "-arch x86_64" When generating a build system using the 'Unix Makefiles' generator this CMakeLists.txt will correctly build and link src1 and src2 as i386 and x86_64 binaries respectively. When generating a build system using the Xcode generator this CMakeLists.txt will generate an Xcode project that cannot correctly build src2. CMake provides default values for CMAKE_OSX_ARCHITECTURES. When the Xcode generator runs, it will use the default value for CMAKE_OSX_ARCHITECTURES (i386 in this case (assume a Core 2 Duo processor)) and the Xcode project will not have any explicit reference to i386 architectures when it is generated. Xcode will by default use the 'native' architecture for the given machine and automatically append -arch i386 to the compile/link commands for src1 and src2. Given that src2 must be an x86_64 architecture only binary (see dependency on libExample2.a) then src2 cannot link correctly. Explicitly setting CMAKE_OSX_ARCHITECTURES to x86_64 in the CMakeLists.txt file does not solve the problem but rather switches the case to src1 which must be compiled as an i386 architecture only binary. Explicitly setting CMAKE_OSX_ARCHITECTURES to x86_64;i386 violates the requirement that the binaries only have i386 and x86_64 architectures respectively. This behavior makes it impossible to have working Makefile and Xcode build systems generated for this source tree. To put it another way, you cannot generate an Xcode project that contains targets with strict exclusive architecture requirements where those requirements vary by target. In order to correct this deficiency, we need to have a property for targets that allows a target to override the project level CMAKE_OSX_ARCHITECTURES setting. I propose the use of the following property names: OSX_ARCHITECTURES and OSX_ARCHITECTURES_<CONFIG> The CMAKE_OSX_ARCHITECTURES property sets the target binary architecture for targets on OSX. Use CMAKE_OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a per-configuration basis. <CONFIG> is an upper-case name (ex. CMAKE_OSX_ARCHITECTURES_DEBUG).
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake