[CMake] PKG_CHECK_MODULE returns lists of parameters, not usable directly with SET_TARGET_PROPERTIES

Nicolas Mansard nmansard at yahoo.fr
Fri Jun 12 06:15:40 EDT 2009


Hello,

I am getting compilation informations for third-party libs using pkg_config:
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(MatrixAbstractLayer REQUIRED ${_MatrixAbstractLayer_REQUIRED})
MESSAGE("CFlags: ${MatrixAbstractLayer_CFLAGS}") 

If more than one cflags are necessary for the third-party, the flags are returned in a list (ie separated with semicolon and not with with spaces). For example, under linux, the previous code will display
CFlags: -DNDEBUG;-D_BOOST_;-I/usr/local/4.2.4/include;-I/usr/include/boost-sandbox

Then, these flags have to be used for compilation. I have to affect them to a particular target, ie using set_target_properties. I am not able to find the proper way to specify the arguments.
One solution is to give directly the list as argument, example:
SET_TARGET_PROPERTIES(${${PROJECT_NAME}_INTERN_LIBS} 
                     PROPERTIES COMPILE_FLAGS ${MatrixAbstractLayer_CFLAGS})
However, when ${MatrixAbstractLayer_CFLAGS} contains more than one flag, this syntax is not accepted by set_target_properties:
CMake Error at src/CMakeLists.txt:83 (SET_TARGET_PROPERTIES):
  set_target_properties called with incorrect number of arguments.

Another solution is to encapsulated the flags with ""
SET_TARGET_PROPERTIES(${${PROJECT_NAME}_INTERN_LIBS} 
                     PROPERTIES COMPILE_FLAGS "${MatrixAbstractLayer_CFLAGS}")
Ok, this is considered as one single arguments, but with semicolon inside, which will definitely not correspond to the syntax of the compiler. Under linux, this will produces the following compiler execution
cd /home/nmansard/src/reforge/StackOfTasks/build/src && /usr/bin/c++    -Dsot_0_EXPORTS -Wall -DNDEBUG -DWITH_OPENHRP -O3 -fPIC -I/home/nmansard/src/reforge/StackOfTasks/build/include -I/usr/include/boost-sandbox   -DNDEBUG;-D_BOOST_;-I/usr/local/4.2.4/include;-I/usr/include/boost-sandbox -o CMakeFiles/sot-0.dir/debug/sotDebug.cpp.o -c /home/nmansard/src/reforge/StackOfTasks/src/debug/sotDebug.cpp
c++: no input files
/bin/sh: -D_BOOST_: not found
Note the ";" that separated the arguments of g++. I guess that a similar problem would occurs on MSVC++

A last solution is to manually parse the args list to a string:
set(libsotcf "")
foreach(cf ${_MatrixAbstractLayer_CFLAGS})
  set(libsotcf "${libsotcf} ${cf}")
endforeach(cf)
Cumbersome ... Isn't there any alternative more straitforward solution?

I found some references to that problem on the www, but no answer. EG:
http://www.mail-archive.com/playerstage-commit@lists.sourceforge.net/msg02935.html
http://svn.apache.org/repos/asf/qpid/trunk/qpid/cpp/src/ssl.cmake

Additionaly, this is link to the use of LIST(APPEND VAR "args"), which is recommended here (second paragraph Use LIST(APPEND ...)).
http://www.vtk.org/Wiki/CMake_Performance_Tips
Similarly, the result of such a concatenation will not be admissible for set_target_properties.

Thanks for the help.
Nico



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090612/f31ed0fb/attachment.htm>


More information about the CMake mailing list