Another interesting experiment, I called CMake with both —debug-output and —trace turned on and was able to find out what directory you were in when calling add_executable through a macro (exe in this case).
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
/Users/dschaefer/tmp/CMakeLists.txt(1): cmake_minimum_required(VERSION 3.3 )
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
/Users/dschaefer/tmp/CMakeLists.txt(3): macro(exe name srcfile )
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
/Users/dschaefer/tmp/CMakeLists.txt(7): add_subdirectory(src )
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
Entering /Users/dschaefer/tmp/src
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
/Users/dschaefer/tmp/src/CMakeLists.txt(1): exe(test1 test.cpp )
Called from: [1] /Users/dschaefer/tmp/src/CMakeLists.txt
/Users/dschaefer/tmp/CMakeLists.txt(4): add_executable(test1 test.cpp )
Called from: [1] /Users/dschaefer/tmp/src/CMakeLists.txt
Returning to /Users/dschaefer/tmp
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
/Users/dschaefer/tmp/CMakeLists.txt(9): exe(test2 test2.cpp )
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
/Users/dschaefer/tmp/CMakeLists.txt(4): add_executable(test2 test2.cpp )
Called from: [1] /Users/dschaefer/tmp/CMakeLists.txt
Anyway, I think we can figure this out, and if not, we can seek to engage the CMake community again to contribute a mechanism for this. Frankly, I was expecting the link commands to be in the compile_commands.json file, but I guess that would be the wrong
name for it then.
There has been a discussion about this topic in the cmake forums
https://cmake.org/pipermail/cmake-developers/2015-March/024666.html
However, AFAIK the proposed contribution was never accepted.
Axel
Am 10.12.2015 13:44 schrieb "Jonah Graham" <
jonah@xxxxxxxxxxxxxxxx>:
Hi folks,
I have been following this discussion with some interest, however it
seems to me that these discussions are happening on the wrong forum.
By that I mean all these discussions should be happening on cmake and
cmake should be improved (by us aka cdt devs!) to provide exactly what
an IDE requires (i.e. full paths to executables, resolved compiler
flags, etc).
It would almost certainly be less effort for cmake to just do the
right thing and have CDT consume a much simpler artefact from cmake.
Jonah
~~~
Jonah Graham
Kichwa Coders Ltd.
www.kichwacoders.com
On 10 December 2015 at 12:17, Axel Müller <axel.carl.mueller@xxxxxxxxx> wrote:
> Here is an example with the macro defined in the file macros.cmake:
> macro(add_my_exe _target _source )
> add_executable( ${_target} ${_source} )
> endmacro()
>
> Then you will get the following output.
> axel@zeus:~/Programming/cmake-build$ cmake ../cmake-test --trace 2>&1 |grep
> add_executable
> /home/axel/Programming/cmake-test/macros.cmake(3): add_executable(hello1
> hello1.cpp )
> /home/axel/Programming/cmake-test/macros.cmake(3): add_executable(hello2
> hello2.cpp )
>
> I have applied the macro in two different subfolders. But the path info is
> not shown.
>
> Axel
>
> 2015-12-09 21:02 GMT+01:00 Doug Schaefer <dschaefer@xxxxxxx>:
>>
>> How does CMake know the path? Is it derived from the path of the current
>> CMakeLists file (I.e. not the one with the macro in it?)
>>
>> From: <cdt-dev-bounces@xxxxxxxxxxx> on behalf of Axel Müller
>> <axel.carl.mueller@xxxxxxxxx>
>> Reply-To: "CDT General developers list." <cdt-dev@xxxxxxxxxxx>
>> Date: Wednesday, December 9, 2015 at 10:57 AM
>> To: "CDT General developers list." <cdt-dev@xxxxxxxxxxx>
>> Subject: Re: [cdt-dev] Antwort: [Newsletter] Re: CMake support in Eclipse
>> CDT
>>
>> You will get the name of the target but you will not get the path. cmake
>> --trace will only show the path to the cmake file where the macro is
>> defined. Please note, that your build tree can have several targets and they
>> can have identical names but reside in different paths!
>>
>> Axel
>>
>> 2015-12-09 16:24 GMT+01:00 Doug Schaefer <dschaefer@xxxxxxx>:
>>>
>>> You mean cmake --trace doesn’t show it if add_executable is in a macro?
>>
>>
>> _______________________________________________
>> cdt-dev mailing list
>> cdt-dev@xxxxxxxxxxx
>> To change your delivery options, retrieve your password, or unsubscribe
>> from this list, visit
>>
https://dev.eclipse.org/mailman/listinfo/cdt-dev
>
>
>
>
> --
> Dr. Axel Müller
> Lorbeerweg 8
> 76149 Karlsruhe
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
>
https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev