a627d0c7d6a67556718fadecaeab717b12da23d6
[reactos.git] / reactos / cmake / idl-support.cmake
1
2 #idl files support
3 if(MSVC)
4 set(IDL_COMPILER midl)
5 set(IDL_HEADER_ARG /h) #.h
6 set(IDL_HEADER_ARG2 /header) #.h
7 set(IDL_TYPELIB_ARG /tlb) #.tlb
8 set(IDL_SERVER_ARG /sstub) #.c for stub server library
9 set(IDL_CLIENT_ARG /cstub) #.c for stub client library
10 set(IDL_PROXY_ARG /proxy)
11 set(IDL_INTERFACE_ARG /iid)
12 if(ARCH MATCHES i386)
13 set(IDL_FLAGS /win32)
14 elseif(ARCH MATCHES amd64)
15 set(IDL_FLAGS /amd64)
16 else()
17 set(IDL_FLAGS "")
18 endif()
19 else()
20 set(IDL_COMPILER native-widl)
21 set(IDL_HEADER_ARG -h -o) #.h
22 set(IDL_HEADER_ARG2 -h -H) #.h
23 set(IDL_TYPELIB_ARG -t -o) #.tlb
24 set(IDL_SERVER_ARG -s -o) #.c for server library
25 set(IDL_CLIENT_ARG -c -o) #.c for stub client library
26 set(IDL_PROXY_ARG -p -o)
27 set(IDL_INTERFACE_ARG -u -o)
28 if(ARCH MATCHES i386)
29 set(IDL_FLAGS -m32 --win32)
30 elseif(ARCH MATCHES amd64)
31 set(IDL_FLAGS -m64 --win64)
32 else()
33 set(IDL_FLAGS "")
34 endif()
35 endif()
36
37
38 macro(get_includes OUTPUT_VAR)
39 set(${OUTPUT_VAR} "")
40 get_directory_property(_includes INCLUDE_DIRECTORIES)
41 foreach(arg ${_includes})
42 set(${OUTPUT_VAR} -I${arg} ${${OUTPUT_VAR}})
43 endforeach()
44 endmacro()
45
46 macro(get_defines OUTPUT_VAR)
47 set(${OUTPUT_VAR} "")
48 get_directory_property(_defines COMPILE_DEFINITIONS)
49 foreach(arg ${_defines})
50 set(${OUTPUT_VAR} ${${OUTPUT_VAR}} -D${arg})
51 endforeach()
52 endmacro()
53
54 macro(add_typelib TARGET)
55 get_includes(INCLUDES)
56 get_defines(DEFINES)
57 foreach(FILE ${ARGN})
58 get_filename_component(NAME ${FILE} NAME_WE)
59 add_custom_command(
60 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb
61 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_TYPELIB_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
62 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
63 list(APPEND OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.tlb)
64 endforeach()
65 add_custom_target(${TARGET} ALL DEPENDS ${OBJECTS})
66 endmacro()
67
68 macro(add_idl_headers TARGET)
69 get_includes(INCLUDES)
70 get_defines(DEFINES)
71 foreach(FILE ${ARGN})
72 get_filename_component(NAME ${FILE} NAME_WE)
73 set(HEADER ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h)
74 add_custom_command(
75 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h
76 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_HEADER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
77 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
78 list(APPEND HEADERS ${HEADER})
79 endforeach()
80 add_custom_target(${TARGET} ALL DEPENDS ${HEADERS})
81 endmacro()
82
83 macro(add_rpcproxy_files)
84 get_includes(INCLUDES)
85 get_defines(DEFINES)
86
87 if(MSVC)
88 set(DLLDATA_ARG /dlldata ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c)
89 endif()
90 foreach(FILE ${ARGN})
91 get_filename_component(NAME ${FILE} NAME_WE)
92 if(NOT MSVC)
93 list(APPEND IDLS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
94 endif()
95 add_custom_command(
96 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c
97 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_PROXY_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_p.c ${IDL_HEADER_ARG2} ${NAME}_p.h ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} ${DLLDATA_ARG}
98 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
99 endforeach()
100
101 # Extra pass to generate dlldata
102 if(MSVC)
103 #nobody told how to generate it, so mark it as generated
104 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c PROPERTIES GENERATED TRUE)
105 else()
106 add_custom_command(
107 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
108 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} --dlldata-only -o ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c ${IDLS}
109 DEPENDS ${IDLS})
110 endif()
111 endmacro()
112
113 macro(add_rpc_library TARGET)
114 get_includes(INCLUDES)
115 get_defines(DEFINES)
116 foreach(FILE ${ARGN})
117 get_filename_component(NAME ${FILE} NAME_WE)
118 add_custom_command(
119 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_s.c
120 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_HEADER_ARG2} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_s.h ${IDL_SERVER_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_s.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
121 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
122 list(APPEND server_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_s.c)
123
124 add_custom_command(
125 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_c.c
126 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_HEADER_ARG2} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_c.h ${IDL_CLIENT_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_c.c ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
127 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
128 list(APPEND client_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_c.c)
129 endforeach()
130 add_library(${TARGET} ${server_SOURCES} ${client_SOURCES})
131 add_dependencies(${TARGET} psdk)
132 endmacro()
133
134 macro(generate_idl_iids IDL_FILE)
135 get_filename_component(FILE ${IDL_FILE} NAME)
136 if(FILE STREQUAL "${IDL_FILE}")
137 set(IDL_FILE_FULL "${CMAKE_CURRENT_SOURCE_DIR}/${IDL_FILE}")
138 else()
139 set(IDL_FILE_FULL ${IDL_FILE})
140 endif()
141 get_includes(INCLUDES)
142 get_defines(DEFINES)
143 get_filename_component(NAME ${IDL_FILE} NAME_WE)
144 add_custom_command(
145 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c
146 COMMAND ${IDL_COMPILER} ${INCLUDES} ${DEFINES} ${IDL_FLAGS} ${IDL_INTERFACE_ARG} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c ${IDL_FILE_FULL}
147 DEPENDS ${IDL_FILE_FULL})
148 set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${NAME}_i.c PROPERTIES GENERATED TRUE)
149 endmacro()
150
151 macro(add_iid_library TARGET)
152 foreach(IDL_FILE ${ARGN})
153 get_filename_component(NAME ${IDL_FILE} NAME_WE)
154 generate_idl_iids(${IDL_FILE})
155 list(APPEND IID_SOURCES ${NAME}_i.c)
156 endforeach()
157 add_library(${TARGET} ${IID_SOURCES})
158 add_dependencies(${TARGET} psdk)
159 endmacro()