Thanks PF, I think this makes more sense now! I was assuming that
cmake always prefers CMAKE_PREFIX_PATH over builtin paths. But as you
clarified, that only applies to libraries that provide find_package
support.

This is actually quite unfortunate. Then I don't see an easy way to
enforce usage of specific libs. As an example, if I want to enforce a
patched libtiff (that does not itself provide find_package support)
the only "safe" way is to replace the system libtiff. Otherwise any
package might just find the system version first without me even
knowing.

This actually opens quite a can of worms :-(

All the best,

   Mario



On 23.03.2018 00:52, P F wrote:
> Are you setting `CMAKE_INSTALL_PREFIX`? This path is searched before the 
> `CMAKE_PREFIX_PATH` is searched. 
> 
> Also the find_package paths listed in the documentation are only for 
> libraries that provide find_package support. Zlib does not, so it cmake 
> fallsback on the
> FindZLIB.cmake module to do the searching which the search order can be 
> entirely up to the author of the module. You can see how FindZLIB.cmake 
> searches here:
> 
> https://github.com/Kitware/CMake/blob/master/Modules/FindZLIB.cmake#L72
> 
> Of course, if its not correctly searching the `CMAKE_PREFIX_PATH` then this 
> should be considered a bug.
> 
>> On Mar 22, 2018, at 11:54 AM, Mario Emmenlauer <ma...@emmenlauer.de 
>> <mailto:ma...@emmenlauer.de>> wrote:
>>
>>
>> Dear Stephen,
>>
>> thanks a lot for your support! I've tested and your suggestion works!
>>
>> But, it does not fully resolve my pain :-( I'm slightly scared now
>> because I assumed that cmake would prefer CMAKE_PREFIX_PATH over system
>> libraries. In my understanding, the documentation says CMAKE_PREFIX_PATH
>> is searched first (1). That aspect is quite crucial to me, because I have
>> patched versions of more than 30 standard libraries in CMAKE_PREFIX_PATH.
>> If I can not rely that cmake would use the patched versions, then I
>> may end up having an "interesting" mix of system and patched libraries
>> in my executable :-(
>>
>> (1) https://cmake.org/cmake/help/v3.0/command/find_package.html
>>
>> Thanks a lot and all the best,
>>
>>    Mario
>>
>>
>> On 22.03.2018 17:43, Stephen McDowell wrote:
>>> Hi Mario,
>>>
>>> Very sorry, I should have looked more closely!  CMAKE_MODULE_PATH is for 
>>> libraries that install their own CMake scripts.  You are correct, Zlib only 
>>> installs a
>>> pkg-config script.  However, FindZLIB.cmake doesn’t appear to use that at 
>>> all (aka I don’t believe you /need/ to be setting PKG_CONFIG_PATH).  You 
>>> should be
>>> able to get away with setting *ZLIB_ROOT*.  So for you I think it would 
>>> look like
>>>
>>>     cmake .. -DZLIB_ROOT=/data/thirdparty
>>>
>>> FindZLIB.cmake will proceed to look for ZLIB_ROOT/include/zlib.h and look 
>>> in ZLIB_ROOT/lib for the library.
>>>
>>> The XXX_ROOT is typically available for any built-in CMake FindXXX.cmake 
>>> modules (see hint at bottom: 
>>> https://cmake.org/cmake/help/v3.0/module/FindZLIB.html ).
>>>  These FindXXX.cmake modules are for this exact scenario: there is a 
>>> library that many users want access to that does not install cmake scripts 
>>> (typically
>>> because the library uses a different build system such as autotools).
>>>
>>> - - - - -
>>>
>>> If you are still having trouble, this is what I used to test this.  I 
>>> didn’t actually write code that uses it, but I suspect if you *remove* 
>>> setting of
>>> CMAKE_PREFIX_PATH (I think that’s where your conflict originates from) and 
>>> just specify ZLIB_ROOT your problem will be solved (I hope!).
>>>
>>> With a very crude CMakeLists.txt:
>>>
>>>     cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
>>>     project("find_zlib")
>>>
>>>     find_package(ZLIB)
>>>     if (ZLIB_FOUND)
>>>       message(FATAL_ERROR "Found Zlib:\n- ZLIB_INCLUDE_DIRS: 
>>> ${ZLIB_INCLUDE_DIRS}\n- ZLIB_LIBRARIES: ${ZLIB_LIBRARIES}")
>>>     else()
>>>       message(FATAL_ERROR "Did not find Zlib :/")
>>>     endif()
>>>
>>> *Without* setting ZLIB_ROOT:
>>>
>>>     $ cmake ..
>>>     -- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.8")
>>>     CMake Error at CMakeLists.txt:6 (message):
>>>       Found Zlib:
>>>       - ZLIB_INCLUDE_DIRS: /usr/include
>>>       - ZLIB_LIBRARIES: /usr/lib/libz.dylib
>>>
>>> That’s the default Zlib that comes with OS X.  However, if I specify 
>>> ZLIB_ROOT:
>>>
>>>     $ cmake .. -DZLIB_ROOT=/usr/local/Cellar/zlib/1.2.11/
>>>     -- Found ZLIB: /usr/local/Cellar/zlib/1.2.11/lib/libz.dylib (found 
>>> version "1.2.11")
>>>     CMake Error at CMakeLists.txt:6 (message):
>>>       Found Zlib:
>>>       - ZLIB_INCLUDE_DIRS: /usr/local/Cellar/zlib/1.2.11/include
>>>       - ZLIB_LIBRARIES: /usr/local/Cellar/zlib/1.2.11/lib/libz.dylib
>>>
>>> Let us know if it works or if you still need help!
>>>
>>> -Stephen



Viele Gruesse,

    Mario Emmenlauer


--
BioDataAnalysis GmbH, Mario Emmenlauer      Tel. Buero: +49-89-74677203
Balanstr. 43                   mailto: memmenlauer * biodataanalysis.de
D-81669 München                          http://www.biodataanalysis.de/
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to