[CMake] [Cygwin] SET_TARGET_PROPERTIES does not work fine

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue May 22 22:34:00 EDT 2007


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

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
__________________________


More information about the CMake mailing list