Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: install executables and create links to them

I'm using cmake and cpack to build my project and build packages. I'm creating a few executables in my project, let's call them EXE1 and EXE2.

When creating different versions of these executables, I want to name to reflect the version of the executable (let's say EXE1_1.0.0). I can change the name of the output for a target by doing set_target_properties.

However, now when doing an install, I want to do create a symlink to this versioned name of the executable, i.e. I want to have

  • the "versioned" executable installed in bin directory, i.e. EXE1_1.0.0
  • create a symlink to the "versioned" executable, i.e. create symlink EXE1, which points to EXE1_1.0.0

Can someone suggest me how to do this?

Second question is: How to install configuration files /etc/MYPROJECT/ directory? What DESTINATION I need to use for configuration files, like I use bin for executables and lib for libraries? Is using an absolute path like /etc an acceptable practice with cmake?

like image 408
Lazylabs Avatar asked Oct 23 '22 01:10

Lazylabs


1 Answers

I asked this question on cmake mailing list subsequently, and this is the response I received:

The validity of the answer will depend on which CMake version you use and which set of platform you want to support.

Symlinks are not that portable

a) Creation may not be [currently] done portably but if you are targeting Unix you can use cmake -E create_symlink to create one.

b) Depending on the CPack generator you use and CMake/CPack version
symlinks may be embedded in the package or not.

i.e. CPack pre 2.8.7 cannot create ZIP archive which contains symlinks CPack 2.8.8 can do that now.

Then you can use an install(SCRIPT ... or install(CODE ...) to do that at install time.

Another option if you are using RPM is to use package specific post install script. cpack --help-variable CPACK_RPM_POST_INSTALL_SCRIPT_FILE

this last solution will off course only work for CPack RPM.

For second question

You can use absolute destination path, they should be handled just fine by CPack DEB and RPM, I don't know for other.

If your software should be installed on Windows this is won't work with archive generator (ZIP, TGZ, etc...) and/or NSIS.

May be you can do something like:

if(UNIX AND NOT APPLE) set(CONFDEST "/etc/${CMAKE_PROJECT_NAME}") else() set(CONFDEST "etc") endif()

install(FILES yourconffile DESTINATION ${CONFDEST})

like image 163
Lazylabs Avatar answered Oct 30 '22 13:10

Lazylabs