[CMAKE]
[reactos.git] / reactos / cmake / midl-support.cmake
1
2 #idl files support
3 if(ARCH MATCHES i386)
4 set(IDL_FLAGS /nologo /win32 /no_def_idir)
5 elseif(ARCH MATCHES 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 #set(_name ${CMAKE_CURRENT_BINARY_DIR}/${_name_we})
29 add_custom_command(
30 OUTPUT ${_name_we}.h ${_name_we}_dummy_i.c
31 COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}.h /iid ${_name_we}_dummy_i.c ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}
32 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file})
33 list(APPEND _target_dependencies ${_name_we}.h)
34 endforeach()
35 add_custom_target(${TARGET} DEPENDS ${_target_dependencies})
36 endfunction()
37
38 function(add_rpcproxy_files)
39 get_includes(_includes)
40 get_defines(_defines)
41 set(_output_files "")
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 proxy.dlldata.c
46 COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /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} ${_output_files})
48 list(APPEND _output_files ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_p.c)
49 list(APPEND _output_files ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_p.h)
50 endforeach()
51 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES GENERATED TRUE)
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 elseif(_type STREQUAL client)
62 set(_server_client /cstub)
63 set(_suffix _c)
64 else()
65 message(FATAL_ERROR "Please pass either server or client as argument to add_rpc_files")
66 endif()
67 foreach(FILE ${ARGN})
68 get_filename_component(_name_we ${FILE} NAME_WE)
69 set(_name_we ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}${_suffix})
70 if(NOT IS_ABSOLUTE ${FILE})
71 set(FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
72 endif()
73 add_custom_command(
74 OUTPUT ${_name_we}.c ${_name_we}.h
75 COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}.h ${_server_client} ${_name_we}.c ${FILE}
76 DEPENDS ${FILE})
77 endforeach()
78 endfunction()
79
80 function(generate_idl_iids _idl_file)
81 get_includes(_includes)
82 get_defines(_defines)
83
84 get_filename_component(_name ${_idl_file} NAME)
85 if(_name STREQUAL "${_idl_file}")
86 set(_idl_file "${CMAKE_CURRENT_SOURCE_DIR}/${_idl_file}")
87 endif()
88
89 get_filename_component(_name_we ${_idl_file} NAME_WE)
90 add_custom_command(
91 OUTPUT ${_name_we}_i.c ${_name_we}_i.h
92 COMMAND midl ${_includes} ${_defines} ${IDL_FLAGS} /h ${_name_we}_i.h /iid ${_name_we}_i.c ${_idl_file}
93 DEPENDS ${_idl_file})
94 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_i.c PROPERTIES GENERATED TRUE)
95 endfunction()
96
97 function(add_iid_library _target)
98
99 foreach(_idl_file ${ARGN})
100 generate_idl_iids(${_idl_file})
101 get_filename_component(_name_we ${_idl_file} NAME_WE)
102 list(APPEND _iid_sources ${CMAKE_CURRENT_BINARY_DIR}/${_name_we}_i.c)
103 endforeach()
104 add_library(${_target} ${_iid_sources})
105
106 # for wtypes.h
107 add_dependencies(${_target} psdk)
108
109 set_target_properties(${_target} PROPERTIES EXCLUDE_FROM_ALL TRUE)
110 endfunction()