How to tell CMake which libpng.dylib to use?

Michael Dickens michaelld at macports.org
Tue Jan 22 05:05:59 PST 2013


Hi Mojca - A number of projects provide their own Find*.cmake files,
which might be a copy of that provided by CMake, maybe modified for
their own needs, or totally home brew.  GNU Radio does this in
cmake/Modules, which is definitely used by CMake -- I recently had to
fix a path-include issue involving Qt, which resulting in me copying
CMake's UseQt4.cmake and modifying it to just set variables but not use
them (I renamed it to "SetupQt4" since that's really what it does now).

All of that said, it should be possible in the CMake port to patch the
"cmake" executable (or related files) to set the default path search
order, to search MacPorts' ${prefix} first.  But, CMake does give the
user the ability to override this ordering, which a lot of the Find*
scripts do as a first cut. So, even doing this does not guarantee that
CMake will correctly find installed projects where they were installed
by MacPorts.  And, even if parts are found in MacPorts, other parts
might be found elsewhere and CMake is somewhat "notorious" for not
correlating found BINARIES, LIBRARIES, and INCLUDES to make sure they
are self-consistent (e.g., in version, prefix, other attributes). The
CMake Python script is a prime example in this regard -- I always define
the 3 Python variables to make sure they are "found" correctly.

It is good that CMake has such flexibility.  But, really, setting CMake
-D flags in the PortGroup files is about as good as we can do, then
setting specific variables on a port-by-port basis.  At least IMHO and
experience; that said, I'm certainly open to suggestions by others. -
MLD

On Jan 22, 2013, at 3:06 AM, Mojca Miklavec <mojca at macports.org> wrote:
> On Tue, Jan 22, 2013 at 2:35 AM, Ryan Schmidt wrote:
> > On Jan 21, 2013, at 16:24, Mojca Miklavec wrote:
> > > 
> > > Thank you very much. The magic turned out to give the correct result:
> > >   -DPNG_LIBRARY=/opt/local/lib/libpng.dylib \
> > >   -DPNG_PNG_INCLUDE_DIR=/opt/local/include
> > > 
> > > (The only thing I wonder is: isn't there some way to set those variables "globally" somewhere, so that it doesn't have to be repeated by every single program/port? ;)
> > > 
> > The program you're currently investigating calls those settings PNG_LIBRARY and PNG_PNG_INCLUDE_DIR but other projects might call them something different.
> > 
> No, those are not the project's variables. These all come from cmake. The file
>    /opt/local/share/cmake-2.8/Modules/FindPNG.cmake
> in particular. There a huge number of files
>    /opt/local/share/cmake-2.8/Modules/Find***.cmake
> that come with CMake and those are supposed to be used to find certain libraries. The libraries that aren't covered must come from the project though.
> 
> What I really wonder is if there is some global setting that would choose the libraries in /opt/local rather that the one in /usr when there is more than one library installed. Or if there should be one.


More information about the macports-dev mailing list