Salome HOME
2cfbf7bc9ac45784c8de856fc5c0d22c70f2a80c
[tools/medcoupling.git] / doc / user / doxygen / CMakeLists.txt
1 # Copyright (C) 2012-2015  CEA/DEN, EDF R&D
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 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile_med_user.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_med_user)
21 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/static/header.html.in ${CMAKE_CURRENT_BINARY_DIR}/static/header.html)
22
23 IF(MEDCOUPLING_MED_ENABLE_PYTHON)
24   INCLUDE(doxy2swig/doxy2swig.cmake)
25
26   FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/tmp/medcouplingexamples.in" input)
27   FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/BuildPyExamplesFromCPP.py" pythondocexamplesgenerator)
28   FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}" output)
29
30   # :TRICKY: For ease of maintenance, documentation for code examples is
31   # splitted in several files. We here splice to a single file before running
32   # Doxygen.
33
34   SET(EXAMPLE_FILES # files to concatenate: order is important!
35     doxfiles/examples/medcouplingexamplesheader.doxy
36     doxfiles/examples/medcouplingexamplesfields.doxy
37     doxfiles/examples/medcouplingexamplesmeshes.doxy
38     doxfiles/examples/medcouplingexamplesarrays.doxy
39     doxfiles/examples/medcouplingexamplesother.doxy
40     doxfiles/examples/medcouplingexamplesfooter.doxy
41   )
42
43   # This function adds IN_FILE contents to the end of OUT_FILE
44   FUNCTION(concat IN_FILE OUT_FILE)
45     FILE(READ ${IN_FILE} CONTENTS)
46     FILE(APPEND ${OUT_FILE} ${CONTENTS})
47   ENDFUNCTION()
48
49   # Prepare a temporary file to "concat" to:
50   FILE(WRITE ${input} "")
51   # Call the "concat" function for each example file
52   FOREACH(EXAMPLE_FILE ${EXAMPLE_FILES})
53     concat(${EXAMPLE_FILE} ${input})
54   ENDFOREACH()
55   # Note: The reason for writing to a temporary is so the real target file only
56   # gets updated if its content has changed.
57
58   # Here is the "standard" procedure, as if ${input} was hand-written.
59   ADD_CUSTOM_TARGET(usr_docs ALL
60     COMMAND ${PYTHON_EXECUTABLE} ${pythondocexamplesgenerator} ${input} ${output}
61     COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile_med_user
62     VERBATIM
63     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
64   )
65
66   # Create dummy target gathering the generation of all .i files:
67   ADD_CUSTOM_TARGET(swig_ready)
68   ADD_DEPENDENCIES(swig_ready usr_docs)
69
70   MEDCOUPLING_MED_SWIG_DOCSTRING_CONFIGURE(usr_docs swig_ready MEDCoupling)
71   MEDCOUPLING_MED_SWIG_DOCSTRING_CONFIGURE(usr_docs swig_ready MEDLoader)
72
73   SET(doxyfile_med_user ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_med_user)
74   FILE(STRINGS ${doxyfile_med_user} enabled_sections REGEX "ENABLED_SECTIONS")
75   IF(enabled_sections)
76     FILE(READ ${doxyfile_med_user} doxy_file)
77     STRING(REPLACE ${enabled_sections} "${enabled_sections} ENABLE_EXAMPLES" new_doxy_file ${doxy_file})
78     FILE(WRITE ${doxyfile_med_user} ${new_doxy_file})
79   ELSE()
80     FILE(APPEND ${doxyfile_med_user}
81       "#Temporary variable to enable python documentation sections\nENABLED_SECTIONS = ENABLE_EXAMPLES")
82   ENDIF()
83
84   # Swig generation to have docstrings correctly populated:
85   INCLUDE(doxy2swig/doxy2swig.cmake)
86
87 ELSE()
88   ADD_CUSTOM_TARGET(usr_docs ALL
89     COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile_med_user
90     VERBATIM
91     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
92   )
93 ENDIF()
94
95 #INSTALL(CODE "EXECUTE_PROCESS(COMMAND \"${CMAKE_COMMAND}\" --build ${PROJECT_BINARY_DIR} --target usr_docs)")
96 INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc_ref_user/html/ DESTINATION ${MEDCOUPLING_INSTALL_DOC})
97 INSTALL(FILES images/head.png DESTINATION ${MEDCOUPLING_INSTALL_DOC})
98
99 SET(MAKE_CLEAN_FILES doc_ref_user tmp)
100 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MAKE_CLEAN_FILES}")