[CMake] How to preserve directory structure within Visual Studio

David Cole david.cole at kitware.com
Thu Dec 8 20:34:39 EST 2011


2011/12/8 Mateusz Łoskot <mateusz at loskot.net>:
> 2011/12/8 David Cole <david.cole at kitware.com>:
>> 2011/12/8 Mateusz Łoskot <mateusz at loskot.net>:
>>> On 8 December 2011 21:45, 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...
>>>
>>> Is it the source_group still the recommended way of grouping?
>>
>> Yes, the source_group command should be able to handle this. Try it
>> with "\\" and "/" separators, I can't remember which character is used
>> to split on for sub-folders within the project file. (Maybe either
>> works...?)
>
>
> The issue I have always suffered is that search_group (or related parties)
> ignores source files (any specified) if they are not used in the targets.
>
> Here is illustration from one of my C++ headers-only pet projects:
>
> 1) I need to collect and structure all headers I want to have listed in
> Solution Explorer in Visual Studio:
> https://github.com/mloskot/boost-gil-workshop/blob/master/CMakeLists.txt
>
> file(GLOB GIL_HPP "${GIL_DIR}/*.hpp")
> file(GLOB GIL_EXT_IO_HPP "${GIL_EXT_IO_DIR}/*.hpp")
> file(GLOB GIL_EXT_IO_DETAIL_HPP "${GIL_EXT_IO_DIR}/detail/*.hpp")
>
> # Make single list with all headers for convenience in 2)
> if(MSVC)
>  list(APPEND GIL_ALL_HPP ${GIL_HPP})
>  list(APPEND GIL_ALL_HPP ${GIL_EXT_IO_HPP})
>  list(APPEND GIL_ALL_HPP ${GIL_EXT_IO_DETAIL_HPP})
> endif()
>
> 2) Indicate the headers are used source files:
>
> add_executable(gil_pnm_test gil_pnm_test.cpp ${GIL_ALL_HPP})
>
> 3) Assign headers to groups:
>
> https://github.com/mloskot/boost-gil-workshop/blob/master/test/CMakeLists.txt
>
> source_group("Header Files\\gil" FILES ${GIL_HPP})
> source_group("Header Files\\gil\\extension\\io_new" FILES ${GIL_EXT_IO_HPP})
> source_group("Header Files\\gil\\extension\\io_new\\detail" FILES
> ${GIL_EXT_IO_DETAIL_HPP})
>
> Has anything changed to make the procedure easier?
>

Not that I'm aware of -- this looks quite reasonable to me.


> Best regards,
> --
> Mateusz Loskot, http://mateusz.loskot.net


More information about the CMake mailing list