0

I have requirement to create different targets for different group of python files in my project. Any target can be dependent on one or more set of targets.

During, make install the files associated with specific targets, shall be copied to some build folder path. I know that we can copy the python files explicitly with below command.

install(FILES file1.py DESTINATION ${BUILD_FILES_INSTALL_PATH}

but, I can not give list of file explicitly with my requirement. Is there a way to install python files with target(for group of python files) name in install (or any other CMake) command?

For example: if there are 2 targets - target1, target2 (both for different set of python files)

I created the target for specific python files with below commands:

add_custom_target(target1 DEPENDS file1.py file2.py)

add_custom_target(target2 DEPENDS file3.py)

target1 has dependency on target2

So, during make install, is there any way to copy python files associated with target1 (and target2 as target1 has dependency on target2) with just giving target1 in install command?

Thank you.

Kevin
  • 16,549
  • 8
  • 60
  • 74
Vinay
  • 107
  • 1
  • 3
  • 15
  • 1
    CMake installs only the files which are **explicitly** requested for installation. No dependency is checked for get a list of the installed files. If you want, you may create your own functions/macros for drive "python targets": create such targets, add python scripts to them, declare dependency between such targets, install such targets. – Tsyvarev Jun 23 '20 at 07:21
  • Thank you very much, @Tsyvarev. if we forget about dependency for now, Can we copy the python files with giving target name in the CMake install function? before install, we would map files with the target with this function: (add_custom_target(target1 ALL file1.py file2.py) ) – Vinay Jun 23 '20 at 09:07
  • 1
    No, in CMake you cannot install **custom** target. This has no sense: You cannot bind files to a **custom** target. The call `add_custom_target(target1 ALL file1.py file2.py)` is invalid: it doesn't fit to the signature of [add_custom_target](https://cmake.org/cmake/help/latest/command/add_custom_target.html) command. You may, however, store a list of files in the **target's property**. So, for extract the list again, you just need to know the **target** name. E.g. you may define your own function `install_py` which takes only a target name and installs all files stored in its property. – Tsyvarev Jun 23 '20 at 09:49

0 Answers0