<div class="gmail_quote">On Tue, Dec 14, 2010 at 4:45 AM, Johan Björk <span dir="ltr">&lt;<a href="mailto:phb@spotify.com">phb@spotify.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Justin,<div><br></div><div>I&#39;m very unsure if this is the correct solution, but it worked for me. I haven&#39;t been able to find any good documentation stating how the CMakeCache interacts with other parts of CMake. </div>

<div><br></div><div>My assumption is that since CMAKE_C{XX}_FLAGS is supposed to allow the user to set optional compilation flags, it prefers the value in the cache versus the one from the toolchain file.</div><div><br></div>

<div>From one of my toolchain files, reproduce as necessary for CMAKE_C_FLAGS:</div><div><div>SET(CMAKE_CXX_FLAGS &quot;${CMAKE_C_FLAGS} -fno-rtti&quot; CACHE STRING &quot;&quot; FORCE)</div></div></blockquote><div><br></div>
<div>I&#39;ll have to give that a try.  For now, I&#39;m getting around the problem by setting the flags within the parent CMakeLists.txt script after loading the toolchain file.</div><div><br></div><div>I&#39;m really not sure what the &quot;best practice&quot; is for this situation.  The compiler will work and can be tested without the &quot;-arch&quot; flags, but the flags are necessary to build for the *right* architecture.  Most cross-compilers will only produce binaries for the target system, so the point is moot.  The iOS compilers, however, will generate code for Intel and ARM so I&#39;m not sure if testing the i386 back-end when I&#39;m targeting ARM is the right way or not.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div><br></div><div>Cheers</div>
<div>/Johan</div><div><br></div><br><div class="gmail_quote"><div><div></div><div class="h5">On Mon, Dec 13, 2010 at 4:49 PM, Justin Holewinski <span dir="ltr">&lt;<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>&gt;</span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">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 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 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 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 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 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 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 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 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 face="&#39;courier new&#39;, monospace">-- The C compiler identification is GNU</font></div><div><font face="&#39;courier new&#39;, monospace">-- The CXX compiler identification is GNU</font></div>
<div><font 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 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 face="&#39;courier new&#39;, monospace">CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):</font></div><div><font face="&#39;courier new&#39;, monospace">  The C compiler</font></div>


<div><font face="&#39;courier new&#39;, monospace">  &quot;/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2&quot; is not</font></div><div><font face="&#39;courier new&#39;, monospace">  able to compile a simple test program.</font></div>


<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  It fails with the following output:</font></div><div>
<font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">   Change Dir: /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  </font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">  Run Build Command:/usr/bin/make &quot;cmTryCompileExec/fast&quot;</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">  /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make</font></div><div><font face="&#39;courier new&#39;, monospace">  CMakeFiles/cmTryCompileExec.dir/build</font></div>


<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  /opt/local/bin/cmake -E cmake_progress_report</font></div>
<div><font face="&#39;courier new&#39;, monospace">  /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/CMakeFiles</font></div><div><font face="&#39;courier new&#39;, monospace">  1</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2</font></div>
<div><font face="&#39;courier new&#39;, monospace">  -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include</font></div><div><font face="&#39;courier new&#39;, monospace">  -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -c</font></div>


<div><font face="&#39;courier new&#39;, monospace">  /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/testCCompiler.c</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  Linking C executable cmTryCompileExec</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  /opt/local/bin/cmake -E cmake_link_script</font></div>
<div><font face="&#39;courier new&#39;, monospace">  CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">  /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch</font></div><div><font face="&#39;courier new&#39;, monospace">  armv6 -arch armv7 -pipe -no-cpp-precomp</font></div>


<div><font face="&#39;courier new&#39;, monospace">  --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk</font></div><div><font face="&#39;courier new&#39;, monospace">  -miphoneos-version-min=4.2</font></div>


<div><font face="&#39;courier new&#39;, monospace">  CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -o cmTryCompileExec</font></div><div><font face="&#39;courier new&#39;, monospace">  -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib</font></div>


<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>


<div><font face="&#39;courier new&#39;, monospace">  was built for i386 which is not the architecture being linked (armv6)</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">  Undefined symbols for architecture armv6:</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">    &quot;_main&quot;, referenced from:</font></div><div><font face="&#39;courier new&#39;, monospace">        start in crt1.3.1.o</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  ld: symbol(s) not found for architecture armv6</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  collect2: ld returned 1 exit status</font></div><div>
<font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font face="&#39;courier new&#39;, monospace">  was built for i386 which is not the architecture being linked (armv7)</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">  Undefined symbols for architecture armv7:</font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">    &quot;_main&quot;, referenced from:</font></div><div><font face="&#39;courier new&#39;, monospace">        start in crt1.3.1.o</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  ld: symbol(s) not found for architecture armv7</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  collect2: ld returned 1 exit status</font></div><div>
<font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  lipo: can&#39;t open input file:</font></div><div><font face="&#39;courier new&#39;, monospace">  /var/folders/pS/pSWOJvZ-FDS4A2Eo7TwIzE+++TI/-Tmp-//ccKkL4CZ.out (No such</font></div>


<div><font face="&#39;courier new&#39;, monospace">  file or directory)</font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  make[1]: *** [cmTryCompileExec] Error 1</font></div>


<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  make: *** [cmTryCompileExec/fast] Error 2</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  </font></div><div><font face="&#39;courier new&#39;, monospace"><br>
</font></div><div><font face="&#39;courier new&#39;, monospace">  </font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">  CMake will not be able to correctly generate this project.</font></div>


<div><font face="&#39;courier new&#39;, monospace">Call Stack (most recent call first):</font></div><div><font face="&#39;courier new&#39;, monospace">  CMakeLists.txt:30 (project)</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font 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>
<br></div></div>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>