Salome HOME
Update MEDReader for python wrapping
[modules/paravis.git] / src / Plugins / MEDReader / CMakeLists.txt
1 # Copyright (C) 2010-2022  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 cmake_minimum_required(VERSION 3.8)
21 project(MEDReader)
22
23 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
24 option(MEDREADER_USE_MPI "Activate parallel reading for MEDREADER" OFF)
25
26 find_package(ParaView REQUIRED)
27 if(MEDREADER_USE_MPI)
28   add_definitions(-DMEDREADER_USE_MPI)
29 endif(MEDREADER_USE_MPI)
30
31 enable_testing()
32
33 include(GNUInstallDirs)
34 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
35 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
36 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
37
38 set("_paraview_plugin_default_${CMAKE_PROJECT_NAME}" ON)
39 paraview_plugin_scan(
40   ENABLE_BY_DEFAULT YES
41   PLUGIN_FILES      "${CMAKE_CURRENT_SOURCE_DIR}/plugin/paraview.plugin"
42   PROVIDES_PLUGINS  plugins
43   REQUIRES_MODULES  required_modules)
44
45 foreach (module IN LISTS required_modules)
46   if (NOT TARGET "${module}")
47     message("Missing required module: ${module}")
48     return ()
49   endif ()
50 endforeach ()
51
52 paraview_plugin_build(
53   RUNTIME_DESTINATION "${CMAKE_INSTALL_BINDIR}"
54   LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}"
55   LIBRARY_SUBDIRECTORY "${PARAVIEW_PLUGIN_SUBDIR}"
56   PLUGINS ${plugins})
57
58 if(TARGET VTK::Python)
59
60   vtk_module_python_default_destination(python_destination)
61
62   vtk_module_wrap_python(
63     MODULES         MEDReaderIO
64     WRAPPED_MODULES medr_wrapped_modules
65     TARGET          MEDREADER::Python
66     INSTALL_EXPORT  MEDReaderVTKPython
67     PYTHON_PACKAGE  "MEDReaderVTK"
68     MODULE_DESTINATION  "${python_destination}"
69     CMAKE_DESTINATION   "${CMAKE_INSTALL_LIBDIR}/cmake/MEDReaderVTKPython"
70     LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}"
71     INSTALL_HEADERS ON
72     BUILD_STATIC    OFF)
73
74   # Generate __init__.py
75   set(python_modules)
76   foreach(module ${medr_wrapped_modules})
77     list(APPEND python_modules "'${module}'")
78   endforeach()
79
80   set(InitContent "__all__ = ['vtkMEDReader']")
81
82   file(GENERATE
83     OUTPUT  "${CMAKE_BINARY_DIR}/${python_destination}/MEDReaderVTK/__init__.py"
84     CONTENT "${InitContent}")
85   install(
86     FILES       "${CMAKE_BINARY_DIR}/${python_destination}/MEDReaderVTK/__init__.py"
87     DESTINATION "${python_destination}/MEDReaderVTK/")
88
89   # Install MEDReaderVTKPython
90   export(
91     EXPORT    MEDReaderVTKPython
92     NAMESPACE MEDREADER::
93     FILE "${CMAKE_BINARY_DIR}/${python_destination}/MEDReaderVTKPython/MEDReaderVTKPython-targets.cmake")
94   install(
95     EXPORT    MEDReaderVTKPython
96     NAMESPACE MEDREADER::
97     FILE      MEDReaderVTKPython-targets.cmake
98     DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/MEDReaderVTKPython")
99
100 endif()