[CMAKE]
[reactos.git] / reactos / cmake / widl-support.cmake
1
2 #idl files support
3 set(IDL_COMPILER native-widl)
4 set(IDL_HEADER_ARG -h -o) #.h
5 set(IDL_HEADER_ARG2 -h -H) #.h
6 set(IDL_TYPELIB_ARG -t -o) #.tlb
7 set(IDL_SERVER_ARG -Oif -s -o) #.c for server library
8 set(IDL_CLIENT_ARG -Oif -c -o) #.c for stub client library
9 set(IDL_PROXY_ARG -p -o)
10 set(IDL_INTERFACE_ARG -u -o)
11 if(ARCH MATCHES i386)
12 set(IDL_FLAGS -m32 --win32)
13 elseif(ARCH MATCHES amd64)
14 set(IDL_FLAGS -m64 --win64)
15 else()
16 set(IDL_FLAGS "")
17 endif()
18 set(IDL_DEPENDS native-widl)
19
20 function(add_typelib)
21 get_includes(INCLUDES)
22 get_defines(DEFINES)
23 foreach(FILE ${ARGN})
24 get_filename_component(NAME ${FILE} NAME_WE)
25 add_custom_command(
26 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb
27 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_TYPELIB_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
28 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} ${IDL_DEPENDS})
29 list(APPEND OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb)
30 endforeach()
31 endfunction()
32
33 function(add_idl_headers TARGET)
34 get_includes(INCLUDES)
35 get_defines(DEFINES)
36 foreach(FILE ${ARGN})
37 get_filename_component(NAME ${FILE} NAME_WE)
38 set(HEADER ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h)
39 add_custom_command(
40 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h
41 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
42 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} ${IDL_DEPENDS})
43 list(APPEND HEADERS ${HEADER})
44 endforeach()
45 add_custom_target(${TARGET} DEPENDS ${HEADERS})
46 endfunction()
47
48 function(add_rpcproxy_files)
49 get_includes(INCLUDES)
50 get_defines(DEFINES)
51
52 if(MSVC)
53 set(DLLDATA_ARG /dlldata ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c)
54 set(OUTPUT_FILES "")
55 endif()
56 foreach(FILE ${ARGN})
57 get_filename_component(NAME ${FILE} NAME_WE)
58 if(MSVC)
59 add_custom_command(
60 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.h ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
61 COMMAND midl ${INCLUDES} ${DEFINES} ${IDL_FLAGS} /proxy ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c /h ${NAME}_p.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} /dlldata ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
62 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} ${OUTPUT_FILES})
63 list(APPEND OUTPUT_FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c)
64 list(APPEND OUTPUT_FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.h)
65 else()
66 list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
67 add_custom_command(
68 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.h
69 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}
70 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} native-widl)
71 endif()
72 endforeach()
73
74 # Extra pass to generate dlldata
75 if(MSVC)
76 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES GENERATED TRUE)
77 else()
78 add_custom_command(
79 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
80 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} --dlldata-only -o ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c ${IDLS}
81 DEPENDS ${IDLS} ${IDL_DEPENDS})
82 endif()
83 endfunction()
84
85 function(add_rpc_files __type)
86 get_includes(INCLUDES)
87 get_defines(DEFINES)
88 # Is it a client or server module?
89 if(__type STREQUAL server)
90 set(__server_client ${IDL_SERVER_ARG})
91 set(__suffix _s)
92 elseif(__type STREQUAL client)
93 set(__server_client ${IDL_CLIENT_ARG})
94 set(__suffix _c)
95 else()
96 message(FATAL_ERROR "Please pass either server or client as argument to add_rpc_files")
97 endif()
98 foreach(FILE ${ARGN})
99 get_filename_component(__name ${FILE} NAME_WE)
100 set(__name ${__name}${__suffix})
101 if(NOT IS_ABSOLUTE ${FILE})
102 set(FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
103 endif()
104 add_custom_command(
105 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${__name}.c ${CMAKE_CURRENT_BINARY_DIR}/${__name}.h
106 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_HEADER_ARG2} ${CMAKE_CURRENT_BINARY_DIR}/${__name}.h ${__server_client} ${CMAKE_CURRENT_BINARY_DIR}/${__name}.c ${FILE}
107 DEPENDS ${FILE} ${IDL_DEPENDS})
108 endforeach()
109 endfunction()
110
111 function(generate_idl_iids IDL_FILE)
112 get_filename_component(FILE ${IDL_FILE} NAME)
113 if(FILE STREQUAL "${IDL_FILE}")
114 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
115 else()
116 set(IDL_FILE_FULL ${IDL_FILE})
117 endif()
118 get_includes(INCLUDES)
119 get_defines(DEFINES)
120 get_filename_component(NAME ${IDL_FILE} NAME_WE)
121 add_custom_command(
122 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c
123 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_INTERFACE_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c ${IDL_FILE_FULL}
124 DEPENDS ${IDL_FILE_FULL} ${IDL_DEPENDS})
125 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c PROPERTIES GENERATED TRUE)
126 endfunction()
127
128 function(add_iid_library TARGET)
129 foreach(IDL_FILE ${ARGN})
130 get_filename_component(NAME ${IDL_FILE} NAME_WE)
131 generate_idl_iids(${IDL_FILE})
132 list(APPEND IID_SOURCES ${NAME}_i.c)
133 endforeach()
134 add_library(${TARGET} ${IID_SOURCES})
135 add_dependencies(${TARGET} psdk)
136 set_target_properties(${TARGET} PROPERTIES EXCLUDE_FROM_ALL TRUE)
137 endfunction()