[CMake] should zlib be searched in CMAKE_PREFIX_PATH or am I confused?

Mario Emmenlauer mario at emmenlauer.de
Thu Mar 22 12:54:42 EDT 2018


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
> 
> 
> 


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


More information about the CMake mailing list