[CMake] find_library search orders with CMAKE_PREFIX_PATH & CMAKE_FIND_ROOT_PATH

Nicolas Tisserand nt at manctl.com
Tue May 22 21:53:50 EDT 2012


Hi all,

I am currently building a collection of inter-dependent libraries and
tools, mostly cmake-built, all installed to a common staging directory.

I therefore need CMake find_library & find_package commands to search in
the staging directory first, before inspecting the system.

Here's my problem: I can't get any combination of CMAKE_PREFIX_PATH or
CMAKE_FIND_ROOT_PATH_MODE_* (in BOTH/NEVER/ONLY modes) to do this
correctly, when find_library is given multiple names for the library.

It only works using CMAKE_PREFIX_PATH, or CMAKE_FIND_ROOT_PATH &
CMAKE_FIND_ROOT_PATH_MODE=BOTH, provided that the name of the library
present in the stage directory is the *first* of the library names list
given to find_library.

It seems like the search order in such cases is as follows (in pseudo-code):

for each name in names
    for dir in stage, system
        if library_found(dir, name)
            return dir, name
        end
    end
end

My use case would require the inner and outer loops to be swapped.

Please find attached a minimal test case illustrating my problem.

When running it on my Mac OS X 10.6 macbook, I get the following output:

==============================> cmake
-DCMAKE_FIND_ROOT_PATH:PATH=/Users/nt/Hacks/cmake-find-png/stage
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY:STRING=ONLY ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
==============================> Looking for: png;png14
==============================> Found:
/Users/nt/Hacks/cmake-find-png/stage/lib/libpng14.a
==============================> Looking for: png14;png
==============================> Found:
/Users/nt/Hacks/cmake-find-png/stage/lib/libpng14.a
-- Configuring done
-- Generating done
-- Build files have been written to:
/Users/nt/Hacks/cmake-find-png/build-ROOT_PATH_ONLY
/Users/nt/Hacks/cmake-find-png
==============================> cmake
-DCMAKE_FIND_ROOT_PATH:PATH=/Users/nt/Hacks/cmake-find-png/stage
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY:STRING=BOTH ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
==============================> Looking for: png;png14
==============================> Found:       /usr/X11R6/lib/libpng.dylib
==============================> Looking for: png14;png
==============================> Found:
/Users/nt/Hacks/cmake-find-png/stage/lib/libpng14.a
-- Configuring done
-- Generating done
-- Build files have been written to:
/Users/nt/Hacks/cmake-find-png/build-ROOT_PATH_BOTH
/Users/nt/Hacks/cmake-find-png
==============================> cmake
-DCMAKE_FIND_ROOT_PATH:PATH=/Users/nt/Hacks/cmake-find-png/stage
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY:STRING=NEVER ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
==============================> Looking for: png;png14
==============================> Found:       /usr/X11R6/lib/libpng.dylib
==============================> Looking for: png14;png
==============================> Found:       /usr/X11R6/lib/libpng.dylib
-- Configuring done
-- Generating done
-- Build files have been written to:
/Users/nt/Hacks/cmake-find-png/build-ROOT_PATH_NEVER
/Users/nt/Hacks/cmake-find-png
==============================> cmake
-DCMAKE_PREFIX_PATH:PATH=/Users/nt/Hacks/cmake-find-png/stage ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
==============================> Looking for: png;png14
==============================> Found:       /usr/X11R6/lib/libpng.dylib
==============================> Looking for: png14;png
==============================> Found:
/Users/nt/Hacks/cmake-find-png/stage/lib/libpng14.a
-- Configuring done
-- Generating done
-- Build files have been written to:
/Users/nt/Hacks/cmake-find-png/build-PREFIX
/Users/nt/Hacks/cmake-find-png

Any thoughts?

Thanks for making such a useful cross-platform build tool.
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120522/1e5e46ad/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmake-find-png.zip
Type: application/zip
Size: 1558 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120522/1e5e46ad/attachment-0001.zip>


More information about the CMake mailing list