How to add_custom_target that depends on “make install”

后端 未结 1 1199
自闭症患者
自闭症患者 2021-01-04 05:06

I\'d like to add a custom target named \"package\" which depends on install target. When I run make package it should cause first running make install

相关标签:
1条回答
  • 2021-01-04 06:00

    You can create custom target which will run install and some other script after.

    CMake script

    For instance if you have a CMake script MyScript.cmake:

    add_custom_target(
        MyInstall
        COMMAND
        "${CMAKE_COMMAND}" --build . --target install
        COMMAND
        "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/MyScript.cmake"
        WORKING_DIRECTORY
        "${CMAKE_BINARY_DIR}"
    )
    

    You can run it by building target MyInstall:

    cmake --build /path/to/build/directory --target MyInstall
    

    Python script

    Of course you can use any scripting language. Just remember to be polite to other platforms (so probably it's a bad idea to write bash script, it will not work on windows).

    For example python script MyScript.py:

    find_package(PythonInterp 3.2 REQUIRED)
    
    add_custom_target(
        MyInstall
        COMMAND
        "${CMAKE_COMMAND}" --build . --target install
        COMMAND
        "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/MyScript.py"
        WORKING_DIRECTORY
        "${CMAKE_BINARY_DIR}"
    )
    
    0 讨论(0)
提交回复
热议问题