[CMake] CMake incorrectly passes linker flags to ar
Brad King
brad.king at kitware.com
Mon Jan 11 11:13:11 EST 2016
On 01/11/2016 10:49 AM, Alan Burlison wrote:
> So is the answer here to add -m64 just to CMAKE_EXE_LINKER_FLAGS and
> CMAKE_SHARED_LINKER_FLAGS and not to CMAKE_STATIC_LINKER_FLAGS? Are
> CMAKE_STATIC_LINKER_FLAGS only ever used with ar?
Yes and yes. Actually adding -m64 to CMAKE_{C,CXX}_FLAGS may be
enough because IIRC CMake uses those when invoking the C or C++
compiler front-end for linking a shared library or executable.
> There seems to be an assumption baked into CMake that if the underlying
> OS is *nix and is 32-bit then all executables that run on it are 32 bit
> and if it is 64-bit then all the executables are 64-bit as well, so
> looking at 'uname -p' is sufficient to determine the type of executables
> that should be produced. Unfortunately that's not correct for either
> Solaris or Linux.
Very few decisions are actually made based on CMAKE_SYSTEM_PROCESSOR.
Most platform tuning is done based on the compiler id detection results
which uses the actual toolchain. For example, CMAKE_SIZEOF_VOID_P is
set to the data pointer size detected from the toolchain target.
If you're not adding -m64 to the CMAKE_{C,CXX}_FLAGS until after the
top-level project() command enables the C and CXX languages then it is
too late for those flags to affect the detected target architecture.
-Brad
More information about the CMake
mailing list