78f1b058bd632b771d2ec4c28e0c59563650343f
[reactos.git] / reactos / 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 get_filename_component(NAME ${FILE} NAME_WE)
16 add_custom_command(
17 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb
18 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -t -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
19 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} native-widl)
20 list(APPEND OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb)
21 endforeach()
22 endfunction()
23
24 function(add_idl_headers TARGET)
25 get_includes(INCLUDES)
26 get_defines(DEFINES)
27 foreach(FILE ${ARGN})
28 get_filename_component(NAME ${FILE} NAME_WE)
29 set(HEADER ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h)
30 add_custom_command(
31 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h
32 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -h -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
33 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} native-widl)
34 list(APPEND HEADERS ${HEADER})
35 endforeach()
36 add_custom_target(${TARGET} DEPENDS ${HEADERS})
37 endfunction()
38
39 function(add_rpcproxy_files)
40 get_includes(INCLUDES)
41 get_defines(DEFINES)
42
43 foreach(FILE ${ARGN})
44 get_filename_component(NAME ${FILE} NAME_WE)
45 list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
46 add_custom_command(
47 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.h
48 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}
49 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} native-widl)
50 endforeach()
51
52 # Extra pass to generate dlldata
53 add_custom_command(
54 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
55 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} --dlldata-only -o ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c ${IDLS}
56 DEPENDS ${IDLS} native-widl)
57 endfunction()
58
59 function(add_rpc_files __type)
60 get_includes(INCLUDES)
61 get_defines(DEFINES)
62 # Is it a client or server module?
63 if(__type STREQUAL "server")
64 set(__server_client -Oif -s -o)
65 set(__suffix _s)
66 elseif(__type STREQUAL "client")
67 set(__server_client -Oif -c -o)
68 set(__suffix _c)
69 else()
70 message(FATAL_ERROR "Please pass either server or client as argument to add_rpc_files")
71 endif()
72 foreach(FILE ${ARGN})
73 get_filename_component(__name ${FILE} NAME_WE)
74 set(__name ${CMAKE_CURRENT_BINARY_DIR}/${__name}${__suffix})
75 if(NOT IS_ABSOLUTE ${FILE})
76 set(FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
77 endif()
78 add_custom_command(
79 OUTPUT ${__name}.c ${__name}.h
80 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -h -H ${__name}.h ${__server_client} ${__name}.c ${FILE}
81 DEPENDS ${FILE} native-widl)
82 endforeach()
83 endfunction()
84
85 function(generate_idl_iids IDL_FILE)
86 get_filename_component(FILE ${IDL_FILE} NAME)
87 if(FILE STREQUAL "${IDL_FILE}")
88 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
89 else()
90 set(IDL_FILE_FULL ${IDL_FILE})
91 endif()
92 get_includes(INCLUDES)
93 get_defines(DEFINES)
94 get_filename_component(NAME ${IDL_FILE} NAME_WE)
95 add_custom_command(
96 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c
97 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -u -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c ${IDL_FILE_FULL}
98 DEPENDS ${IDL_FILE_FULL} native-widl)
99 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c PROPERTIES GENERATED TRUE)
100 endfunction()
101
102 function(add_iid_library TARGET)
103 foreach(IDL_FILE ${ARGN})
104 get_filename_component(NAME ${IDL_FILE} NAME_WE)
105 generate_idl_iids(${IDL_FILE})
106 list(APPEND IID_SOURCES ${NAME}_i.c)
107 endforeach()
108 add_library(${TARGET} ${IID_SOURCES})
109 add_dependencies(${TARGET} psdk)
110 set_target_properties(${TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
111 endfunction()
112
113 function(add_idl_reg_script IDL_FILE)
114 get_filename_component(FILE ${IDL_FILE} NAME)
115 if(FILE STREQUAL "${IDL_FILE}")
116 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
117 else()
118 set(IDL_FILE_FULL ${IDL_FILE})
119 endif()
120 get_includes(INCLUDES)
121 get_defines(DEFINES)
122 get_filename_component(NAME ${IDL_FILE} NAME_WE)
123 add_custom_command(
124 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res
125 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -r -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res ${IDL_FILE_FULL}
126 DEPENDS ${IDL_FILE_FULL} native-widl)
127 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res PROPERTIES
128 GENERATED TRUE EXTERNAL_OBJECT TRUE)
129 endfunction()