forked from obsproject/obs-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIDLFileHelper.cmake
65 lines (55 loc) · 1.98 KB
/
IDLFileHelper.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
macro(add_idl_files generated_files)
foreach(filename ${ARGN})
get_filename_component(file_we ${filename} NAME_WE)
get_filename_component(file_path ${filename} PATH)
set(file_c ${file_we}_i.c)
set(file_h ${file_we}.h)
set(bin_file_h ${CMAKE_CURRENT_BINARY_DIR}/${file_h})
set(bin_file_c ${CMAKE_CURRENT_BINARY_DIR}/${file_c})
if(MSVC)
add_custom_command(
OUTPUT ${bin_file_h} ${bin_file_c}
DEPENDS ${filename}
COMMAND midl /h ${file_h} /iid ${file_c} /notlb ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else()
execute_process(COMMAND echo
COMMAND ${CMAKE_C_COMPILER} -v -x c++ -E -
ERROR_VARIABLE cpp_inc_output
OUTPUT_QUIET
ERROR_STRIP_TRAILING_WHITESPACE)
string(REPLACE ";" " " include_dirs ${cpp_inc_output})
string(REPLACE "\n" ";" include_dirs ${cpp_inc_output})
set(include_params)
foreach(include_dir ${include_dirs})
string(SUBSTRING ${include_dir} 0 1 first_char)
if(${first_char} STREQUAL " ")
string(LENGTH "${include_dir}" include_dir_len)
math(EXPR include_dir_len "${include_dir_len} - 1")
string(SUBSTRING ${include_dir} 1 ${include_dir_len} include_dir)
set(include_params "-I\"${include_dir}\" ${include_params}")
endif()
endforeach()
if(WIN32)
separate_arguments(include_params WINDOWS_COMMAND ${include_params})
endif()
add_custom_command(
OUTPUT ${file_h}
DEPENDS ${filename}
COMMAND ${CMAKE_WIDL} ${include_params} -h -o ${file_h} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
file(WRITE ${bin_file_c} "#include <initguid.h>\n#include <${file_h}>\n")
endif()
set_source_files_properties(
${bin_file_h}
${bin_file_c}
PROPERTIES
GENERATED TRUE)
set(${generated_files} ${${generated_file}}
${bin_file_h}
${bin_file_c})
set_source_files_properties(${filename}
PROPERTIES
HEADER_FILE_ONLY TRUE)
endforeach(filename ${ARGN})
endmacro(add_idl_files)