I am experiencing a cross-compiling issue that I believe is related to how toolchain files interact with the configure-time compiler checks. For reference, I am targeting the iOS 4.2 SDK. I have a toolchain file that sets CMAKE_C_FLAGS, CMAKE_CXX_FLAGS, CMAKE_C_LINK_FLAGS, and CMAKE_CXX_LINK_FLAGS with appropriate flags for the iOS platform, in particular "-arch armv6 -arch armv7". The toolchain file also sets the proper C and C++ compilers.<div>
<br></div><div>When CMake is executed and the C compiler is tested, the toolchain-specified compiler arguments are passed to the link line, but *not* the compile line (according to the error output). Since the compile line does not contain the "-arch" arguments, the generated object file is for i386. However, since the link line contains these flags, the linker tries to link ARM code and fails.</div>
<div><br></div><div>Are there any additional variables I should be setting in addition to CMAKE_C_FLAGS and CMAKE_CXX_FLAGS in order to get the compiler tests to use the right flags? If I add the "-arch" flags using ADD_DEFINITIONS(), they are passed to the compiler test and it succeeds. That seems like a hack and not a proper solution, though.</div>
<div><br></div><div>Below is the CMake output that prints the values of CMAKE_*_FLAGS as set by the toolchain file, as well as the compile and link lines used by CMake.</div><div><br></div><div>I am using CMake 2.8.3 on Snow Leopard 10.6.5.</div>
<div><br></div><div>CMake Output:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_C_FLAGS: -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_CXX_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_C_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_CXX_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_C_FLAGS: -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_CXX_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_C_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- CMAKE_CXX_LINK_FLAGS -arch armv6 -arch armv7 -pipe -no-cpp-precomp --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- The C compiler identification is GNU</font></div><div><font class="Apple-style-span" face="'courier new', monospace">-- The CXX compiler identification is GNU</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">-- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2</font></div><div><font class="Apple-style-span" face="'courier new', monospace">-- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -- broken</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> The C compiler</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2" is not</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> able to compile a simple test program.</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> It fails with the following output:</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Change Dir: /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Run Build Command:/usr/bin/make "cmTryCompileExec/fast"</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> CMakeFiles/cmTryCompileExec.dir/build</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> /opt/local/bin/cmake -E cmake_progress_report</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/CMakeFiles</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> 1</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -c</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/testCCompiler.c</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Linking C executable cmTryCompileExec</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> /opt/local/bin/cmake -E cmake_link_script</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> armv6 -arch armv7 -pipe -no-cpp-precomp</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -o cmTryCompileExec</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> was built for i386 which is not the architecture being linked (armv6)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Undefined symbols for architecture armv6:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> "_main", referenced from:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> start in crt1.3.1.o</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> ld: symbol(s) not found for architecture armv6</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> collect2: ld returned 1 exit status</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> was built for i386 which is not the architecture being linked (armv7)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Undefined symbols for architecture armv7:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> "_main", referenced from:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> start in crt1.3.1.o</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> ld: symbol(s) not found for architecture armv7</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> collect2: ld returned 1 exit status</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> lipo: can't open input file:</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> /var/folders/pS/pSWOJvZ-FDS4A2Eo7TwIzE+++TI/-Tmp-//ccKkL4CZ.out (No such</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> file or directory)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> make[1]: *** [cmTryCompileExec] Error 1</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> make: *** [cmTryCompileExec/fast] Error 2</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"> CMake will not be able to correctly generate this project.</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">Call Stack (most recent call first):</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> CMakeLists.txt:30 (project)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">-- Configuring incomplete, errors occurred!</font></div>
</div><div><br></div><div><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>
</div>