在编译时更新资源
Updating resources at compile
我有一个 COM 服务器,tlb 应该集成到其中。我使用 cmake(ToolChain Visual Studio 2019)和以下命令收集它
set(SOURCES ... myLib.idl myLib.rc)
add_executable(myLib.exe WIN32 ${SOURCES})
set(MIDL_OUTPUT
${CMAKE_CURRENT_LIST_DIR}/myLib_i.h
${CMAKE_CURRENT_LIST_DIR}/myLib_i.c
)
set(MIDL_FILE ${CMAKE_CURRENT_LIST_DIR}/myLib.idl)
set(TLB_NAME "${CMAKE_CURRENT_LIST_DIR}/myLib.tlb")
add_custom_command(
OUTPUT ${MIDL_OUTPUT}
COMMENT "midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target NT60"
COMMAND midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target "NT60"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${MIDL_FILE}
MAIN_DEPENDENCY ${MIDL_FILE}
VERBATIM
)
target_sources(myLib.exe PRIVATE ${MIDL_FILE} ${MIDL_OUTPUT})
和myLib.rc
文件
1 TYPELIB "myLib.tlb"
问题:修改idl文件后,将之前版本的tlb文件添加为资源。直到我构建项目
据我了解,问题是 myLib.rc.res
文件在编译期间没有更新。我怎样才能让它更新?
结果是这样的:
add_custom_command(
OUTPUT ${MIDL_OUTPUT}
COMMENT "midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target NT60"
COMMAND midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target "NT60"
COMMAND "C:/Program Files/Git/usr/bin/touch.exe" -c "-r${TLB_NAME}" "${CMAKE_CURRENT_LIST_DIR}/myLib.rc"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${MIDL_FILE}
MAIN_DEPENDENCY ${MIDL_FILE}
VERBATIM
)
我向 add_custom_command
添加了另一个命令,该命令在创建 tlb 时更改 rc 文件的创建日期。之后,编译器自己重建 myLib.rc.res
我有一个 COM 服务器,tlb 应该集成到其中。我使用 cmake(ToolChain Visual Studio 2019)和以下命令收集它
set(SOURCES ... myLib.idl myLib.rc)
add_executable(myLib.exe WIN32 ${SOURCES})
set(MIDL_OUTPUT
${CMAKE_CURRENT_LIST_DIR}/myLib_i.h
${CMAKE_CURRENT_LIST_DIR}/myLib_i.c
)
set(MIDL_FILE ${CMAKE_CURRENT_LIST_DIR}/myLib.idl)
set(TLB_NAME "${CMAKE_CURRENT_LIST_DIR}/myLib.tlb")
add_custom_command(
OUTPUT ${MIDL_OUTPUT}
COMMENT "midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target NT60"
COMMAND midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target "NT60"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${MIDL_FILE}
MAIN_DEPENDENCY ${MIDL_FILE}
VERBATIM
)
target_sources(myLib.exe PRIVATE ${MIDL_FILE} ${MIDL_OUTPUT})
和myLib.rc
文件
1 TYPELIB "myLib.tlb"
问题:修改idl文件后,将之前版本的tlb文件添加为资源。直到我构建项目
据我了解,问题是 myLib.rc.res
文件在编译期间没有更新。我怎样才能让它更新?
结果是这样的:
add_custom_command(
OUTPUT ${MIDL_OUTPUT}
COMMENT "midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target NT60"
COMMAND midl /h myLib_i.h /iid myLib_i.c /tlb ${TLB_NAME} /proxy myLib_p.c ${MIDL_FILE} /env x64 /W1 /char signed /robust /nologo /Oicf /target "NT60"
COMMAND "C:/Program Files/Git/usr/bin/touch.exe" -c "-r${TLB_NAME}" "${CMAKE_CURRENT_LIST_DIR}/myLib.rc"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
DEPENDS ${MIDL_FILE}
MAIN_DEPENDENCY ${MIDL_FILE}
VERBATIM
)
我向 add_custom_command
添加了另一个命令,该命令在创建 tlb 时更改 rc 文件的创建日期。之后,编译器自己重建 myLib.rc.res