1

I'm trying to use CMake to add an entire directory structure to my Visual Studio project. I know it is possible in VS because I already succeed by manually copying the root folder of the structure in the same directory of the project and by selecting "Include in Project". However, I'm not sure that it would be possible with CMake.

My .vcxproj contains this ItemGroup after this manual operation:

<ItemGroup>
   <Text Include="asd\test.txt" />
   <Text Include="asd\asd2\test.txt" />
</ItemGroup>

As you can see I just added two folders and two txt files. This produces the result I'm trying to achieve.

Any idea on how to generate this with CMake?

Oneiros
  • 4,328
  • 6
  • 40
  • 69
  • Possible duplicate of [How to set Visual Studio Filters for nested sub directory using cmake](https://stackoverflow.com/questions/31422680/how-to-set-visual-studio-filters-for-nested-sub-directory-using-cmake) – Florian Jul 03 '17 at 07:51
  • Thank you Florian but it is not what I need: I don't need to replicate the directory structure on my project as filters, I need the actual folders in the output directory of my project – Oneiros Jul 03 '17 at 12:10

1 Answers1

1

CMake is meant to hide the details of the build/OS environment from the user. This requires some generalization across platforms/environments. So it's difficult to get an exact copy of a manual made .vcxproj project.

You can add any files to CMake targets - explicitly including none-source files - that will then be added by CMake to generated IDE projects.

If I understand your particular case correctly the problem is to get Text instead of None tool name in ItemGroup source file's listing.

Since CMake version 3.7 you can use VS_TOOL_OVERRIDE source files property to override CMake's default for non-source files.

The following small example:

cmake_minimum_required(VERSION 3.7)

project(HelloWorld)

file(WRITE main.cpp [=[
#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;
}
]=])

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/asd/test.txt" "")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/asd/asd2/test.txt" "")

add_executable(HelloWorld "main.cpp" "asd/test.txt" "asd/asd2/test.txt")

set_source_files_properties(
    "asd/test.txt"
    "asd/asd2/test.txt" 
    PROPERTIES VS_TOOL_OVERRIDE "Text"
)

Does give your expected results. CMake just generates absolute paths by default.

Reference

Florian
  • 39,996
  • 9
  • 133
  • 149