fix: type of liba.version in Python2
[liba.git] / cmake / FindLDoc.cmake
blob604533bf2222df13450b4246c9b9db744dec54ff
1 #.rst:
2 # FindLDoc
3 # --------
5 # Find ldoc executable.
7 # Result Variables
8 # ^^^^^^^^^^^^^^^^
10 # This module defines the following variables:
12 # ``LDOC_FOUND``
14 # ``LDOC_EXECUTABLE``
16 # ``LDOC_VERSION``
18 # Functions
19 # ^^^^^^^^^
21 # .. command:: create_ldoc
23 #   ::
25 #     create_ldoc(target [QUIET] [VERBOSE]
26 #         [WORKING_DIRECTORY dir] [COMMENT comment] [CONFIG cfg]
27 #         [OPTIONS opt ...] [SOURCES src ...] [src ...]
28 #     )
30 include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
31 if(CMAKE_HOST_WIN32)
32   find_program(LDOC_EXECUTABLE NAMES ldoc ldoc.bat)
33 else()
34   find_program(LDOC_EXECUTABLE NAMES ldoc)
35 endif()
36 mark_as_advanced(LDOC_EXECUTABLE)
38 if(EXISTS "${LDOC_EXECUTABLE}")
39   execute_process(COMMAND ${LDOC_EXECUTABLE} OUTPUT_VARIABLE LDOC_VERSION ERROR_VARIABLE LDOC_VERSION)
40   string(REGEX REPLACE "[^0-9]+([^\n ]+).*" "\\1" LDOC_VERSION "${LDOC_VERSION}")
41 endif()
43 find_package_handle_standard_args(LDoc
44   FOUND_VAR
45     LDOC_FOUND
46   REQUIRED_VARS
47     LDOC_EXECUTABLE
48   VERSION_VAR
49     LDOC_VERSION
52 if(LDOC_FOUND)
53   function(create_ldoc target)
54     cmake_parse_arguments(LDOC "QUIET;VERBOSE" "WORKING_DIRECTORY;COMMENT;CONFIG" "OPTIONS;SOURCES" ${ARGN})
55     list(APPEND LDOC_SOURCES ${LDOC_UNPARSED_ARGUMENTS})
56     if(LDOC_QUIET)
57       list(INSERT LDOC_OPTIONS 0 --quiet)
58     endif()
59     if(LDOC_VERBOSE)
60       list(INSERT LDOC_OPTIONS 0 --verbose)
61     endif()
62     if(EXISTS "${LDOC_CONFIG}")
63       list(APPEND LDOC_OPTIONS -c ${LDOC_CONFIG})
64     endif()
65     if(NOT LDOC_WORKING_DIRECTORY)
66       set(LDOC_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
67     endif()
68     if(NOT LDOC_COMMENT)
69       set(LDOC_COMMENT "Generate API documentation for ${target}")
70     endif()
71     add_custom_target(${target} # https://stevedonovan.github.io/ldoc/manual/doc.md.html
72       COMMAND ${LDOC_EXECUTABLE} ${LDOC_OPTIONS} ${LDOC_SOURCES}
73       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
74       COMMENT "${LDOC_COMMENT}"
75     )
76   endfunction()
77 endif()