[CMake] CMake incorrectly passes linker flags to ar

Alan Burlison Alan.Burlison at oracle.com
Mon Jan 11 11:53:53 EST 2016


On 11/01/2016 16:13, Brad King wrote:

> 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.

Thanks, I've removed -m64 from CMAKE_STATIC_LINKER_FLAGS and with 3.3.2 
on Solaris it fixes the problem, I'll ring the changes on the other 
platforms and with 2.8.6 and make sure it still works elsewhere.

>> 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.

ISTR part of the issue at least was in the bowels of the CMake FindJNI 
module, that makes extensive use of CMAKE_SYSTEM_PROCESSOR.

> 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.

The Hadoop CMakeLists.txt files don't use a PROJECT() command. The CMake 
docs say if you don't do so then an implicit PROJECT() is added that 
selects the C & C++ languages, is that done before processing any other 
commands in CMakeLists.txt? If so then from what you say it seems 
setting CMAKE_{C,CXX}_FLAGS wouldn't have any effect, which is probably 
why it has been done via CMAKE_EXE_LINKER_FLAGS etc.

-- 
Alan Burlison
--


More information about the CMake mailing list