ctkFunctionCMakeDoxygenFilterCompile.cmake 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #! \ingroup CMakeUtilities
  19. function(ctkFunctionCMakeDoxygenFilterCompile)
  20. #-------------------- parse function arguments -------------------
  21. set(DEFAULT_ARGS)
  22. set(prefix "FILTER")
  23. set(arg_names "OUT;NAMESPACE")
  24. set(option_names "")
  25. foreach(arg_name ${arg_names})
  26. set(${prefix}_${arg_name})
  27. endforeach()
  28. foreach(option ${option_names})
  29. set(${prefix}_${option} FALSE)
  30. endforeach()
  31. set(current_arg_name DEFAULT_ARGS)
  32. set(current_arg_list)
  33. foreach(arg ${ARGN})
  34. set(larg_names ${arg_names})
  35. list(FIND larg_names "${arg}" is_arg_name)
  36. if(is_arg_name GREATER -1)
  37. set(${prefix}_${current_arg_name} ${current_arg_list})
  38. set(current_arg_name "${arg}")
  39. set(current_arg_list)
  40. else()
  41. set(loption_names ${option_names})
  42. list(FIND loption_names "${arg}" is_option)
  43. if(is_option GREATER -1)
  44. set(${prefix}_${arg} TRUE)
  45. else()
  46. set(current_arg_list ${current_arg_list} "${arg}")
  47. endif()
  48. endif()
  49. endforeach()
  50. set(${prefix}_${current_arg_name} ${current_arg_list})
  51. #------------------- finished parsing arguments ----------------------
  52. if(FILTER_OUT)
  53. set(copy_file "${FILTER_OUT}")
  54. else()
  55. set(copy_file "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CMakeDoxygenFilter${CMAKE_EXECUTABLE_SUFFIX}")
  56. endif()
  57. set(compile_defs "")
  58. if(FILTER_NAMESPACE)
  59. set(compile_defs "${compile_defs} -DUSE_NAMESPACE=${FILTER_NAMESPACE}")
  60. endif()
  61. set(cmake_doxygen_filter_src "${CTK_SOURCE_DIR}/Documentation/CMakeDoxygenFilter.cpp")
  62. try_compile(result_var
  63. "${CMAKE_CURRENT_BINARY_DIR}"
  64. "${cmake_doxygen_filter_src}"
  65. COMPILE_DEFINITIONS ${compile_defs}
  66. OUTPUT_VARIABLE compile_output
  67. COPY_FILE ${copy_file}
  68. )
  69. if(NOT result_var)
  70. message(FATAL_ERROR "error: Faild to compile ${cmake_doxygen_filter_src} (result: ${result_var})\n${compile_output}")
  71. endif()
  72. set(CMakeDoxygenFilter_EXECUTABLE "${copy_file}" PARENT_SCOPE)
  73. endfunction()