[CMake] How to preserve directory structure within Visual Studio

David Cole david.cole at kitware.com
Fri Dec 9 11:58:47 EST 2011


On Fri, Dec 9, 2011 at 11:41 AM, J Decker <d3ck0r at gmail.com> wrote:
> On Thu, Dec 8, 2011 at 1:45 PM, David Cole <david.cole at kitware.com> wrote:
>> No, the FOLDER property is only a mechanism for grouping and
>> organizing *targets*, it is not a source file property...
>>
>
> uhh...  FOLDER works on projects in a solution, but it also works on
> source files within a project.
>
> SET_TARGET_PROPERTIES(bag.image PROPERTIES
>                  FOLDER "Image Library"
> ....)
>
> SET_SOURCE_FILES_PROPERTIES( ${OPTION_SOURCE} PROPERTIES
>                FOLDER "Source Files\\Option Library" )
>
>
>>
>> On Thu, Dec 8, 2011 at 4:19 PM, J Decker <d3ck0r at gmail.com> wrote:
>>> set_property(GLOBAL PROPERTY USE_FOLDERS On)
>>>
>>> SET_SOURCE_FILES_PROPERTIES( ${YOUR_SOURCES} PROPERTIES
>>>                FOLDER "project folder name here" )
>>>
>>>
>>> On Thu, Dec 8, 2011 at 12:32 PM, Stephen Torri <stephen.torri at gmail.com> wrote:
>>>> CMake version: 2.8
>>>> IDE: Visual Studio 2008
>>>>
>>>> For the source and header files I would like to preserve the directory
>>>> structure within the Visual Studio "Header Files" and "Source Files"
>>>> folders. Without it should there occur two files with the same name
>>>> but in different directories only one is shown. For example:
>>>>
>>>> SET ( HEADERS
>>>>   base_units/time.hpp
>>>>   si/time.hpp )
>>>>
>>>> add_custom_target ( UnitHeaders SOURCES ${HEADERS} )
>>>>
>>>> If UnitHeaders is included within the parent CMakeLists.txt file a
>>>> Project called UnitHeaders is included within the Visual Studio
>>>> Solution. What you will see undert the "Header Files" for UnitHeaders
>>>> is only one header file. I would like to see the following within
>>>> Visual Studio under Header Files:
>>>>
>>>> UnitHeaders
>>>>   |
>>>>   |-- Header Files -> base -> time.hpp
>>>>                          -> si -> time.hpp
>>>>
>>>> A search on Google has shown two similar questions asked in the past
>>>> but no answer was posted in reply to them.
>>>>
>>>> Stephen
>>>> --
>>>>
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.cmake.org/mailman/listinfo/cmake
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake

Well, you can set any properties you want on any entity you want. They
are just key/value pairs that are stored with the entity.

But, what I'm saying is: CMake does not pay attention to any FOLDER
property you put on your source files. If I grep the CMake source tree
for "FOLDER" the only uses I see of it are related to targets, not to
source files.

So. If you're saying that this has some sort of organizational effect
all by itself on your source files in your generated Visual Studio
projects, then I'd like to know what version of CMake you're using.
Sounds like 2.8.magic to me. :-)

Are you sure you don't also have proper source_group calls in your
CMakeLists.txt files?


David


More information about the CMake mailing list