ctkFunctionCMakeDoxygenFilterCompile.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!
  2. #! \brief Compile a CMake doxygen input filter
  3. #!
  4. #! \param OUT <out-file> (optional) Supply an absolute filename for
  5. #! the generated executable.
  6. #! \param NAMESPACE <namespace> (optional) Supply a C++ namespace in
  7. #! which the generated function declrarations
  8. #! should be wrapped.
  9. #!
  10. #! \return This function sets the <code>CMakeDoxygenFilter_EXECUTABLE</code>
  11. #! variable to the absolute path of the generated input filter executable
  12. #! in the parent scope. If <out-file> is specified, they will be the same.
  13. #!
  14. #! This CMake function compiles the http://github.com/saschazelzer/CMakeDoxygenFilter
  15. #! project into a doxygen input filter executable. See
  16. #! http://github.com/saschazelzer/CMakeDoxygenFilter/blob/master/README for more details.
  17. #!
  18. function(ctkFunctionCMakeDoxygenFilterCompile)
  19. #-------------------- parse function arguments -------------------
  20. set(DEFAULT_ARGS)
  21. set(prefix "FILTER")
  22. set(arg_names "OUT;NAMESPACE")
  23. set(option_names "")
  24. foreach(arg_name ${arg_names})
  25. set(${prefix}_${arg_name})
  26. endforeach(arg_name)
  27. foreach(option ${option_names})
  28. set(${prefix}_${option} FALSE)
  29. endforeach(option)
  30. set(current_arg_name DEFAULT_ARGS)
  31. set(current_arg_list)
  32. foreach(arg ${ARGN})
  33. set(larg_names ${arg_names})
  34. list(FIND larg_names "${arg}" is_arg_name)
  35. if(is_arg_name GREATER -1)
  36. set(${prefix}_${current_arg_name} ${current_arg_list})
  37. set(current_arg_name "${arg}")
  38. set(current_arg_list)
  39. else(is_arg_name GREATER -1)
  40. set(loption_names ${option_names})
  41. list(FIND loption_names "${arg}" is_option)
  42. if(is_option GREATER -1)
  43. set(${prefix}_${arg} TRUE)
  44. else(is_option GREATER -1)
  45. set(current_arg_list ${current_arg_list} "${arg}")
  46. endif(is_option GREATER -1)
  47. endif(is_arg_name GREATER -1)
  48. endforeach(arg ${ARGN})
  49. set(${prefix}_${current_arg_name} ${current_arg_list})
  50. #------------------- finished parsing arguments ----------------------
  51. if(FILTER_OUT)
  52. set(copy_file "${FILTER_OUT}")
  53. else()
  54. set(copy_file "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CMakeDoxygenFilter${CMAKE_EXECUTABLE_SUFFIX}")
  55. endif()
  56. set(compile_defs "")
  57. if(FILTER_NAMESPACE)
  58. set(compile_defs "${compile_defs} -DUSE_NAMESPACE=${FILTER_NAMESPACE}")
  59. endif()
  60. set(cmake_doxygen_filter_src "${CTK_SOURCE_DIR}/Documentation/CMakeDoxygenFilter.cpp")
  61. try_compile(result_var
  62. "${CMAKE_CURRENT_BINARY_DIR}"
  63. "${cmake_doxygen_filter_src}"
  64. COMPILE_DEFINITIONS ${compile_defs}
  65. OUTPUT_VARIABLE compile_output
  66. COPY_FILE ${copy_file}
  67. )
  68. if(NOT result_var)
  69. message(FATAL_ERROR "error: Faild to compile ${cmake_doxygen_filter_src} (result: ${result_var})\n${compile_output}")
  70. endif()
  71. set(CMakeDoxygenFilter_EXECUTABLE "${copy_file}" PARENT_SCOPE)
  72. endfunction()