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 &quot;-arch armv6 -arch armv7&quot;.  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 &quot;-arch&quot; 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 &quot;-arch&quot; 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, monospace">-- The C compiler identification is GNU</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-- The CXX compiler identification is GNU</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, 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="&#39;courier new&#39;, 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="&#39;courier new&#39;, monospace">CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  The C compiler</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  &quot;/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2&quot; is not</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  able to compile a simple test program.</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  It fails with the following output:</font></div><div>
<font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">   Change Dir: /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  </font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  Run Build Command:/usr/bin/make &quot;cmTryCompileExec/fast&quot;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CMakeFiles/cmTryCompileExec.dir/build</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /opt/local/bin/cmake -E cmake_progress_report</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/CMakeFiles</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  1</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -c</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/testCCompiler.c</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  Linking C executable cmTryCompileExec</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /opt/local/bin/cmake -E cmake_link_script</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  armv6 -arch armv7 -pipe -no-cpp-precomp</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  -miphoneos-version-min=4.2</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -o cmTryCompileExec</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  was built for i386 which is not the architecture being linked (armv6)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  Undefined symbols for architecture armv6:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    &quot;_main&quot;, referenced from:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        start in crt1.3.1.o</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  ld: symbol(s) not found for architecture armv6</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  collect2: ld returned 1 exit status</font></div><div>
<font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  was built for i386 which is not the architecture being linked (armv7)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  Undefined symbols for architecture armv7:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    &quot;_main&quot;, referenced from:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">        start in crt1.3.1.o</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  ld: symbol(s) not found for architecture armv7</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  collect2: ld returned 1 exit status</font></div><div>
<font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  lipo: can&#39;t open input file:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  /var/folders/pS/pSWOJvZ-FDS4A2Eo7TwIzE+++TI/-Tmp-//ccKkL4CZ.out (No such</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  file or directory)</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  make[1]: *** [cmTryCompileExec] Error 1</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  make: *** [cmTryCompileExec/fast] Error 2</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  </font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  </font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CMake will not be able to correctly generate this project.</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Call Stack (most recent call first):</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CMakeLists.txt:30 (project)</font></div>
<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, 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>