<div class="gmail_quote">On Tue, Dec 14, 2010 at 4:45 AM, Johan Björk <span dir="ltr"><<a href="mailto:phb@spotify.com">phb@spotify.com</a>></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'm very unsure if this is the correct solution, but it worked for me. I haven'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 "${CMAKE_C_FLAGS} -fno-rtti" CACHE STRING "" FORCE)</div></div></blockquote><div><br></div>
<div>I'll have to give that a try. For now, I'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'm really not sure what the "best practice" is for this situation. The compiler will work and can be tested without the "-arch" 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'm not sure if testing the i386 back-end when I'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"><<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>></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 "-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 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 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 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 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 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 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 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 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 face="'courier new', monospace">-- The C compiler identification is GNU</font></div><div><font face="'courier new', monospace">-- The CXX compiler identification is GNU</font></div>
<div><font face="'courier new', monospace">-- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2</font></div><div><font face="'courier new', monospace">-- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -- broken</font></div>
<div><font face="'courier new', monospace">CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):</font></div><div><font face="'courier new', monospace"> The C compiler</font></div>
<div><font face="'courier new', monospace"> "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2" is not</font></div><div><font face="'courier new', monospace"> able to compile a simple test program.</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> It fails with the following output:</font></div><div>
<font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> Change Dir: /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> </font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> Run Build Command:/usr/bin/make "cmTryCompileExec/fast"</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make</font></div><div><font face="'courier new', monospace"> CMakeFiles/cmTryCompileExec.dir/build</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> /opt/local/bin/cmake -E cmake_progress_report</font></div>
<div><font face="'courier new', monospace"> /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/CMakeFiles</font></div><div><font face="'courier new', monospace"> 1</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2</font></div>
<div><font face="'courier new', monospace"> -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include</font></div><div><font face="'courier new', monospace"> -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -c</font></div>
<div><font face="'courier new', monospace"> /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/testCCompiler.c</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> Linking C executable cmTryCompileExec</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> /opt/local/bin/cmake -E cmake_link_script</font></div>
<div><font face="'courier new', monospace"> CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch</font></div><div><font face="'courier new', monospace"> armv6 -arch armv7 -pipe -no-cpp-precomp</font></div>
<div><font face="'courier new', monospace"> --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk</font></div><div><font face="'courier new', monospace"> -miphoneos-version-min=4.2</font></div>
<div><font face="'courier new', monospace"> CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -o cmTryCompileExec</font></div><div><font face="'courier new', monospace"> -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font face="'courier new', monospace"> was built for i386 which is not the architecture being linked (armv6)</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> Undefined symbols for architecture armv6:</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> "_main", referenced from:</font></div><div><font face="'courier new', monospace"> start in crt1.3.1.o</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> ld: symbol(s) not found for architecture armv6</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> collect2: ld returned 1 exit status</font></div><div>
<font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file</font></div>
<div><font face="'courier new', monospace"> was built for i386 which is not the architecture being linked (armv7)</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> Undefined symbols for architecture armv7:</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> "_main", referenced from:</font></div><div><font face="'courier new', monospace"> start in crt1.3.1.o</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> ld: symbol(s) not found for architecture armv7</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> collect2: ld returned 1 exit status</font></div><div>
<font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> lipo: can't open input file:</font></div><div><font face="'courier new', monospace"> /var/folders/pS/pSWOJvZ-FDS4A2Eo7TwIzE+++TI/-Tmp-//ccKkL4CZ.out (No such</font></div>
<div><font face="'courier new', monospace"> file or directory)</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> make[1]: *** [cmTryCompileExec] Error 1</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> make: *** [cmTryCompileExec/fast] Error 2</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> </font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> </font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> CMake will not be able to correctly generate this project.</font></div>
<div><font face="'courier new', monospace">Call Stack (most recent call first):</font></div><div><font face="'courier new', monospace"> CMakeLists.txt:30 (project)</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><br></font></div><div><font 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>
<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>