-
Notifications
You must be signed in to change notification settings - Fork 5
/
FunctionCMakeDoxygenFilterCompile.cmake
100 lines (84 loc) · 3.7 KB
/
FunctionCMakeDoxygenFilterCompile.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!
#! \brief Download and compile a CMake doxygen input filter
#!
#! \param OUT <out-file> (optional) Supply an absolute filename for
#! the generated executable.
#! \param NAMESPACE <namespace> (optional) Supply a C++ namespace in
#! which the generated function declrarations
#! should be wrapped.
#!
#! \return This function sets the <code>CMakeDoxygenFilter_EXECUTABLE</code>
#! variable to the absolute path of the generated input filter executable
#! in the parent scope. If <out-file> is specified, they will be the same.
#!
#! This CMake function compiles the http://github.com/saschazelzer/CMakeDoxygenFilter
#! project into a doxygen input filter executable. See
#! http://github.com/saschazelzer/CMakeDoxygenFilter/blob/master/README for more details.
#!
function(FunctionCMakeDoxygenFilterCompile)
#-------------------- parse function arguments -------------------
set(DEFAULT_ARGS)
set(prefix "FILTER")
set(arg_names "OUT;NAMESPACE")
set(option_names "")
foreach(arg_name ${arg_names})
set(${prefix}_${arg_name})
endforeach(arg_name)
foreach(option ${option_names})
set(${prefix}_${option} FALSE)
endforeach(option)
set(current_arg_name DEFAULT_ARGS)
set(current_arg_list)
foreach(arg ${ARGN})
set(larg_names ${arg_names})
list(FIND larg_names "${arg}" is_arg_name)
if(is_arg_name GREATER -1)
set(${prefix}_${current_arg_name} ${current_arg_list})
set(current_arg_name "${arg}")
set(current_arg_list)
else(is_arg_name GREATER -1)
set(loption_names ${option_names})
list(FIND loption_names "${arg}" is_option)
if(is_option GREATER -1)
set(${prefix}_${arg} TRUE)
else(is_option GREATER -1)
set(current_arg_list ${current_arg_list} "${arg}")
endif(is_option GREATER -1)
endif(is_arg_name GREATER -1)
endforeach(arg ${ARGN})
set(${prefix}_${current_arg_name} ${current_arg_list})
#------------------- finished parsing arguments ----------------------
if(FILTER_OUT)
set(copy_file "${FILTER_OUT}")
else()
set(copy_file "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CMakeDoxygenFilter${CMAKE_EXECUTABLE_SUFFIX}")
endif()
set(compile_defs "")
if(FILTER_NAMESPACE)
set(compile_defs "${compile_defs} -DUSE_NAMESPACE=${FILTER_NAMESPACE}")
endif()
set(cmake_doxygen_filter_url "https://github.com/saschazelzer/CMakeDoxygenFilter/raw/master/CMakeDoxygenFilter.cpp")
set(cmake_doxygen_filter_src "${CMAKE_CURRENT_BINARY_DIR}/CMakeDoxygenFilter.cpp")
# If downloading on Windows fails with a "unsupported protocol" error, your CMake
# version is not build with SSL support. Either build CMake yourself with
# CMAKE_USE_OPENSSL enabled, or copy https://github.com/saschazelzer/CMakeDoxygenFilter/raw/master/CMakeDoxygenFilter.cpp
# into your repository and set cmake_doxygen_filter_src to your local copy
# and remove the download code below.
file(DOWNLOAD "${cmake_doxygen_filter_url}" "${cmake_doxygen_filter_src}" STATUS status)
list(GET status 0 error_code)
list(GET status 1 error_msg)
if(error_code)
message(FATAL_ERROR "error: Failed to download ${cmake_doxygen_filter_url} - ${error_msg}")
endif()
try_compile(result_var
"${CMAKE_CURRENT_BINARY_DIR}"
"${cmake_doxygen_filter_src}"
COMPILE_DEFINITIONS ${compile_defs}
OUTPUT_VARIABLE compile_output
COPY_FILE ${copy_file}
)
if(NOT result_var)
message(FATAL_ERROR "error: Faild to compile ${cmake_doxygen_filter_src} (result: ${result_var})\n${compile_output}")
endif()
set(CMakeDoxygenFilter_EXECUTABLE "${copy_file}" PARENT_SCOPE)
endfunction()