Sync with trunk revision r58045 to bring the corrections on configure.cmd and on...
[reactos.git] / 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)
86 foreach(IDL_FILE ${ARGN})
87 get_filename_component(FILE ${IDL_FILE} NAME)
88 if(FILE STREQUAL "${IDL_FILE}")
89 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
90 else()
91 set(IDL_FILE_FULL ${IDL_FILE})
92 endif()
93 get_includes(INCLUDES)
94 get_defines(DEFINES)
95 get_filename_component(NAME ${IDL_FILE} NAME_WE)
96 add_custom_command(
97 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c
98 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -u -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c ${IDL_FILE_FULL}
99 DEPENDS ${IDL_FILE_FULL} native-widl)
100 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c PROPERTIES GENERATED TRUE)
101 endforeach()
102 endfunction()
103
104 function(add_iid_library TARGET)
105 foreach(IDL_FILE ${ARGN})
106 get_filename_component(NAME ${IDL_FILE} NAME_WE)
107 generate_idl_iids(${IDL_FILE})
108 list(APPEND IID_SOURCES ${NAME}_i.c)
109 endforeach()
110 add_library(${TARGET} ${IID_SOURCES})
111 add_dependencies(${TARGET} psdk)
112 set_target_properties(${TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
113 endfunction()
114
115 function(add_idl_reg_script IDL_FILE)
116 get_filename_component(FILE ${IDL_FILE} NAME)
117 if(FILE STREQUAL "${IDL_FILE}")
118 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
119 else()
120 set(IDL_FILE_FULL ${IDL_FILE})
121 endif()
122 get_includes(INCLUDES)
123 get_defines(DEFINES)
124 get_filename_component(NAME ${IDL_FILE} NAME_WE)
125 add_custom_command(
126 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res
127 COMMAND native-widl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} -r -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res ${IDL_FILE_FULL}
128 DEPENDS ${IDL_FILE_FULL} native-widl)
129 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_r.res PROPERTIES
130 GENERATED TRUE EXTERNAL_OBJECT TRUE)
131 endfunction()