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