[cmake-developers] [CMake 0016133]: NO_DEFAULT_PATH is taken as a path when specified after the PATHS option.
Mantis Bug Tracker
mantis at public.kitware.com
Tue May 31 20:27:03 EDT 2016
The following issue has been SUBMITTED.
======================================================================
https://public.kitware.com/Bug/view.php?id=16133
======================================================================
Reported By: Alexis Wilke
Assigned To:
======================================================================
Project: CMake
Issue ID: 16133
Category: CMake
Reproducibility: always
Severity: major
Priority: normal
Status: new
======================================================================
Date Submitted: 2016-05-31 20:27 EDT
Last Modified: 2016-05-31 20:27 EDT
======================================================================
Summary: NO_DEFAULT_PATH is taken as a path when specified
after the PATHS option.
Description:
I wanted to make sure that I could get a header from my environment (i.e. source
tree) first, then from the system if no specific version in the environment was
defined there. For this purpose, I used the NO_DEFAULT_PATH option as defined in
the documentation:
https://cmake.org/cmake/help/v3.5/command/find_path.html
However, the code would always return path "/usr/include" when I expect (in my
specific case) to see path "...path-to-source.../contrib/catch"
I found that by putting the NO_DEFAULT_PATH before the PATHS option, it worked
as I first expected. It seems to me, though, that it is not correct. There
should be a check and if a path defined after the PATHS option looks like a
flag, it should be taken as such and see it as the end of the list of PATHS or
HINTS.
Steps to Reproduce:
The failing search looks like this:
FIND_PATH(CATCH_INCLUDE_DIR
catch.hpp
PATHS
${CMAKE_SOURCE_DIR}/contrib/catch
${CMAKE_SOURCE_DIR}/contrib
NO_DEFAULT_PATH
)
IF(NOT CATCH_INCLUDE_DIR)
# Try again with default paths as per cmake
FIND_PATH(CATCH_INCLUDE_DIR
catch.hpp
)
ENDIF()
My Ubuntu installation includes a catch.hpp under /usr/include. This is because
I have the catch package already installed:
apt-get install catch
My source directory includes a contrib/catch/catch.hpp file.
Adding a MESSAGE("Found Path? ")(${CATCH_INCLUDE_DIR}) before the IF() shows us
that the CATCH_INCLUDE_DIR is already set and it is "/usr/include" instead of
the expected "${CMAKE_SOURCE_DIR}/contrib/catch".
Additional Information:
There is a work around, which makes me think that the problem is that PATHS (and
probably HINTS) does not properly recognize NO_DEFAULT_PATH as a flag and no see
it as a path...
All I have to do is to put the NO_DEFAULT_PATH ahead of the PATHS specification.
FIND_PATH(CATCH_INCLUDE_DIR
catch.hpp
NO_DEFAULT_PATH
PATHS
${CMAKE_SOURCE_DIR}/contrib/catch
${CMAKE_SOURCE_DIR}/contrib
)
See also my Stackoverflow.com entry here:
http://stackoverflow.com/questions/37534142/how-do-i-get-cmake-to-choose-the-header-found-in-my-contrib-directory/37534160#37534160
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2016-05-31 20:27 Alexis Wilke New Issue
======================================================================
More information about the cmake-developers
mailing list