MantisBT - CMake
View Issue Details
0013462CMakeCMakepublic2012-08-07 20:502013-01-09 10:55
Benjamin kay 
David Cole 
normalminoralways
closedno change required 
Debian (unstable)Linux3.2.0-3-amd64
CMake 2.8.8 
 
0013462: set_target_properties include_directories should accept multiple parameters
The set_target_properties command can be used to set properties on a library or executable. One of the properties that can be set is INCLUDE_DIRECTORIES, which is discussed on the mailing list: http://www.cmake.org/pipermail/cmake/2009-June/030429.html [^]

The ability to set INCLUDE_DIRECTORIES on a specific target without setting it on an entire directory (i.e. with the include_directories command) is useful; see related bugs 0008189 and 0001968. Unfortunately, it appears that only one include directory can be set in this way. Take a simple test project:

project(TESTPROJECT)
add_executable(test test.c)
set_target_properties(test PROPERTIES INCLUDE_DIRECTORIES /var /tmp)

Obviously there's no need to include anything from /var or /tmp -- they're just there to illustrate the following error that occurs when running cmake:

CMake Error at CMakeLists.txt:3 (set_target_properties):
  set_target_properties called with incorrect number of arguments.

The following alternative syntax appears to work, but running make with VERBOSE=1 reveals that only the last directory included (/tmp in this case) is actually included. /var is not included.

project(TESTPROJECT)
add_executable(test test.c)
set_target_properties(test PROPERTIES INCLUDE_DIRECTORIES /var INCLUDE_DIRECTORIES /tmp)

Other variations such as the following also fail (incorrect number of arguments):

project(TESTPROJECT)
add_executable(test test.c)
set(LIST_OF_DIRECTORIES /var)
list(APPEND LIST_OF_DIRECTORIES /tmp)
set_target_properties(test PROPERTIES INCLUDE_DIRECTORIES ${LIST_OF_DIRECTORIES})


For set_target_properties(target PROPERTIES INCLUDE_DIRECTORIES ...) to be truly useful, it should be able to accept multiple parameters.
The version of CMake installed on my system is actually 2.8.9-rc3, not 2.8.8.
No tags attached.
Issue History
2012-08-07 20:50Benjamin kayNew Issue
2012-08-08 02:46Rolf Eike BeerNote Added: 0030187
2012-08-08 03:42Stephen KellyNote Added: 0030188
2012-08-08 06:57David ColeAssigned To => David Cole
2012-08-08 06:57David ColeStatusnew => assigned
2012-08-08 06:58David ColeNote Added: 0030189
2012-08-08 06:58David ColeStatusassigned => resolved
2012-08-08 06:58David ColeResolutionopen => no change required
2012-08-08 08:21Benjamin kayNote Added: 0030190
2012-08-08 08:21Benjamin kayStatusresolved => feedback
2012-08-08 08:21Benjamin kayResolutionno change required => reopened
2012-08-08 08:26Brad KingNote Added: 0030191
2012-08-08 08:26Brad KingStatusfeedback => resolved
2012-08-08 08:26Brad KingResolutionreopened => no change required
2013-01-09 10:55Robert MaynardNote Added: 0032011
2013-01-09 10:55Robert MaynardStatusresolved => closed

Notes
(0030187)
Rolf Eike Beer   
2012-08-08 02:46   
I will bet it's a list, so this should work:

set_target_properties(test PROPERTIES INCLUDE_DIRECTORIES /var;/tmp)
(0030188)
Stephen Kelly   
2012-08-08 03:42   
Another one that works is

set_property(TARGET foo PROPERTY INCLUDE_DIRECTORIES ${LIST_OF_DIRECTORIES})

Note that you shouldn't create test targets called 'test' generally because it confuses ctest. It's better to get used to not doing so.
(0030189)
David Cole   
2012-08-08 06:58   
Please see the other notes for more information.

As noted:

Prefer "set_property' for passing multiple values to a property. Or simply use a list as a single argument to the existing set_target_properties.
(0030190)
Benjamin kay   
2012-08-08 08:21   
Thank you, Stephen Kelley has the right idea here.
SET_PROPERTY(TARGET <target> PROPERTY <name> [value1 [value2 ...]])
Is the correct way to set a target property with multiple values.

A careful re-reading of the documentation actually gives no indication that SET_TARGET_PROPERTIES() can do this at all. Rolf Eike Beer and David Cole, have you actually tried your suggestions to use semicolon-separated lists with SET_TARGET_PROPERTIES()? I have tried this and it does not work for me. If you feel it should work then please consider re-opening the bug, otherwise feel free to mark as invalid or resolved.
(0030191)
Brad King   
2012-08-08 08:26   
Re 0013462:0030190: Eike's suggestion is almost correct. You need to quote the argument to prevent it from getting split:

 set_target_properties(test PROPERTIES INCLUDE_DIRECTORIES "/var;/tmp")

Unquoted arguments are divided on semicolons into multiple separate arguments. This is standard CMake syntax and is not specific to this command.
(0032011)
Robert Maynard   
2013-01-09 10:55   
Closing resolved issues that have not been updated in more than 4 months.