[FFS] Silence some only-informative KdPrints.
[reactos.git] / sdk / cmake / widl-support.cmake
1
2 #idl files support
3 if(ARCH STREQUAL "i386")
4 set(IDL_FLAGS -m32 --win32)
5 elseif(ARCH STREQUAL "amd64")
6 set(IDL_FLAGS -m64 --win64)
7 else()
8 set(IDL_FLAGS "")
9 endif()
10
11 function(add_typelib)
12 get_includes(INCLUDES)
13 get_defines(DEFINES)
14 foreach(FILE ${ARGN})
15 if(${FILE} STREQUAL "std_ole_v1.idl")
16 set(IDL_FLAGS ${IDL_FLAGS} --oldtlb)
17 endif()
18 get_filename_component(NAME ${FILE} NAME_WE)
19 add_custom_command(
20 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb
21 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -t -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
22 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} native-widl)
23 list(APPEND OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb)
24 endforeach()
25 endfunction()
26
27 function(add_idl_headers TARGET)
28 get_includes(INCLUDES)
29 get_defines(DEFINES)
30 foreach(FILE ${ARGN})
31 get_filename_component(NAME ${FILE} NAME_WE)
32 set(HEADER ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h)
33 add_custom_command(
34 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h
35 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -h -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
36 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} native-widl)
37 list(APPEND HEADERS ${HEADER})
38 endforeach()
39 add_custom_target(${TARGET} DEPENDS ${HEADERS})
40 endfunction()
41
42 function(add_rpcproxy_files)
43 get_includes(INCLUDES)
44 get_defines(DEFINES)
45
46 foreach(FILE ${ARGN})
47 get_filename_component(NAME ${FILE} NAME_WE)
48 # Most proxy idl's have names like <proxyname>_<original>.idl
49 # We use this to create a dependency from the proxy to the original idl
50 string(REPLACE "_" ";" SPLIT_FILE ${FILE})
51 list(LENGTH SPLIT_FILE len)
52 unset(EXTRA_DEP)
53 if(len STREQUAL "2")
54 list(GET SPLIT_FILE 1 SPLIT_FILE)
55 if(EXISTS "${REACTOS_SOURCE_DIR}/sdk/include/psdk/${SPLIT_FILE}")
56 set(EXTRA_DEP ${REACTOS_SOURCE_DIR}/sdk/include/psdk/${SPLIT_FILE})
57 endif()
58 endif()
59 list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
60 add_custom_command(
61 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.h
62 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -p -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c -h -H ${NAME}_p.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
63 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} ${EXTRA_DEP} native-widl)
64 endforeach()
65
66 # Extra pass to generate dlldata
67 add_custom_command(
68 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
69 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} --dlldata-only -o ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c ${IDLS}
70 DEPENDS ${IDLS} native-widl)
71 endfunction()
72
73 function(add_rpc_files __type)
74 get_includes(INCLUDES)
75 get_defines(DEFINES)
76 # Is it a client or server module?
77 if(__type STREQUAL "server")
78 set(__server_client -Oif -s -o)
79 set(__suffix _s)
80 elseif(__type STREQUAL "client")
81 set(__server_client -Oif -c -o)
82 set(__suffix _c)
83 else()
84 message(FATAL_ERROR "Please pass either server or client as argument to add_rpc_files")
85 endif()
86 foreach(FILE ${ARGN})
87 get_filename_component(__name ${FILE} NAME_WE)
88 set(__name ${CMAKE_CURRENT_BINARY_DIR}/${__name}${__suffix})
89 if(NOT IS_ABSOLUTE ${FILE})
90 set(FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
91 endif()
92 add_custom_command(
93 OUTPUT ${__name}.c ${__name}.h
94 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -h -H ${__name}.h ${__server_client} ${__name}.c ${FILE}
95 DEPENDS ${FILE} native-widl)
96 endforeach()
97 endfunction()
98
99 function(generate_idl_iids)
100 foreach(IDL_FILE ${ARGN})
101 get_filename_component(FILE ${IDL_FILE} NAME)
102 if(FILE STREQUAL "${IDL_FILE}")
103 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
104 else()
105 set(IDL_FILE_FULL ${IDL_FILE})
106 endif()
107 get_includes(INCLUDES)
108 get_defines(DEFINES)
109 get_filename_component(NAME ${IDL_FILE} NAME_WE)
110 add_custom_command(
111 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c
112 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -u -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c ${IDL_FILE_FULL}
113 DEPENDS ${IDL_FILE_FULL} native-widl)
114 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c PROPERTIES GENERATED TRUE)
115 endforeach()
116 endfunction()
117
118 function(add_iid_library TARGET)
119 foreach(IDL_FILE ${ARGN})
120 get_filename_component(NAME ${IDL_FILE} NAME_WE)
121 generate_idl_iids(${IDL_FILE})
122 list(APPEND IID_SOURCES ${NAME}_i.c)
123 endforeach()
124 add_library(${TARGET} ${IID_SOURCES})
125 add_dependencies(${TARGET} psdk)
126 set_target_properties(${TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
127 endfunction()
128
129 function(add_idl_reg_script IDL_FILE)
130 get_filename_component(FILE ${IDL_FILE} NAME)
131 if(FILE STREQUAL "${IDL_FILE}")
132 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
133 else()
134 set(IDL_FILE_FULL ${IDL_FILE})
135 endif()
136 get_includes(INCLUDES)
137 get_defines(DEFINES)
138 get_filename_component(NAME ${IDL_FILE} NAME_WE)
139 add_custom_command(
140 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res
141 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -r -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res ${IDL_FILE_FULL}
142 DEPENDS ${IDL_FILE_FULL} native-widl)
143 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res PROPERTIES
144 GENERATED TRUE EXTERNAL_OBJECT TRUE)
145 endfunction()