[cmake-developers] [CMake 0015963]: strange behaviour running readlink via execute_process

Mantis Bug Tracker mantis at public.kitware.com
Tue Feb 9 16:52:46 EST 2016


The following issue has been SUBMITTED. 
====================================================================== 
https://cmake.org/Bug/view.php?id=15963 
====================================================================== 
Reported By:                Bruce Adams
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15963
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2016-02-09 16:52 EST
Last Modified:              2016-02-09 16:52 EST
====================================================================== 
Summary:                    strange behaviour running readlink via
execute_process
Description: 
I'm trying to use readlink -f to get the absolute path to a shared library
following all symlinks.

>readlink -f /opt/gcc4.9.3/lib64/libstdc++.so.6
/opt/gcc4.9.3/lib64/libstdc++.so.6.0.20

but when I do this in cmake it doesn't expand the full path E.g.

set(CPP11_PATH ${CMAKE_CURRENT_BINARY_DIR}/)
execute_process(COMMAND ldd ${CPP11_PATH} COMMAND grep libstdc++ COMMAND awk "{
print $3; }" OUTPUT_VARIABLE LIBSTDCPP_PATH)
message("LIBSTDCPP_PATH=${LIBSTDCPP_PATH}")
execute_process(COMMAND readlink -f ${LIBSTDCPP_PATH} OUTPUT_VARIABLE
LIBSTDCPP_ABSPATH)
message("LIBSTDCPP_ABSPATH=${LIBSTDCPP_ABSPATH}")

prints:

LIBSTDCPP_PATH=/opt/gcc4.9.3/lib64/libstdc++.so.6
LIBSTDCPP_ABSPATH=/opt/gcc4.9.3/lib64/libstdc++.so.6

This also happens if I wrap it in a shell script:

execute_process(COMMAND doreadlink.sh ${LIBSTDCPP_PATH} OUTPUT_VARIABLE
LIBSTDCPP_ABSPATH2)
message("LIBSTDCPP_ABSPATH2=${LIBSTDCPP_ABSPATH2}")

>LIBSTDCPP_ABSPATH2=/opt/gcc4.9.3/lib64/libstdc++.so.6




Steps to Reproduce: 
cmake_minimum_required(VERSION 2.8)
project(TEST CXX) 
CMake script as below

set(CPP11_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpp11)
execute_process(COMMAND g++ ${CMAKE_CURRENT_SOURCE_DIR}/cpp11.cpp
-o${CPP11_PATH})

execute_process(COMMAND ldd ${CPP11_PATH} COMMAND grep libstdc++ COMMAND awk "{
print $3; }" OUTPUT_VARIABLE LIBSTDCPP_PATH)
message("LIBSTDCPP_PATH=${LIBSTDCPP_PATH}")
execute_process(COMMAND readlink -f ${LIBSTDCPP_PATH} OUTPUT_VARIABLE
LIBSTDCPP_ABSPATH)
message("LIBSTDCPP_ABSPATH=${LIBSTDCPP_ABSPATH}")

Additional Information: 
The following is an effective work around

execute_process(COMMAND ldd ${CPP11_PATH} COMMAND grep libstdc++ COMMAND awk "{
print $3; }" COMMAND xargs readlink -f OUTPUT_VARIABLE LIBSTDCPP_PATH)

Originally raised on stackoverflow:

http://stackoverflow.com/questions/35299970/strange-behaviour-with-readlink-under-cmake
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2016-02-09 16:52 Bruce Adams    New Issue                                    
======================================================================



More information about the cmake-developers mailing list