0

我正在寻找一种使用 CMake(makefile 示例)实现以下目标的方法:

*.elf: *.c
    <do stuff>

post-processing-target: *.elf
    <do stuff>

我目前有以下内容:

add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME}
        PRIVATE
                ${C_FILES}
)
target_include_directories(${PROJECT_NAME}
        PRIVATE
                ${INCLUDE_DIRS}
)

add_custom_command(
    TARGET ${PROJECT_NAME}
    POST_BUILD
    <more stuff>

这按预期工作,但现在我试图添加“后处理”目标,如下所示(注释掉我的一些测试尝试):

add_executable(${POST_PROCESS_PROJECT_NAME})
#add_dependencies(${POST_PROCESS_PROJECT_NAME} ${PROJECT_NAME})

add_custom_command(
    TARGET ${POST_PROCESS_PROJECT_NAME}
    #POST_BUILD
    MAIN_DEPENDENCY ${PROJECT_NAME}
    #DEPENDS ${PROJECT_NAME}
    <Do stuff>

问题是我每次尝试从 CMakeLists.txt 生成 makefile 时都会收到以下错误(或类似错误):

CMake Error at CMakeLists.txt:82 (add_executable):
  No SOURCES given to target: post-processing-target

关于如何实现预期功能的任何想法?

BR

4

0 回答 0