[cmake-developers] QNX QCC and _CMAKE_TOOLCHAIN_PREFIX
Stephen Kelly
steveire at gmail.com
Wed Aug 7 11:56:04 EDT 2013
Hi there,
I can use a trivial toolchain file to compile for QNX with qcc:
SET(CMAKE_SYSTEM_NAME QNX)
SET(arch gcc_ntoarmv7le)
SET(CMAKE_C_COMPILER qcc -V${arch})
SET(CMAKE_CXX_COMPILER QCC -V${arch})
SET(CMAKE_FIND_ROOT_PATH $ENV{QNX_TARGET}/armle-v7 $ENV{QNX_TARGET})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
However, I just noticed that when I build, /usr/bin/ar is used instead of
/home/stephen/bbndk/host_10_1_0_132/linux/x86/usr/bin/ntoarm-ar
When cross-compiling with g++, the _CMAKE_TOOLCHAIN_PREFIX is set by
examining the name of the compiler in CMakeDetermineCXXCompiler.cmake.
When using qcc, the COMPILER_BASENAME doesn't match, and the appropriate
prefix is not encoded into the name anyway. I was thinking that
CMakeDetermineCXXCompiler.cmake could be extended to handle QCC and use the
CMAKE_CXX_COMPILER_TARGET.
However, currently the CMAKE_CXX_COMPILER_TARGET needs to be of the form
gcc_nto<arch>, not just nto<arch>, so the QNX specific code in
CMakeDetermineCXXCompiler.cmake would have to account for that, and other
possible suffixes (the version is optional):
stephen at hal:~/bbndk/host_10_1_0_132/linux/x86/usr/bin$ ./QCC -V
cc: targets available in
/home/stephen/bbndk/host_10_1_0_132/linux/x86/etc/qcc:
4.6.3,gcc_ntoarmv7le_gpp
4.6.3,gcc_ntox86_gpp
4.6.3,gcc_ntox86_cpp
4.6.3,gcc_ntoarmv7le_cpp-ne
4.6.3,gcc_ntoarmv7le
4.6.3,gcc_ntox86_cpp-ne
4.6.3,gcc_ntox86 (default)
4.6.3,gcc_ntoarmv7le_cpp
Can I extend the CMakeDetermineCXXCompiler.cmake with handling for that?
That would mean that with a recent enough cmake version, I can replace the
SET(arch gcc_ntoarmv7le)
SET(CMAKE_C_COMPILER qcc -V${arch})
SET(CMAKE_CXX_COMPILER QCC -V${arch})
in my toolchain file with
SET(arch gcc_ntoarmv7le)
SET(CMAKE_C_COMPILER qcc)
SET(CMAKE_CXX_COMPILER QCC)
SET(CMAKE_C_COMPILER_TARGET ${arch})
SET(CMAKE_CXX_COMPILER_TARGET ${arch})
and it will 'just work'.
I also notice that CMakeDetermineCXXCompiler.cmake doesn't have specific
handling for clang, and it could be extended similarly. Note that there are
two ways to use clang as a cross-compiler. One is specifying -target, which
CMAKE_C_COMPILER_TARGET does, and the other is creating a symlink or copy so
that the name contains the triple:
stephen at hal:/tmp$ /usr/bin/clang -dumpmachine
x86_64-pc-linux-gnu
stephen at hal:/tmp$ ln -s clang arm-linux-gnueabihf-clang
stephen at hal:/tmp$ ./arm-linux-gnueabihf-clang -dumpmachine
arm--linux-gnueabihf
So, possibly both ways should be handled in the clang case. I haven't
actually done any testing for the clang cases yet though to find out if the
missing _CMAKE_TOOLCHAIN_PREFIX causes a problem. I don't recall ever
hitting any, which confuses me somewhat.
Thanks,
Steve.
More information about the cmake-developers
mailing list