Sync with trunk r63743.
[reactos.git] / cmake / midl-support.cmake
1
2 #idl files support
3 if(ARCH STREQUAL "i386")
4 set(IDL_FLAGS /nologo /win32 /no_def_idir)
5 elseif(ARCH STREQUAL "amd64")
6 set(IDL_FLAGS /nologo /amd64 /no_def_idir)
7 else()
8 set(IDL_FLAGS /nologo /no_def_idir)
9 endif()
10
11 function(add_typelib)
12 get_includes(_includes)
13 get_defines(_defines)
14 foreach(_idl_file ${ARGN})
15 get_filename_component(_name_we ${_idl_file} NAME_WE)
16 add_custom_command(
17 OUTPUT ${_name_we}.tlb
18 COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /tlb ${_name_we}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}
19 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
20 endforeach()
21 endfunction()
22
23 function(add_idl_headers TARGET)
24 get_includes(_includes)
25 get_defines(_defines)
26 foreach(_idl_file ${ARGN})
27 get_filename_component(_name_we ${_idl_file} NAME_WE)
28 add_custom_command(
29 OUTPUT ${_name_we}.h
30 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}
31 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
32 list(APPEND _target_dependencies ${_name_we}.h)
33 endforeach()
34 add_custom_target(${TARGET} DEPENDS ${_target_dependencies})
35 endfunction()
36
37 function(add_rpcproxy_files)
38 get_includes(_includes)
39 get_defines(_defines)
40 set(_chain_dependency "")
41 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES GENERATED TRUE)
42 foreach(_idl_file ${ARGN})
43 get_filename_component(_name_we ${_idl_file} NAME_WE)
44 add_custom_command(
45 OUTPUT ${_name_we}_p.c ${_name_we}_p.h
46 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}
47 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file} ${_chain_dependency})
48 list(APPEND _chain_dependency ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_p.c)
49 list(APPEND _chain_dependency ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_p.h)
50 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
51 endforeach()
52 endfunction()
53
54 function(add_rpc_files _type)
55 get_includes(_includes)
56 get_defines(_defines)
57 # Is it a client or server module?
58 if(_type STREQUAL "server")
59 set(_server_client /sstub)
60 set(_suffix _s)
61 set(_prevent_second_type /client none)
62 elseif(_type STREQUAL "client")
63 set(_server_client /cstub)
64 set(_suffix _c)
65 set(_prevent_second_type /server none)
66 else()
67 message(FATAL_ERROR "Please pass either server or client as argument to add_rpc_files")
68 endif()
69 foreach(_idl_file ${ARGN})
70 if(NOT IS_ABSOLUTE ${_idl_file})
71 set(_idl_file ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
72 endif()
73 get_filename_component(_name_we ${_idl_file} NAME_WE)
74 set(_name_we ${_name_we}${_suffix})
75 add_custom_command(
76 OUTPUT ${_name_we}.c ${_name_we}.h
77 COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}.h ${_server_client} ${_name_we}.c ${_prevent_second_type} ${_idl_file}
78 DEPENDS ${_idl_file})
79 endforeach()
80 endfunction()
81
82 function(generate_idl_iids)
83 foreach(_idl_file ${ARGN})
84 get_includes(_includes)
85 get_defines(_defines)
86
87 if(NOT IS_ABSOLUTE ${_idl_file})
88 set(_idl_file "${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}")
89 endif()
90
91 get_filename_component(_name_we ${_idl_file} NAME_WE)
92 add_custom_command(
93 OUTPUT ${_name_we}_i.c ${_name_we}_i.h
94 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}
95 DEPENDS ${_idl_file})
96 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_i.c PROPERTIES GENERATED TRUE)
97 endforeach()
98 endfunction()
99
100 function(add_iid_library _target)
101
102 foreach(_idl_file ${ARGN})
103 generate_idl_iids(${_idl_file})
104 get_filename_component(_name_we ${_idl_file} NAME_WE)
105 list(APPEND _iid_sources ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_i.c)
106 endforeach()
107 add_library(${_target} ${_iid_sources})
108
109 # for wtypes.h
110 add_dependencies(${_target} psdk)
111
112 set_target_properties(${_target} PROPERTIES EXCLUDE_FROM_ALL TRUE)
113 endfunction()