Bug 1131949 - CMake may fail to build if '/bin' or '/sbin' is in $PATH
Summary: CMake may fail to build if '/bin' or '/sbin' is in $PATH
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: cmake
Version: 20
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Orion Poplawski
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-08-20 11:32 UTC by J. Sastre
Modified: 2014-08-20 15:22 UTC (History)
6 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2014-08-20 15:22:34 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description J. Sastre 2014-08-20 11:32:27 UTC
Description of problem:

When building using CMake an error may occur if '/bin' or '/sbin' is in $PATH. bins and libs directories were moved to '/usr' in the past but '/usr/lib{64}' is still reachable through '/lib{64}'. CMake uses $PATH among (many others resources) to set variables regarding prefixes and paths to others components and packages. When searching for these paths CMake consider '/' as a valid search path if '/bin' or '/sbin' are included in $PATH.

Some packages store its <PkgName>-config.cmake files under '/usr/lib64/cmake/<PkgName>/' and since '/' is in the internal search path list of CMake '/lib64/cmake/<PkgName>' is also reachable. Some variables will be affected by this (e.g. CMAKE_CURRENT_LIST_FILE or CMAKE_CURRENT_LIST_DIR). If these vars are used to infer any kind of PREFIX (collada-dom-devel package make use of this mechanism. See https://bugzilla.redhat.com/show_bug.cgi?id=1057985) '/' will be gotten instead of '/usr' and any content other than libs will not be reachable (e.g. '/usr/include' will be looked up on /include).


Version-Release number of selected component (if applicable):
2.8.12.2

Steps to reproduce:
# mkdir /usr/lib64/cmake/mypkg
# echo "message(${CMAKE_CURRENT_LIST_DIR})" > /usr/lib64/cmake/mypkg/mypkg-config.cmake
$ cd ; mkdir tmp ; cd tmp
$ echo -e "cmake_minimum_required(VERSION 2.8.3)\nproject(mypkg)\nfind_package(MYPKG)"
$ cmake ./


Actual results:
/lib64/cmake/mypkg

Expected results:
/usr/lib64/cmake/mypkg

Additional info:

Possible solutions

* Consider using CMAKE_CURRENT_LIST_XXX vars to deduce prefixes as a bad practice and avoid its use (some different packages involved) 
* Reinforce path search mechanism in CMake to detect this situation.
* May be not really a bug. Removing '/bin' and '/sbin' from $PATH works well.

Comment 1 Orion Poplawski 2014-08-20 15:22:34 UTC
Yeah, don't use CMAKE_CURRENT_* variables in the installed cmake files.  Set the variables explicitly at install time (when they are known).  You might look at libcmocka for an example.


Note You need to log in before you can comment on or make changes to this bug.