[CMake] CMake 3.11: Gives wrong paths to ar/strip/etc. when overridden
Deniz Bahadir
dbahadir at benocs.com
Thu Jun 14 05:41:10 EDT 2018
Am 14.06.2018 um 07:05 schrieb Paul Smith:
> I've discovered that CMake is not correctly locating ar/strip/etc. if I
> override the names of these tools on the command line. I've tried this
> with 3.5.2 as well and I get the same incorrect behavior.
>
> Here's an example (this is on a GNU/Linux system):
>
> $ type -a my-ar
> /work/bin/my-ar
>
> $ my-ar --version | head -n1
> GNU ar (GNU Binutils) 2.30
>
> $ pwd
> /tmp/obj
>
> $ cat ../CMakeLists.txt
> PROJECT(foobar)
> CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
>
> $ cmake --version | head -n1
> cmake version 3.11.3
>
> $ cmake -DCMAKE_AR=my-ar ..
> ...
>
> $ grep CMAKE_AR CMakeCache.txt
> CMAKE_AR:FILEPATH=/tmp/obj/my-ar
> //ADVANCED property for variable: CMAKE_AR
> CMAKE_AR-ADVANCED:INTERNAL=1
>
>
> Note how, instead of either using just "my-ar" or else the fully-
> qualified path "/work/bin/my-ar", CMake uses the bogus and completely
> non-existent path "/tmp/obj/my-ar". This causes my builds to fail,
> obviously.
>
> I tried enabling debug-output, trace, and trace-expand but there are no
> clues there as to why CMake prefixes these paths with the local object
> directory.
>
> I should note that resetting the C and C++ compilers works:
>
> * -DCMAKE_C_COMPILER=my-gcc --> CMAKE_C_COMPILER=/work/bin/my-gcc
> * -DCMAKE_CXX_COMPILER=my-g++ --> CMAKE_CXX_COMPILER=/work/bin/my-g++
I would not have this expected to work.
>
> But all the other bintools variable overrides do the wrong thing:
>
> * -DCMAKE_AR=my-ar --> CMAKE_AR=/tmp/obj/my-ar
> * -DCMAKE_LINKER=my-ld --> CMAKE_LINKER=/tmp/obj/my-ld
> * -DCMAKE_RANLIB=my-ranlib --> CMAKE_RANLIB=/tmp/obj/my-ranlib
> * -DCMAKE_STRIP=my-strip --> CMAKE_STRIP=/tmp/obj/my-strip
> * -DCMAKE_OBJCOPY=my-objcopy --> CMAKE_OBJCOPY=/tmp/obj/objcopy
>
This is what I would have expected.
If you just give the executable's name as value to the variable an
implicit "./" is seen by CMake which when translated into an absolute
path results in "./" being replaced by the current working-directory of
CMake (which seems to be "/tmp/obj/").
> Can anyone explain this, and hopefully help me find a way to fix it?
> Am I just doing variables wrong here? How should I do it?
I recommend to us the fully qualified path to your alternative
executables as values for the variables. That should do the trick.
>
> Thanks!
>
HTH,
Deniz
PS: You are right that the behavior seems to be inconsistent for
different variables and should be similar for all variables. So I
recommend you file a bug-report in CMake's issue-tracker.
More information about the CMake
mailing list