MantisBT - CMake
View Issue Details
0015113CMakeCMakepublic2014-08-27 10:262016-06-10 14:31
raspy 
Kitware Robot 
normalminoralways
closedmoved 
x86_64RedHat Enterprise Linux6.4
CMake 3.0 
 
0015113: <TARGET_BASE> is generated wrong in case of up-leading path
We use <TARGET_BASE> in platform configuration to instruct linker to create map file named the same way as target with different extension:

set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET_BASE>.map <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>")

However, if <TARGET> is created in upper directory, <TARGET_BASE> is terminated on the last dot, which happens to be part of directory, i.e.:

Linking C executable ../../out/binary
cd /path/to/source && /path/to/cmake-3.0.0-Linux-i386/bin/cmake -E cmake_link_script CMakeFiles/binary.dir/link.txt --verbose=1
/path/to/cl6x --run_linker --output_file=../../out/binary --map_file=../..map
CMakeFiles/binary.dir/tools/dictionary.c.obj --search_path=/path/to/lib
Simple reproduction on Linux with gcc:

$ cat CMakeLists.txt
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> -o <TARGET> -Wl,-Map,<TARGET_BASE>.map <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
add_subdirectory(subdirectory)

$ cat subdirectory/CMakeLists.txt
add_executable(hello hello.c)

$ cat subdirectory/hello.c
#include <stdint.h>

int main(int argc, char *argv[])
{
    return 0;
}

Result:
cd /path/to/cmake-test/subdirectory && /usr/bin/cc -o CMakeFiles/hello.dir/hello.o -c /path/to/cmake-test/subdirectory/hello.c
Linking C executable ../out/hello
cd /path/to/cmake-test/subdirectory && /path/to/cmake-3.0.0-Linux-i386/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/cc -o ../out/hello -Wl,-Map,..map CMakeFiles/hello.dir/hello.o -rdynamic
No tags attached.
Issue History
2014-08-27 10:26raspyNew Issue
2014-08-27 10:52Brad KingNote Added: 0036684
2014-08-28 04:32raspyNote Added: 0036685
2016-06-10 14:29Kitware RobotNote Added: 0042614
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0036684)
Brad King   
2014-08-27 10:52   
TARGET_BASE is not documented for public use. It is an old implementation detail left over from an older approach to .dll/.lib handling on Windows. It won't work at all with the Ninja generator due to differences in the way the command lines get generated. Also there is no official support for application code modifying make rule variables like CMAKE_C_LINK_EXECUTABLE.

One alternative is to use the LINK_FLAGS target property to add the needed flags to each target that needs this.

Another option is to raise discussion on the cmake-developers mailing list and propose an interface to add first-class support for linker map files to CMake.
(0036685)
raspy   
2014-08-28 04:32   
Well, <TARGET_BASE> is explicitly mentioned in CMakeCInformation.cmake:

# variables supplied by the generator at use time
# <TARGET>
# <TARGET_BASE> the target without the suffix
# <OBJECTS>
# <OBJECT>
# <LINK_LIBRARIES>
# <FLAGS>
# <LINK_FLAGS>

I agree that it would be the best if CMake has built-in support for creating linker maps upon linking targets (and for cleaning them as well).
(0042614)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.