Salome HOME
8b41385f209ce7b0ba4bf069d4baab0d86f49fb0
[tools/medcoupling.git] / doc / developer / doxygen / CMakeLists.txt
1 # Copyright (C) 2012-2024  CEA, EDF
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # Set MEDCOUPLING_SERVER_BASED_SEARCH=ON when building docs for putting on www.salome-platform.org
21 # MEDCOUPLING_SERVER_BASED_SEARCH is used in Doxyfile
22 #
23 IF(MEDCOUPLING_SERVER_BASED_SEARCH)
24   SET(MEDCOUPLING_SERVER_BASED_SEARCH "YES")
25 ELSE()
26   SET(MEDCOUPLING_SERVER_BASED_SEARCH "NO")
27 ENDIF()
28
29 configure_file(Doxyfile.in Doxyfile @ONLY)
30 configure_file(static/header.html.in static/header.html @ONLY)
31
32
33 IF(NOT MEDCOUPLING_ENABLE_PYTHON)
34   ADD_CUSTOM_TARGET(doxygen
35     COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
36     VERBATIM
37     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
38   )
39 ELSE()
40   INCLUDE(doxy2swig/doxy2swig.cmake)
41
42   # >>>>>>>>>>>>>>>>
43   # For ease of maintenance, documentation for code examples is splitted in
44   # several files. We here splice to a single file before running Doxygen.
45
46   SET(EXAMPLE_FILES # files to concatenate: order is important!
47     doxfiles/examples/medcouplingexamplesheader.doxy
48     doxfiles/examples/medcouplingexamplesfields.doxy
49     doxfiles/examples/medcouplingexamplesmeshes.doxy
50     doxfiles/examples/medcouplingexamplesarrays.doxy
51     doxfiles/examples/medcouplingexamplesother.doxy
52     doxfiles/examples/medcouplingexamplesfooter.doxy
53     )
54
55   # This function adds IN_FILE contents to the end of OUT_FILE
56   FUNCTION(concat IN_FILE OUT_FILE)
57     FILE(READ ${IN_FILE} CONTENTS)
58     FILE(APPEND ${OUT_FILE} ${CONTENTS})
59   ENDFUNCTION()
60
61   FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/tmp/medcouplingexamples.in" input)
62   FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/BuildPyExamplesFromCPP.py" pythondocexamplesgenerator)
63   FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" output)
64
65   # Prepare a temporary file to "concat" to:
66   FILE(WRITE ${input} "")
67   # Call the "concat" function for each example file
68   FOREACH(EXAMPLE_FILE ${EXAMPLE_FILES})
69     concat(${EXAMPLE_FILE} ${input})
70   ENDFOREACH()
71   # Note: The reason for writing to a temporary is so the real target file only
72   # gets updated if its content has changed.
73   # <<<<<<<<<<<<<<<<
74
75   ADD_CUSTOM_TARGET(dev_docs ALL
76     COMMAND ${PYTHON_EXECUTABLE} ${pythondocexamplesgenerator} ${input} ${output}
77     COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
78     VERBATIM
79     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
80   )
81
82   # Create dummy target gathering the generation of all .i files:
83   ADD_CUSTOM_TARGET(swig_ready)
84   ADD_DEPENDENCIES(swig_ready dev_docs)
85
86   MEDCOUPLING_SWIG_DOCSTRING_CONFIGURE(dev_docs swig_ready MEDCoupling)
87   MEDCOUPLING_SWIG_DOCSTRING_CONFIGURE(dev_docs swig_ready MEDLoader)
88
89   SET(doxyfile_path ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
90   FILE(STRINGS ${doxyfile_path} enabled_sections REGEX "ENABLED_SECTIONS")
91   IF(enabled_sections)
92     FILE(READ ${doxyfile_path} doxyfile_content)
93     STRING(REPLACE ${enabled_sections} "${enabled_sections} ENABLE_EXAMPLES" new_doxyfile ${doxyfile_content})
94     FILE(WRITE ${doxyfile_path} ${new_doxyfile})
95   ELSE()
96     FILE(APPEND ${doxyfile_path}
97       "#Temporary variable to enable python documentation sections\nENABLED_SECTIONS = ENABLE_EXAMPLES")
98   ENDIF()
99
100   # Swig generation to have docstrings correctly populated:
101   INCLUDE(doxy2swig/doxy2swig.cmake)
102 ENDIF()
103
104 INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc_ref_dev/html/ DESTINATION ${MEDCOUPLING_INSTALL_DOC}/developer)
105
106 SET(MAKE_CLEAN_FILES doc_ref_dev tmp)
107 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MAKE_CLEAN_FILES}")