0

I need to create symbolic links to directory common_resources which contains textures, fonts, 3D models, shaders, and is located in my CMAKE_SOURCE_DIR. I have to put such a link into all of my compiled binary target's working directories (~50 directories).

I can probably do it one-by-one by adding this ADD_CUSTOM_TARGET to each subfolder

ADD_CUSTOM_TARGET( common_resources ALL  COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/common_resources ${CMAKE_CURRENT_BINARY_DIR}/common_resources )

but I do not want to do it because:

  1. I don't want to to edit all those CMakeList.txt files and
  2. I don't want to create so many custom targets for no reason. I use Code::Blocks IDE and I already have very long list of targets to select from, which makes it difficult to work with.
usr1234567
  • 21,601
  • 16
  • 108
  • 128
Prokop Hapala
  • 2,424
  • 2
  • 30
  • 59

1 Answers1

1

The answer is two-fold:

  1. Write a function wrapping the custom command.

  2. You have to automatically iterate over all sub-directories, see https://stackoverflow.com/a/7788165/2799037 how to do that. Call your function for every sub-directory.

Your second concern is probably a misconception. custom_command does not add a new target, that is only custom_target.

Community
  • 1
  • 1
usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • thanks, I' did not know how to use `custom_command`. Btw. do you have idea if it is possible to get rid of all `target/fast` which cmake generate by default dogether with `target` ? – Prokop Hapala Oct 08 '16 at 17:58