Salome HOME
Update copyrights
[tools/medcoupling.git] / doc / developer / doxygen / doxy2swig / doxy2swig.cmake
1 # Copyright (C) 2012-2019  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 ##
21 ## This module is dedicated to the generation of specific SWIG files (".i") containing
22 ## the docstrings built from the C++ doxygen documentation.
23 ##
24
25 SET(_DOXY2SWIG ${PROJECT_SOURCE_DIR}/doc/developer/doxygen/doxy2swig/doxy2swig.py)
26
27 SET(_SWIG_DOC_SUFFIX "doc_class_")
28
29 #
30 # MEDCoupling classes to include
31 #
32 SET(_classes_MEDCoupling
33    MEDCoupling_1_1MEDCouplingPointSet
34    MEDCoupling_1_1MEDCouplingUMesh
35    MEDCoupling_1_1MEDCouplingCMesh
36    MEDCoupling_1_1MEDCouplingRemapper
37    MEDCoupling_1_1DataArray
38    #MEDCoupling_1_1DataArrayInt
39    MEDCoupling_1_1DataArrayDouble
40     )
41
42 #
43 # MEDLoader classes to include
44 #
45 SET(_classes_MEDLoader
46     MEDCoupling_1_1MEDFileMeshes
47     MEDCoupling_1_1MEDFileMesh
48     MEDCoupling_1_1MEDFileUMesh
49     MEDCoupling_1_1MEDFileCMesh
50     )
51
52 ##
53 ## Generates the ".i" files from a list of C++ classes.
54 ##
55 ## \param[in] target_doc main target for the stantard doxygen generation
56 ## \param[in] target_swig dummy target encompassing the final build of all SWIG files
57 ## \param[in] cls_list list of classes for which to generate SWIG files
58 ## \param[in] swig_main_file main SWIG file including the other generated SWIG files
59 ## \param[out] swig_files list of generated SWIG files
60 ##
61 MACRO(MEDCOUPLING_SWIG_DOCSTRING_GENERATE target_doc target_swig cls_list swig_main_file swig_files)
62     # List of generated SWIG files (.i) for doc purposes only:
63     SET(${swig_files})
64     FOREACH(_cls IN LISTS ${cls_list})
65       SET(_xml_file "${CMAKE_CURRENT_BINARY_DIR}/../doxygen/doc_ref_dev/xml/class${_cls}.xml")
66       SET(_swig_file_base "${_SWIG_DOC_SUFFIX}${_cls}.i")
67       SET(_swig_file "${PROJECT_BINARY_DIR}/doc/${_swig_file_base}" )
68
69       # SWIG doc files will always be generated *after* Doxygen is run:
70       ### WARNING: ADD_CUSTOM_COMMAND(TARGET xxx POST_BUILD ...) command
71       ### must be in exactly the same subdir as the initial target construction command.
72       ### That's why this file is included with an INCLUDE() rather than using ADD_SUBDIRECTORY
73       # Note: we touch the main .i file to be sure to retrigger swig when the doc in a included
74       # class changes.
75       ADD_CUSTOM_COMMAND(OUTPUT ${_swig_file}
76         COMMAND ${PYTHON_EXECUTABLE} ${_DOXY2SWIG} "-n" ${_xml_file} ${_swig_file}
77         COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${swig_main_file}
78         DEPENDS ${_xml_file}
79         COMMENT "Generating docstring SWIG file (from Doxygen's XML): ${_swig_file_base}"
80         VERBATIM
81       )
82       ADD_CUSTOM_TARGET(${_swig_file_base} DEPENDS ${_swig_file})
83       # The doxy2swig script is executed once the doxygen documentation has been generated ...
84       ADD_DEPENDENCIES(${_swig_file_base} ${target_doc})
85       # ... and the meta target 'swig_ready' (here ${target_swig}) is ready when all .i files
86       # have been generated:
87       ADD_DEPENDENCIES(${target_swig} ${_swig_file_base})
88
89       LIST(APPEND ${swig_files} ${_swig_file_base})
90     ENDFOREACH()
91 ENDMACRO(MEDCOUPLING_SWIG_DOCSTRING_GENERATE)
92
93
94 ##
95 ## Configures the MEDCoupling_doc.i or MEDLoader_doc.i file so that they include
96 ## the list of SWIG files generated by the macro above.
97 ##
98 ## \param[in] target_doc main target for the stantard doxygen generation
99 ## \param[in] target_swig dummy target encompassing the final build of all SWIG files
100 ## \param[in] root_name either 'MEDCoupling' or 'MEDLoader'
101 ##
102 MACRO(MEDCOUPLING_SWIG_DOCSTRING_CONFIGURE target_doc target_swig root_name)
103     SET(_all_swig_docs)
104     SET(_swig_include_set)
105     SET(_in_file doxy2swig/${root_name}_doc.i.in)
106     SET(_out_file ${PROJECT_BINARY_DIR}/doc/${root_name}_doc.i)
107     MEDCOUPLING_SWIG_DOCSTRING_GENERATE(${target_doc} ${target_swig} _classes_${root_name} ${_out_file} _all_swig_docs)
108     FOREACH(f IN LISTS _all_swig_docs)
109         SET(_swig_include_set "${_swig_include_set}\n%include \"${f}\"")
110     ENDFOREACH()
111     CONFIGURE_FILE(${_in_file} ${_out_file} @ONLY)
112 ENDMACRO(MEDCOUPLING_SWIG_DOCSTRING_CONFIGURE)