[CMake] Find preferentially in /usr/local/lib not working

Timenkov Yuri ytimenkov at parallels.com
Fri Mar 28 07:50:42 EDT 2008


On Friday 28 March 2008 14:02:03 Stephen Collyer wrote:
> Timenkov Yuri wrote:
> > Did you run this on clean build directory or CMakeCache.txt existed?
> > If so, you should manually delete CURL_INCLUDE_DIR value from cache (or
> > whole cache).
> >
> > The point is that once search variable is found in cache, cmake will
> > never look again for headers nor validate its value.  Therefore you can
> > put multiple find_path statements into single file.
>
> OK, thanks, I now understand what's going on. I misunderstood what was
> happening - I didn't realise that if a value was already in the cache
> then the *first* FIND_PATH is ignored as well. It's been so long since
> I changed my setup that I'd forgotten this. If I clear the cache then
> I can indeed find the stuff in /usr/local preferentially.
>
> However, this is a pain - I'd rather have cmake reconstruct the cached
> FIND_PATH values each time I run it, without my having to remove it
> or alter it manually - is that possible ?
I don't think it is possible :(. Moreover, cmake runs automatically, when you 
change one of CMakeLists.txt files, and I don't think users will happy when 
cmake will run heavy cycle of finding dependencies every time.

However, you should write cmake files in the way that cmake should find 
everything in right place from single run :)

Alternatively, you may clean CMakeCache.txt file with command like:
cat /dev/null > CMakeCache.txt.
I don't know, should it work at all, so use with caution :) I suppose this 
will remove all cached variables.

I know, it is tricky to make initial setup sometimes (If you have custom-built 
libraries which are placed in unusual places). Sometimes, you can work-around 
this behavior with extra variables. From Modules/CMakeGenericSystem.cmake:

# Set a variable to indicate whether the value of CMAKE_INSTALL_PREFIX
# was initialized by the block below.  This is useful for user
# projects to change the default prefix while still allowing the
# command line to override it.
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
  SET(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)

# Choose a default install prefix for this platform.
IF(UNIX)
  SET(CMAKE_INSTALL_PREFIX "/usr/local"
    CACHE PATH "Install path prefix, prepended onto install directories.")
ELSE(UNIX)

So in my files I can write:
# Replace CMAKE_INSTALL_PREFIX to Currently used one,
# If it wasn't overriden from command line / cache.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
	set(CMAKE_INSTALL_PREFIX "/opt/myproduct" CACHE PATH "Install path prefix, 
prepended onto install directories." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

So you can write something like:

option(CURL_RESET_CONFIG "Find Curl libraries again" FALSE)
if(CURL_RESET_CONFIG)
	set(CURL_INCLUDE_DIR CURL_INCLUDE_DIR-NOTFOUND CACHE FORCE)
	# Reset to prevent finding headers on next cmake run.
	set(CURL_RESET_CONFIG FALSE CACHE FORCE)
endif(CURL_RESET_CONFIG)

FIND_PATH(CURL_INCLUDE_DIR NAMES curl/curl.h PATHS /usr/local/include 
NO_DEFAULT_PATH)
FIND_PATH(CURL_INCLUDE_DIR NAMES curl/curl.h)

so, you can run:
cmake -DCURL_RESET_CONFIG=ON
to rescan include paths. (or set this option in GUI and press configure).

Note: obviously, I didn't test this solution :)


More information about the CMake mailing list