On 5/23/07, Alan W. Irwin <[EMAIL PROTECTED]> wrote:

On 2007-05-23 09:50+0800 Clark J. Wang wrote:

> In Cygwin environment I have a C source file named `grep.c' which needs
> `libpcre' to compile. The CMakeLists.txt writes:
>
> PROJECT(myGrep)
>
> SET(CMAKE_VERBOSE_MAKEFILE ON)
>
> FIND_PROGRAM(PCRE_CONFIG pcre-config)
> IF(PCRE_CONFIG)
>   ADD_EXECUTABLE(grep_pcre grep.c)
>   SET_TARGET_PROPERTIES(grep_pcre
>       PROPERTIES
>       COMPILE_FLAGS "-DUSE_PCRE $(shell pcre-config --cflags)"
>       LINK_FLAGS "$(shell pcre-config --libs)"
>   )
> ENDIF(PCRE_CONFIG)

It's possible the above style might be made to work, but I am not sure
about
that so let me recommend a style that I know works in general for dealing
with the results of external configuration scripts (although I have no
specific experience with pcre-config).


The program `pcre-config' is used to determine paths of libpcre's header
file and library file. Actually in my Cygwin environment the above
CMakeLists.txt is the same as this one:

PROJECT(myGrep)

SET(CMAKE_VERBOSE_MAKEFILE ON)

ADD_EXECUTABLE(grep_pcre grep.c)
SET_TARGET_PROPERTIES(grep_pcre
   PROPERTIES
   COMPILE_FLAGS "-DUSE_PCRE"
   LINK_FLAGS "-L/usr/lib -lpcre"
)

And this CMakeLists.txt does not work either.

I suggest you use EXECUTE_PROCESS twice to run the configuration script to
determine compiler flags and the full path of the library that you need.
Store those results in different CMake variables, then use
SET_SOURCE_FILES_PROPERTIES to set the compile flags, and use
TARGET_LINK_LIBRARIES to link your executable target to the external
library (specified with its full path).

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and
Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting
software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________

_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to