如何使用CMake post_build执行shell脚本?

时间:2022-03-18 14:40:04

How to execute a shell script using CMake? The command that should be run is my_script that should be executed after build. The CMakeLists.txt

如何使用CMake执行shell脚本?应该运行的命令是应该在构建之后执行的my_script。 CMakeLists.txt

cmake_minimum_required(VERSION 3.0)

project(abc)

include_directories("/usr/lib/avr/include")

set(CMAKE_CURRENT_SOURCE_DIR /home/user/Desktop)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmcu=atmega8")
set(SOURCE_FILES main.c)

add_executable(abc ${SOURCE_FILES})

#not working ----->
add_custom_command(TARGET abc
        POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E my_script
        )

DISCLAIMER

Yes, there are similar questions in SO here, here, here, etc; however, they don't give me a clear vision how this can be achieved.

是的,在这里,这里,这里等有类似的问题;但是,他们没有给我一个清晰的愿景如何实现这一目标。

1 个解决方案

#1


7  

You are invoking CMake with it's command-line tool mode which doesn't execute generic scripts or commands.

您正在使用命令行工具模式调用CMake,该模式不执行通用脚本或命令。

Instead do e.g.

相反,例如,

add_custom_command(TARGET abc
        POST_BUILD
        COMMAND /bin/sh /path/to/my_script
        )

#1


7  

You are invoking CMake with it's command-line tool mode which doesn't execute generic scripts or commands.

您正在使用命令行工具模式调用CMake,该模式不执行通用脚本或命令。

Instead do e.g.

相反,例如,

add_custom_command(TARGET abc
        POST_BUILD
        COMMAND /bin/sh /path/to/my_script
        )