Re: [CMake] Cross-compiling, CMAKE_C_FLAGS, and configure-time compiler tests
Hi Justin, On Tuesday 14 December 2010, Justin Holewinski wrote: On Tue, Dec 14, 2010 at 4:45 AM, Johan Björk p...@spotify.com wrote: 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) 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. 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. please put your problem in the cmake bug tracker http://public.kitware.com/Bug/ and assign it to me. Thanks Alex ___ 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
Re: [CMake] Cross-compiling, CMAKE_C_FLAGS, and configure-time compiler tests
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
Re: [CMake] Cross-compiling, CMAKE_C_FLAGS, and configure-time compiler tests
On Tue, Dec 14, 2010 at 4:45 AM, Johan Björk p...@spotify.com wrote: 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) 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. 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. 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