tags:

views:

96

answers:

1
find_package(GTK)

How can I make it output something so that I can know whether it finds something or not?

Platform: windows XP

+1  A: 

You can use the message command as in:

FIND_PACKAGE(GTK)
IF (${GTK_FOUND})
   MESSAGE(STATUS "Found GTK.")
ELSE (${GTK_FOUND})
   MESSAGE(STATUS "Could not locate GTK.")
ENDIF (${GTK_FOUND})

Or, if you want it to abort if GTK isn't found:

FIND_PACKAGE(GTK)
IF (${GTK_FOUND})
   MESSAGE(STATUS "Found GTK.")
ELSE (${GTK_FOUND})
   MESSAGE(FATAL_ERROR "Could not locate GTK.")
ENDIF (${GTK_FOUND})

Note that if you do the latter, then you can simply use the "REQUIRED" flag with FIND_PACKAGE, as specifying the "REQUIRED" flag ensures that it will fail with an error if it isn't found:

FIND_PACKAGE(GTK REQUIRED)

The command above will cause CMake to abort and print an error message if GTK is not found. You may also be interested in the documentation for FIND_PACKAGE from the CMake Manual. Also, one should note that FIND_PACKAGE(XYZ) actually invokes the CMake module FindXYZ, and so each package with a corresponding FIND_PACKAGE has its own CMake module implementing the find operation... since CMake is stilll somewhat new, some of those find modules are not correctly implemented... based on your comments below, it would seem that FindGTK has not been implemented correctly (since if it isn't present, the use of the REQUIRED flag should cause it to abort with a fatal error, but does not seem to do so in your case).

Michael Aaron Safyan
It just outputs `-- Could not locate GTK` but doesn't abort .
Gtker
@Runner, if you want it to abort, use MESSAGE(FATAL_ERROR "Could not locate GTK.") instead of MESSAGE(STATUS "Could not locate GTK."). Or, simply use FIND_PACKAGE(GTK REQUIRED).
Michael Aaron Safyan
I used `FIND_PACKAGE(GTK REQUIRED)` but it doesn't abort, just outputs `Could not locate GTK`.
Gtker
@Runner, that means that FindGTK is broken; it is supposed to abort.
Michael Aaron Safyan
Where can I find the `FindGTK` on windows platform?
Gtker
It's in the "Modules" folder of CMake, wherever you happen to have CMake installed. It should be named "FindGTK.cmake". I would just do a search for "FindGTK.cmake" on your system.
Michael Aaron Safyan
Oh I found `FindGTK.cmake` and `FindGTK2.cmake` there,what's the difference? Maybe I should switch to `GTK2`?
Gtker
Well, it depends on if you are planning to use libgtk or libgtk2. They are different libraries (the 1.0 line vs. the 2.0 line). Which one does your code use?
Michael Aaron Safyan
I should add that if you are planning to write cross-platform code, using Qt instead of GTK is probably a better idea... while GTK has been ported to Windows and to Mac OS X, it really doesn't work so well on either, while Qt runs very well on Windows, OS X, and Linux.
Michael Aaron Safyan
If you are just starting your project and haven't written any code, you might want to start with:http://code.google.com/p/cpp-project-template/
Michael Aaron Safyan
I've no idea which one should I use exactly,I'm following this tutorial(it uses `#include <gtk/gtk.h>`): http://luv.asn.au/overheads/gtk_intro/index.html
Gtker
@Runner, but what is your goal? Are you trying to create a GUI program? Or are you trying to learn GTK, specifically? If you are just trying to create a GUI program, then learning Qt is a better choice, IMHO.
Michael Aaron Safyan