cmake run script for install target?

后端 未结 2 1946
傲寒
傲寒 2020-12-16 19:41

I have a project where \"installing\" the code is not quite as simple as just copying some files. With a traditional Makefile, I would just create a make install

2条回答
  •  失恋的感觉
    2020-12-16 19:53

    CMake's install command allows for custom scripts. See the official documentation: install - Custom Installation Logic:

    install([[SCRIPT ] [CODE ]]
            [COMPONENT ] [...])
    

    The SCRIPT form will invoke the given CMake script files during installation. If the script file name is a relative path it will be interpreted with respect to the current source directory. The CODE form will invoke the given CMake code during installation. Code is specified as a single argument inside a double-quoted string. For example, the code

    install(CODE "MESSAGE(\"Sample install message.\")")
    

    will print a message during installation.

    To run custom shell script (or whatever program), combine install(CODE ...) with execute_process:

    install(CODE "execute_process(COMMAND my_script.sh)")
    

提交回复
热议问题