Create symlink to a install result

.
├── build
│ └── lib
│ └── foo.so
└── package
├── fixed
│ └── dir
│ └── structure
│ └── bar.so
└── lib
└── foo.so

I don’t have much experience on writing CMakeLists. I have a project where I want to create a symlink bar.so that points to “package/lib/foo.so”, and this needs to be done in a different CMakeLists.txt from the one for the target foo.

Some question:

  1. how to ensure the order? The foo.so has to be installed before symlink.
  2. how to create symlink? I think add_custom_target can help on this?

Not sure that matters, but just make sure the directory installing foo.so is add_subdirectory’d before the install() for the symlink is performed.

You can use install(CODE) or install(SCRIPT) to run CMake code at install time. There, you can use file(CREATE_LINK … SYMBOLIC).