[CMake] [Cygwin] SET_TARGET_PROPERTIES does not work fine

Clark J. Wang dearvoid at gmail.com
Tue May 22 21:50:21 EDT 2007


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)

Cmake ran well but make failed:

$ cmake .
-- Check for working C compiler: /bin/gcc.exe
-- Check for working C compiler: /bin/gcc.exe -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: /bin/c++.exe
-- Check for working CXX compiler: /bin/c++.exe -- works
-- Configuring done
-- Generating done
-- Build files have been written to: /home/Administrator/tmp
$ make
/bin/cmake.exe -H/home/Administrator/tmp -B/home/Administrator/tmp
--check-build-system CMakeFiles/Makefile.cmake 0
/bin/cmake.exe -E cmake_progress_start /home/Administrator/tmp/CMakeFiles 1
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/cygdrive/e/jwang/tmp'
make -f CMakeFiles/grep_pcre.dir/build.make CMakeFiles/grep_pcre.dir/depend
make[2]: Entering directory `/cygdrive/e/jwang/tmp'
make[2]: Warning: File `CMakeFiles/grep_pcre.dir/depend.make' has
modification time 1.1 s in the future
Scanning dependencies of target grep_pcre
cd /home/Administrator/tmp && /bin/cmake.exe -E cmake_depends "Unix
Makefiles" /home/Administrator/tmp /home/Administrator/tmp
/home/Administrator/tmp /home/Administrator/tmp
/home/Administrator/tmp/CMakeFiles/grep_pcre.dir/DependInfo.cmake
make[2]: warning:  Clock skew detected.  Your build may be incomplete.
make[2]: Leaving directory `/cygdrive/e/jwang/tmp'
make -f CMakeFiles/grep_pcre.dir/build.make CMakeFiles/grep_pcre.dir/build
make[2]: Entering directory `/cygdrive/e/jwang/tmp'
make[2]: Warning: File `CMakeFiles/grep_pcre.dir/depend.make' has
modification time 0.29 s in the future
/bin/cmake.exe -E cmake_progress_report /home/Administrator/tmp/CMakeFiles 1
[100%] Building C object CMakeFiles/grep_pcre.dir/grep.o
/bin/gcc.exe   -DUSE_PCRE  -o CMakeFiles/grep_pcre.dir/grep.o   -c
/home/Administrator/tmp/grep.c
/home/Administrator/tmp/grep.c:16:2: warning: #warning Using PCRE
Linking C executable grep_pcre.exe
/bin/cmake.exe -P CMakeFiles/grep_pcre.dir/cmake_clean_target.cmake
/bin/gcc.exe     -L/usr/lib -lpcre "CMakeFiles/grep_pcre.dir/grep.o"   -o
grep_pcre.exe -Wl,--major-image-version,0,--minor-image-version,0
CMakeFiles/grep_pcre.dir/grep.o:grep.c:(.text+0x15a): undefined reference to
`_pcre_exec'
CMakeFiles/grep_pcre.dir/grep.o:grep.c:(.text+0x3aa): undefined reference to
`_pcre_compile'
CMakeFiles/grep_pcre.dir/grep.o:grep.c:(.text+0x47b): undefined reference to
`_pcre_exec'
CMakeFiles/grep_pcre.dir/grep.o:grep.c:(.text+0x4d9): undefined reference to
`_pcre_free'
collect2: ld returned 1 exit status
make[2]: *** [grep_pcre.exe] Error 1
make[2]: Leaving directory `/cygdrive/e/jwang/tmp'
make[1]: *** [CMakeFiles/grep_pcre.dir/all] Error 2
make[1]: Leaving directory `/cygdrive/e/jwang/tmp'
make: *** [all] Error 2

The problem is that when linking `grep_pcre' CMake puts LINK_FLAGS
`-L/usr/lib -lpcre' before the object file
`CMakeFiles/grep_pcre.dir/grep.o'. The following command works well:

$ /bin/gcc.exe "CMakeFiles/grep_pcre.dir/grep.o" -L/usr/lib -lpcre -o
grep_pcre.exe -Wl,--major-image-version,0,--minor-image-version,0

I'm not sure whether it's gcc's bug or not. But why doesn't CMake put
LINK_FLAGS after the object files? Or is there any workaround I can do?

Thanks.

--
Clark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070523/89f35f57/attachment.html


More information about the CMake mailing list