reactos/sdk/cmake/midl-support.cmake
Hermès Bélusca-Maïto ee92f4b28e
[SDK:CMAKE/IDL] Fix dependency tracking in generate_idl_iids() and extra cleanup.
Do the same in add_idl_reg_script() (currently unused helper) as well.

This is an addendum to commit b587e7b32, where the removal of the
IDL_FILE_FULL variable definition, broke dependency tracking with
the DEPENDS option. Now we use the correct variable.

The problem was caught after doing a partial (non-clean) build after
commit 0d10fb814. In this commit, two new interfaces, IExecuteCommand
and IObjectWithSelection, were added in the psdk/shobjidl.idl file
and used elsewhere. Recompilation correctly regenerated the corresponding
header, psdk/shobjidl.h, but did not trigger a regeneration of the uuid
static library (via the regeneration of sdk/lib/uuid/shobjidl_i.c),
due to broken dependency tracking on the shobjidl.idl file.
Because of this, the shobjidl_i.c did not contain the new GUID
definitions for these new interfaces, IID_IExecuteCommand and
IID_IObjectWithSelection, and triggered linking errors for the
com_apitest, actxprxy and shell32 modules:

```
error LNK2001: unresolved external symbol _IID_IExecuteCommand
error LNK2001: unresolved external symbol _IID_IObjectWithSelection
fatal error LNK1120: 2 unresolved externals
```
2024-06-04 22:21:59 +02:00

111 lines
4.5 KiB
CMake

#idl files support
if(ARCH STREQUAL "i386")
set(IDL_FLAGS /nologo /win32 /no_def_idir)
elseif(ARCH STREQUAL "amd64")
set(IDL_FLAGS /nologo /amd64 /no_def_idir)
else()
set(IDL_FLAGS /nologo /no_def_idir)
endif()
function(add_typelib)
get_includes(_includes)
get_defines(_defines)
foreach(_idl_file ${ARGN})
get_filename_component(_name_we ${_idl_file} NAME_WE)
add_custom_command(
OUTPUT ${_name_we}.tlb
COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /tlb ${_name_we}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
endforeach()
endfunction()
function(add_idl_headers TARGET)
get_includes(_includes)
get_defines(_defines)
foreach(_idl_file ${ARGN})
get_filename_component(_name_we ${_idl_file} NAME_WE)
add_custom_command(
OUTPUT ${_name_we}.h
COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}.h /client none /server none /iid ${_name_we}_dummy_i.c ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
list(APPEND _target_dependencies ${_name_we}.h)
endforeach()
add_custom_target(${TARGET} DEPENDS ${_target_dependencies})
endfunction()
function(add_rpcproxy_files)
get_includes(_includes)
get_defines(_defines)
set(_chain_dependency "")
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES GENERATED TRUE)
foreach(_idl_file ${ARGN})
get_filename_component(_name_we ${_idl_file} NAME_WE)
add_custom_command(
OUTPUT ${_name_we}_p.c ${_name_we}_p.h
COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /client none /server none /proxy ${_name_we}_p.c /h ${_name_we}_p.h /dlldata proxy.dlldata.c ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file} ${_chain_dependency})
list(APPEND _chain_dependency ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_p.c)
list(APPEND _chain_dependency ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_p.h)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
endforeach()
endfunction()
function(add_rpc_files _type)
get_includes(_includes)
get_defines(_defines)
# Is it a client or server module?
if(_type STREQUAL "server")
set(_server_client /sstub)
set(_suffix _s)
set(_prevent_second_type /client none)
elseif(_type STREQUAL "client")
set(_server_client /cstub)
set(_suffix _c)
set(_prevent_second_type /server none)
else()
message(FATAL_ERROR "Please pass either server or client as argument to add_rpc_files")
endif()
foreach(_idl_file ${ARGN})
if(NOT IS_ABSOLUTE ${_idl_file})
set(_idl_file ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
endif()
get_filename_component(_name_we ${_idl_file} NAME_WE)
set(_name_we ${_name_we}${_suffix})
add_custom_command(
OUTPUT ${_name_we}.c ${_name_we}.h
COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}.h ${_server_client} ${_name_we}.c ${_prevent_second_type} ${_idl_file}
DEPENDS ${_idl_file})
endforeach()
endfunction()
function(generate_idl_iids)
foreach(_idl_file ${ARGN})
get_includes(_includes)
get_defines(_defines)
if(NOT IS_ABSOLUTE ${_idl_file})
set(_idl_file "${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}")
endif()
get_filename_component(_name_we ${_idl_file} NAME_WE)
add_custom_command(
OUTPUT ${_name_we}_i.c ${_name_we}_i.h
COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}_i.h /client none /server none /iid ${_name_we}_i.c /proxy ${_name_we}_dummy_p.c ${_idl_file}
DEPENDS ${_idl_file})
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_i.c PROPERTIES GENERATED TRUE)
endforeach()
endfunction()
function(add_iid_library _target)
foreach(_idl_file ${ARGN})
generate_idl_iids(${_idl_file})
get_filename_component(_name_we ${_idl_file} NAME_WE)
list(APPEND _iid_sources ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_i.c)
endforeach()
add_library(${_target} ${_iid_sources})
# for wtypes.h
add_dependencies(${_target} psdk)
set_target_properties(${_target} PROPERTIES EXCLUDE_FROM_ALL TRUE)
endfunction()