[CMake] problems detecting a required version of a library

Brad King brad.king at kitware.com
Wed Jun 28 13:09:47 EDT 2006


Scott Amort wrote:
> Hi Brad,
> 
> Thanks for the quick response.
> 
> Brad King wrote:
>> What is the output value of "antlr-config --libs"?  What is the command
>> you are using to store the value in the cache?
> 
> The output value is: /usr/lib64/libantlr.a on my AMD64 gentoo box.  I'm
> not doing anything specific re: cache, here are the exact commands:
> 
> FIND_PROGRAM(ANTLR_CONFIG
>   antlr-config
>   /usr/bin
>   /usr/local/bin
> )
> 
> IF(ANTLR_CONFIG)
> 
>   EXECUTE_PROCESS(COMMAND ${ANTLR_CONFIG} --libs OUTPUT_VARIABLE
> ANTLR_CONFIG_LIBS)
> 
> ENDIF(ANTLR_CONFIG)
> 
> ...and later in a subdirectory's CMakeLists.txt,
> 
> TARGET_LINK_LIBRARIES(mylibrary ${ANTLR_CONFIG_LIBS})
> 
> If I output ANTLR_CONFIG_LIBS to a status message, it seems to throw an
> end-of-line character into the output, which seems to be confusing the
> cache used by TARGET_LINK_LIBRARIES.  It is the TARGET_LINK_LIBRARIES
> that causes the actual problem, if I comment it out, everything works fine.
> 
> The actual error comes after a successful `cmake .', followed by `make':
> 
> CMake Error: Parse error in cache file (...)CMakeCache.txt. Offending
> entry: ;
> 
> Here are the offending lines in CMakeCache.txt:
> 
> //Dependencies for the target
> mylibrary_LIB_DEPENDS:STATIC=/usr/lib64/libantlr.a
> ;
> 
> I'm guessing the ; separator shouldn't be on a newline.
> 
> As a bit of experimentation, I discovered that by replacing the
> EXECUTE_PROCESS with:
> 
> EXEC_PROGRAM(${ANTLR_CONFIG} ARGS --libs OUTPUT_VARIABLE ANTLR_CONFIG_LIBS)
> 
> The problem is fixed.  No end-of-line appears in ANTLR_CONFIG_LIBS (or
> CMakeCache.txt), and the TARGET_LINK_LIBRARIES works just fine.
> 
> Perhaps a bug?

No, EXEC_PROGRAM and EXECUTE_PROCESS have different policies for 
capturing the output of a program.  It looks like EXEC_PROGRAM 
automatically strips leading and trailing whitespace from the output, 
while EXECUTE_PROCESS gives you the real output of the program.

Try putting this after EXECUTE_PROCESS:

STRING(REGEX REPLACE "[\r\n]+$" "" ANTLR_CONFIG_LIBS "${ANTLR_CONFIG_LIBS}")

-Brad


More information about the CMake mailing list