[CMake] Total cmake newbie needs some help

Johannes Zarl johannes.zarl at jku.at
Mon Aug 20 07:43:23 EDT 2012


On Saturday, 18. August 2012, 00:16:41, Edgar wrote:
> I have these problems -
> 1) Cmake cannot find ZLIB
> 2) Cmake cannot find LIBPNG

> There are some .cmake files named FindALLEGRO, and FindFREETYPE, and
> those work properly. Do I need to create similar cmake files for zlib
> and libpng?

Those two are standard cmake modules[1][2]. You only have to point them to the 
location of your zlib/libpng installation. You can help cmake by setting the 
environment variable CMAKE_PREFIX_PATH to a colon-separated list of paths 
(e.g. /myopt:/usr/local).

In your case it might even suffice to set the cmake variable ZLIB_ROOT (libpng 
depends on zlib and therefore FindPNG.cmake will bail out if zlib is not 
found).

> 3) There are undefined reference errors during the linking process for
> the OpenLayer demos, and I don't know how to properly link the necessary
> libraries using cmake.

You should read up on target_link_libraries [3] for that. Normally the usage 
pattern is something like the following:

FIND_PACKAGE(FOO REQUIRED)
TARGET_LINK_LIBRARIES(someTarget ${FOO_LIBRARIES})

Cheers,
  Johannes


[1] http://www.cmake.org/cmake/help/v2.8.9/cmake.html#module:FindZLIB
[2] http://www.cmake.org/cmake/help/v2.8.9/cmake.html#module:FindPNG
[3] 
http://www.cmake.org/cmake/help/v2.8.9/cmake.html#command:target_link_libraries


More information about the CMake mailing list