Hi Justin, 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.
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. >From one of my toolchain files, reproduce as necessary for CMAKE_C_FLAGS: SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti" CACHE STRING "" FORCE) Cheers /Johan On Mon, Dec 13, 2010 at 4:49 PM, Justin Holewinski < justin.holewin...@gmail.com> wrote: > 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. > > 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. > > 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. > > 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. > > I am using CMake 2.8.3 on Snow Leopard 10.6.5. > > CMake Output: > > -- 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 > -- 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 > -- 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 > -- 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 > -- 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 > -- 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 > -- 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 > -- 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 > -- The C compiler identification is GNU > -- The CXX compiler identification is GNU > -- Check for working C compiler: > /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 > -- Check for working C compiler: > /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -- broken > CMake Error at > /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE): > The C compiler > "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2" is not > able to compile a simple test program. > > It fails with the following output: > > Change Dir: > /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp > > > > Run Build Command:/usr/bin/make "cmTryCompileExec/fast" > > /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make > CMakeFiles/cmTryCompileExec.dir/build > > /opt/local/bin/cmake -E cmake_progress_report > > > /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/CMakeFiles > 1 > > Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj > > /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 > > > -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include > -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -c > > > /Users/jholewinski/projects/rapture/build-test/ios/CMakeFiles/CMakeTmp/testCCompiler.c > > > Linking C executable cmTryCompileExec > > /opt/local/bin/cmake -E cmake_link_script > CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1 > > /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch > armv6 -arch armv7 -pipe -no-cpp-precomp > > > --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk > -miphoneos-version-min=4.2 > CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj -o cmTryCompileExec > > > -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/lib > > > ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file > was built for i386 which is not the architecture being linked (armv6) > > Undefined symbols for architecture armv6: > > "_main", referenced from: > start in crt1.3.1.o > > ld: symbol(s) not found for architecture armv6 > > collect2: ld returned 1 exit status > > ld: warning: in CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.obj, file > was built for i386 which is not the architecture being linked (armv7) > > Undefined symbols for architecture armv7: > > "_main", referenced from: > start in crt1.3.1.o > > ld: symbol(s) not found for architecture armv7 > > collect2: ld returned 1 exit status > > lipo: can't open input file: > /var/folders/pS/pSWOJvZ-FDS4A2Eo7TwIzE+++TI/-Tmp-//ccKkL4CZ.out (No such > file or directory) > > make[1]: *** [cmTryCompileExec] Error 1 > > make: *** [cmTryCompileExec/fast] Error 2 > > > > > > CMake will not be able to correctly generate this project. > Call Stack (most recent call first): > CMakeLists.txt:30 (project) > > > -- Configuring incomplete, errors occurred! > > > -- > > Thanks, > > Justin Holewinski > > > _______________________________________________ > 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 >
_______________________________________________ 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