View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014631CMakeCMakepublic2013-12-04 14:332014-06-02 08:37
ReporterRyan H. Kawicki 
Assigned ToBrad King 
PrioritynormalSeveritytweakReproducibilityalways
StatusclosedResolutionfixed 
PlatformMicrosoftOSWindowsOS Version6.1.7601
Product VersionCMake 2.8.11.1 
Target VersionCMake 3.0Fixed in VersionCMake 3.0 
Summary0014631: source_group should document behavior of relative paths
DescriptionOutput of the custom command is unable to be properly placed in the IDE folder structure.

// simple example
cmake_minimum_required(VERSION 2.8.11.1)

project(blah)

set(all_src blah.cpp blah2.cpp)
SOURCE_GROUP("BlahFiles\\Source" FILES ${all_src})

ADD_CUSTOM_COMMAND(OUTPUT blah2.cpp
                   COMMAND del blah2.cpp
                   COMMAND echo 2>blah2.cpp
                   WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
                   COMMENT "create me some source")

add_executable(blah_test WIN32 ${all_src})
// end simple example

- first problem is that the IDE thinks that blah2.cpp is generated in binary source directory but the execution of the commands happens in the source directory. a little confusing and may need documentation updated to reflect this more clearly.

- the first issue can be resolved by removing the WORKING_DIRECTORY command. This solves the issue of not being able to find it correctly in the IDE (even though not correct directory), the build rules are able to execute, but it still shows up in the wrong location in the IDE.

- to resolve the second issue, we have to make a further change that i will just show in the next modified example below. What was changed was that I had to prefix CMAKE_CURRENT_BINARY_DIR to the source file to have it be able to place it correctly in the IDE. The odd thing here is that if not adding the prefix, things still work correctly. Add_executable, in the original issue, was still able to determine that blah2.cpp was a generated file and that it understood that the list of files provided somehow matched up (no cmake errors). Source_group, on the other hand, requires a full physical path of the generated file for it to properly find it in the list of provided source files, even though add_executable was able to determine that blah2.cpp was a GENERATED file without the full path.

// simple example
cmake_minimum_required(VERSION 2.8.11.1)

project(blah)

set(all_src blah.cpp "${CMAKE_CURRENT_BINARY_DIR}/blah2.cpp")
SOURCE_GROUP("BlahFiles\\Source" FILES ${all_src})

ADD_CUSTOM_COMMAND(OUTPUT blah2.cpp
                   COMMAND del blah2.cpp
                   COMMAND echo 2>blah2.cpp
                   COMMENT "create me some source")

add_executable(blah_test WIN32 ${all_src})
// end simple example

- my question / suggestion is to determine if it is possible for SOURCE_GROUP to also be able to understand, like add_executable, that blah2.cpp is a generated file and to marry the two together without the full path.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0034715)
Brad King (manager)
2013-12-04 14:58

> first problem is that the IDE thinks that blah2.cpp is generated in binary

http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:add_custom_command [^]
"If an output name is a relative path it will be interpreted relative
 to the build tree directory corresponding to the current source directory."

Generating files into the source tree is not recommended but if you insist:

 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/blah2.cpp

> Source_group, on the other hand, requires a full physical path of the generated file

The source_group command FILES option treats relative paths with respect to the current source directory:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmSourceGroupCommand.cxx;hb=v2.8.12.1#l78 [^]

though it looks like the whole option is not described in the docs.

Both the source_group FILES option and the add_custom_command OUTPUT option convert relative paths to full paths immediately.
The add_executable command saves the name and looks it up at the end and is therefore able to pick up the generated file.
(0034726)
Ryan H. Kawicki (reporter)
2013-12-05 13:01

>> "If an output name is a relative path it will be interpreted relative to the build tree directory corresponding to the current source directory."

I completely skipped over that (face palm). Sorry.

>> Generating files into the source tree is not recommended but if you insist:

I understand I can add the current source directory, but I guess I am more curious now as to why it is not recommended?

>> though it looks like the whole option is not described in the docs.

I guess this is why I was confused. I assumed that providing the same name for custom commands, source groups, and defining the files for the project would pick things up all the same. Thank you for clarifying this.

I guess then this comes down to a documentation issue for command source_group.

Thanks again for the explanation.
(0034727)
Brad King (manager)
2013-12-05 13:35

> I understand I can add the current source directory, but I guess I am more curious now as to why it is not recommended?

CMake supports generation of multiple build trees outside of the source tree. The source tree should be left pristine so that separate builds do not conflict.

> I guess then this comes down to a documentation issue for command source_group.

I've updated the documentation of source_group to clarify this:

 Help: Format and clarify source_group() documentation
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0060e955 [^]
(0036053)
Robert Maynard (manager)
2014-06-02 08:37

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2013-12-04 14:33 Ryan H. Kawicki New Issue
2013-12-04 14:58 Brad King Note Added: 0034715
2013-12-05 13:01 Ryan H. Kawicki Note Added: 0034726
2013-12-05 13:35 Brad King Note Added: 0034727
2013-12-05 13:35 Brad King Assigned To => Brad King
2013-12-05 13:35 Brad King Status new => resolved
2013-12-05 13:35 Brad King Resolution open => fixed
2013-12-05 13:35 Brad King Fixed in Version => CMake 3.0
2013-12-05 13:35 Brad King Target Version => CMake 3.0
2013-12-05 13:35 Brad King Summary Unable To Add Output Of Custom Command To Source Group Command => source_group should document behavior of relative paths
2014-06-02 08:37 Robert Maynard Note Added: 0036053
2014-06-02 08:37 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team