我要在CMAKE中使用MIDL编译器,但无法从CmakeList调用MIDL编译器

那是我用来实现目标的命令

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/IFace.h ${CMAKE_CURRENT_BINARY_DIR}/GUIDS.c ${CMAKE_CURRENT_BINARY_DIR}/Proxy.c ${CMAKE_CURRENT_BINARY_DIR}/ProxyDll.c
COMMAND midl /h IFace.h /iid GUIDS.c /proxy Proxy.c /dlldata ProxyDll.c ${CMAKE_CURRENT_LIST_DIR}/include/Server.idl
)

当我构建项目时,${CMAKE_CURRENT_BINARY_DIR}中没有MIDL编译器生成的文件

但是有了这个签名文件,生成的很好
add_custom_command(
PRE_BUILD
TARGET ${PROJECT_NAME}
COMMAND midl /h IFace.h /iid GUIDS.c /proxy Proxy.c /dlldata ProxyDll.c ${CMAKE_CURRENT_LIST_DIR}/include/Server.idl
)

我究竟做错了什么?

最佳答案

这就是它的工作方式:

set(MIDL_OUTPUT
    ${CMAKE_CURRENT_BINARY_DIR}/IFace.h
    ${CMAKE_CURRENT_BINARY_DIR}/GUIDS.c
    ${CMAKE_CURRENT_BINARY_DIR}/Proxy.c
    ${CMAKE_CURRENT_BINARY_DIR}/ProxyDll.c
    )
set(MIDL_FILE
    ${CMAKE_CURRENT_LIST_DIR}/include/Server.idl
    )
add_custom_command(
    OUTPUT ${MIDL_OUTPUT}
    COMMAND midl /h IFace.h /iid GUIDS.c /proxy Proxy.c /dlldata ProxyDll.c ${MIDL_FILE}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    DEPENDS ${MIDL_FILE}
    VERBATIM
    )
add_custom_target(midl-cmplr
    DEPENDS ${MIDL_OUTPUT}
    )
add_dependencies(${PROJECT_NAME}
    midl-cmplr
    )
set_source_files_properties(
    ${MIDL_OUTPUT}
        PROPERTIES
            GENERATED TRUE
            )

关于c++ - 从CMAKE调用MIDL编译器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46878906/

10-13 08:18