1 # Copyright (C) 2015-2016 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11 FATAL_ERROR)
21 #INCLUDE(CMakeDependentOption)
22 PROJECT(MEDCoupling C CXX)
24 # Ensure a proper linker behavior:
25 CMAKE_POLICY(SET CMP0003 NEW)
29 # Project name, upper case
30 STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC)
32 SET(${PROJECT_NAME_UC}_MAJOR_VERSION 9)
33 SET(${PROJECT_NAME_UC}_MINOR_VERSION 2)
34 SET(${PROJECT_NAME_UC}_PATCH_VERSION 0)
35 SET(${PROJECT_NAME_UC}_VERSION
36 ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
39 SET(CONFIGURATION_ROOT_DIR $ENV{CONFIGURATION_ROOT_DIR} CACHE PATH "Path to the Salome CMake files")
40 IF(EXISTS ${CONFIGURATION_ROOT_DIR})
41 LIST(APPEND CMAKE_MODULE_PATH "${CONFIGURATION_ROOT_DIR}/cmake")
44 MESSAGE(FATAL_ERROR "We absolutely need the Salome CMake configuration files, please define CONFIGURATION_ROOT_DIR !")
49 INCLUDE(SalomeSetupPlatform)
54 INCLUDE(CMakeDependentOption)
55 OPTION(MEDCOUPLING_MICROMED "Build MED without MED file dependency." OFF)
56 OPTION(MEDCOUPLING_ENABLE_PYTHON "Build PYTHON bindings." ON)
57 OPTION(MEDCOUPLING_ENABLE_PARTITIONER "Build MEDPartitioner." ON)
58 OPTION(MEDCOUPLING_ENABLE_RENUMBER "Build Renumber." ON)
59 OPTION(MEDCOUPLING_WITH_FILE_EXAMPLES "Install examples of files containing meshes and fields of different formats." ON)
60 OPTION(MEDCOUPLING_USE_MPI "(Use MPI containers) - For MED this triggers the build of ParaMEDMEM." OFF)
61 OPTION(MEDCOUPLING_BUILD_TESTS "Build MED tests." ON)
62 OPTION(MEDCOUPLING_BUILD_DOC "Build MED doc." ON)
63 OPTION(MEDCOUPLING_BUILD_STATIC "Build MEDCoupling library in static mode." OFF)
64 IF(${MEDCOUPLING_USE_MPI})
65 SET(USE_METIS_NOT_PARMETIS OFF)
67 SET(USE_METIS_NOT_PARMETIS ON)
69 CMAKE_DEPENDENT_OPTION(MEDCOUPLING_PARTITIONER_METIS "Enable metis graph library in MEDPartitioner." ${USE_METIS_NOT_PARMETIS}
70 "MEDCOUPLING_ENABLE_PARTITIONER" OFF)
71 CMAKE_DEPENDENT_OPTION(MEDCOUPLING_PARTITIONER_SCOTCH "Enable scotch graph library in MEDPartitioner." ON
72 "MEDCOUPLING_ENABLE_PARTITIONER" OFF)
73 CMAKE_DEPENDENT_OPTION(MEDCOUPLING_PARTITIONER_PARMETIS "Enable parmetis graph library in MEDPartitioner." ${MEDCOUPLING_USE_MPI}
74 "MEDCOUPLING_ENABLE_PARTITIONER;MEDCOUPLING_USE_MPI" OFF)
75 CMAKE_DEPENDENT_OPTION(MEDCOUPLING_PARTITIONER_PTSCOTCH "Enable ptscotch graph library in MEDPartitioner." ${MEDCOUPLING_USE_MPI}
76 "MEDCOUPLING_ENABLE_PARTITIONER;MEDCOUPLING_USE_MPI" OFF)
77 SET(XDR_DEFAULT_OPTION ON)
79 SET(XDR_DEFAULT_OPTION OFF)
81 CMAKE_DEPENDENT_OPTION(MEDCOUPLING_MEDLOADER_USE_XDR "Enable use of XDR for SauvReader." ${XDR_DEFAULT_OPTION} "NOT MEDCOUPLING_MICROMED" OFF)
82 CMAKE_DEPENDENT_OPTION(MEDCOUPLING_BUILD_FRENCH_DOC "Generate MEDCOUPLING French documentation" OFF
83 "MEDCOUPLING_BUILD_DOC" OFF)
85 IF(MEDCOUPLING_BUILD_STATIC)
86 SET(BUILD_SHARED_LIBS 0)
87 SET(CMAKE_POSITION_INDEPENDENT_CODE 1) # -fPIC option
89 SET(BUILD_SHARED_LIBS 1)
92 IF(${MEDCOUPLING_PARTITIONER_PARMETIS} AND ${MEDCOUPLING_PARTITIONER_METIS})
93 MESSAGE(FATAL_ERROR "ParMetis and Metis are mutually exclusive! Make a choice (options MEDCOUPLING_PARTITIONER_METIS and MEDCOUPLING_PARTITIONER_PARMETIS).")
96 IF(${MEDCOUPLING_PARTITIONER_PTSCOTCH} AND ${MEDCOUPLING_PARTITIONER_SCOTCH})
97 MESSAGE(FATAL_ERROR "PTScotch and Scotch are mutually exclusive! Make a choice (options MEDCOUPLING_PARTITIONER_SCOTCH and MEDCOUPLING_PARTITIONER_PTSCOTCH).")
101 # Set list of prerequisites
102 # =========================
104 IF(NOT MEDCOUPLING_MICROMED)
105 FIND_PACKAGE(SalomeHDF5 REQUIRED)
106 FIND_PACKAGE(SalomeMEDFile REQUIRED)
108 IF(MEDCOUPLING_MEDLOADER_USE_XDR)
109 FIND_PACKAGE(SalomeXDR REQUIRED)
110 ENDIF(MEDCOUPLING_MEDLOADER_USE_XDR)
112 IF(MEDCOUPLING_ENABLE_PARTITIONER)
113 FIND_PACKAGE(SalomeLibXml2)
114 SALOME_LOG_OPTIONAL_PACKAGE(LibXml2 MEDCOUPLING_ENABLE_PARTITIONER)
115 IF(MEDCOUPLING_PARTITIONER_METIS)
116 FIND_PACKAGE(SalomeMetis)
117 SALOME_LOG_OPTIONAL_PACKAGE(Metis MEDCOUPLING_PARTITIONER_METIS)
118 IF(SalomeMetis_FOUND)
119 ADD_DEFINITIONS("-DMED_ENABLE_METIS")
121 ENDIF(MEDCOUPLING_PARTITIONER_METIS)
122 IF(MEDCOUPLING_PARTITIONER_SCOTCH)
123 FIND_PACKAGE(SalomeScotch)
124 SALOME_LOG_OPTIONAL_PACKAGE(Scotch MEDCOUPLING_PARTITIONER_SCOTCH)
125 IF(SalomeScotch_FOUND)
126 ADD_DEFINITIONS("-DMED_ENABLE_SCOTCH")
128 ENDIF(MEDCOUPLING_PARTITIONER_SCOTCH)
129 ENDIF(MEDCOUPLING_ENABLE_PARTITIONER)
130 ENDIF(NOT MEDCOUPLING_MICROMED)
132 ENABLE_TESTING() # let it outsite because even if MEDCOUPLING_BUILD_TESTS is OFF, python tests that not need additional compilation can be run.
134 IF(MEDCOUPLING_BUILD_TESTS)
135 FIND_PACKAGE(SalomeCppUnit)
136 SALOME_LOG_OPTIONAL_PACKAGE(CppUnit SALOME_BUILD_TESTS)
137 ENDIF(MEDCOUPLING_BUILD_TESTS)
139 IF(MEDCOUPLING_USE_MPI)
140 FIND_PACKAGE(SalomeMPI REQUIRED)
141 ADD_DEFINITIONS("-DHAVE_MPI")
142 SALOME_ADD_MPI_TO_HDF5()
143 IF(MEDCOUPLING_PARTITIONER_PARMETIS)
144 FIND_PACKAGE(SalomeParMetis)
145 SALOME_LOG_OPTIONAL_PACKAGE(ParMetis MEDCOUPLING_PARTITIONER_PARMETIS)
146 IF (SalomeParMetis_FOUND)
147 ADD_DEFINITIONS("-DMED_ENABLE_PARMETIS")
149 ENDIF(MEDCOUPLING_PARTITIONER_PARMETIS)
150 IF(MEDCOUPLING_PARTITIONER_PTSCOTCH)
151 FIND_PACKAGE(SalomePTScotch)
152 SALOME_LOG_OPTIONAL_PACKAGE(PTScotch MEDCOUPLING_PARTITIONER_PTSCOTCH)
153 IF(SalomePTScotch_FOUND)
154 ADD_DEFINITIONS("-DMED_ENABLE_PTSCOTCH")
155 ENDIF(SalomePTScotch_FOUND)
156 ENDIF(MEDCOUPLING_PARTITIONER_PTSCOTCH)
157 ENDIF(MEDCOUPLING_USE_MPI)
159 IF(MEDCOUPLING_ENABLE_RENUMBER)
160 FIND_PACKAGE(SalomeBoost)
161 SALOME_LOG_OPTIONAL_PACKAGE(Boost MEDCOUPLING_ENABLE_RENUMBER)
162 ENDIF(MEDCOUPLING_ENABLE_RENUMBER)
164 IF(MEDCOUPLING_ENABLE_PYTHON)
165 FIND_PACKAGE(SalomePythonInterp)
166 FIND_PACKAGE(SalomePythonLibs)
167 FIND_PACKAGE(SalomeNumPySciPy)
168 FIND_PACKAGE(SalomeSWIG)
169 SALOME_LOG_OPTIONAL_PACKAGE(PythonInterp MEDCOUPLING_ENABLE_PYTHON)
170 SALOME_LOG_OPTIONAL_PACKAGE(PythonLibs MEDCOUPLING_ENABLE_PYTHON)
171 SALOME_LOG_OPTIONAL_PACKAGE(SWIG MEDCOUPLING_ENABLE_PYTHON)
172 IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "2")
173 IF("${PYTHON_VERSION_MINOR}" LESS "7")
174 MESSAGE(FATAL_ERROR "MEDCoupling's Python requires at least Python 2.7 (you seem to have ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}). Upgrade your Python, or turn off MEDCOUPLING_ENABLE_PYTHON")
177 IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
178 MESSAGE(STATUS "Using Python 3")
180 ENDIF(MEDCOUPLING_ENABLE_PYTHON)
182 IF(MEDCOUPLING_BUILD_DOC)
183 FIND_PACKAGE(SalomeDoxygen)
184 FIND_PACKAGE(SalomeGraphviz)
185 FIND_PACKAGE(SalomeSphinx)
186 SALOME_LOG_OPTIONAL_PACKAGE(Doxygen MEDCOUPLING_BUILD_DOC)
187 SALOME_LOG_OPTIONAL_PACKAGE(Graphviz MEDCOUPLING_BUILD_DOC)
188 SALOME_LOG_OPTIONAL_PACKAGE(Sphinx MEDCOUPLING_BUILD_DOC)
189 ENDIF(MEDCOUPLING_BUILD_DOC)
192 SALOME_PACKAGE_REPORT_AND_CHECK()
196 # Directories have to be given after prerequisites (to be able to use
197 # Python version string for example).
199 SET(MEDCOUPLING_INSTALL_BINS bin CACHE PATH "Install path: MEDCoupling binaries")
200 SET(MEDCOUPLING_INSTALL_LIBS lib CACHE PATH "Install path: MEDCoupling libs")
201 SET(MEDCOUPLING_INSTALL_HEADERS include CACHE PATH "Install path: MEDCoupling headers")
202 SET(MEDCOUPLING_INSTALL_SCRIPT_SCRIPTS ${MEDCOUPLING_INSTALL_BINS} CACHE PATH "Install path: MEDCoupling scripts")
203 SET(MEDCOUPLING_INSTALL_TESTS tests CACHE PATH "Install path: MEDCoupling tests")
204 # SET(MEDCOUPLING_INSTALL_SCRIPT_DATA ${MEDCOUPLING_INSTALL_BINS} CACHE PATH "Install path: MEDCoupling script data")
205 SET(MEDCOUPLING_INSTALL_SCRIPT_PYTHON ${MEDCOUPLING_INSTALL_BINS} CACHE PATH "Install path: MEDCoupling Python scripts")
206 SET(MEDCOUPLING_INSTALL_CMAKE_LOCAL cmake_files CACHE PATH "Install path: local MEDCoupling CMake files")
208 IF(MEDCOUPLING_ENABLE_PYTHON)
209 SET(_pydir lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
210 SET(MEDCOUPLING_INSTALL_PYTHON ${_pydir} CACHE PATH "Install path: MEDCoupling Python stuff")
211 SET(MEDCOUPLING_INSTALL_PYTHON_SHARED ${MEDCOUPLING_INSTALL_PYTHON}/shared_modules CACHE PATH
212 "Install path: MEDCoupling Python shared modules")
213 ENDIF(MEDCOUPLING_ENABLE_PYTHON)
215 SET(MEDCOUPLING_INSTALL_RES share/resources CACHE PATH "Install path: MEDCoupling resources")
216 SET(MEDCOUPLING_INSTALL_DOC share/doc CACHE PATH "Install path: MEDCoupling documentation")
220 SET(MEDCOUPLING_INSTALL_RES_DATA "${MEDCOUPLING_INSTALL_RES}/med" CACHE PATH "Install path: MEDCoupling specific data")
221 #SET(MEDCOUPLING_INSTALL_RES_SCRIPTS "${MEDCOUPLING_INSTALL_RES}/med" CACHE PATH "Install path: MEDCouplng specific scripts")
223 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_BINS MEDCOUPLING_INSTALL_LIBS MEDCOUPLING_INSTALL_IDLS MEDCOUPLING_INSTALL_HEADERS)
224 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_SCRIPT_SCRIPTS MEDCOUPLING_INSTALL_SCRIPT_DATA MEDCOUPLING_INSTALL_SCRIPT_PYTHON)
225 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_APPLISKEL_SCRIPTS MEDCOUPLING_INSTALL_APPLISKEL_PYTHON MEDCOUPLING_INSTALL_CMAKE MEDCOUPLING_INSTALL_CMAKE_LOCAL MEDCOUPLING_INSTALL_RES)
226 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_PYTHON MEDCOUPLING_INSTALL_PYTHON_SHARED MEDCOUPLING_INSTALL_RES_DATA MEDCOUPLING_INSTALL_DOC)
228 # Header configuration
229 # ====================
230 SALOME_XVERSION(${PROJECT_NAME})
231 SALOME_CONFIGURE_FILE(MEDCoupling_version.h.in MEDCoupling_version.h INSTALL ${MEDCOUPLING_INSTALL_HEADERS})
233 # Accumulate environment variables for MED module
234 #SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${MEDCOUPLING_INSTALL_BINS}
235 # ${CMAKE_INSTALL_PREFIX}/${MEDCOUPLING_INSTALL_PYTHON})
236 #SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${MEDCOUPLING_INSTALL_LIBS})
242 ADD_DEFINITIONS("-D_USE_MATH_DEFINES")
245 ADD_SUBDIRECTORY(src)
246 ADD_SUBDIRECTORY(adm_local)
248 IF(MEDCOUPLING_BUILD_DOC)
249 ADD_SUBDIRECTORY(doc)
250 ENDIF(MEDCOUPLING_BUILD_DOC)
252 ADD_SUBDIRECTORY(resources)
253 IF(MEDCOUPLING_ENABLE_PYTHON)
254 ADD_SUBDIRECTORY(v8_work)
257 # Configuration export
258 # ====================
259 INCLUDE(CMakePackageConfigHelpers)
261 # List of targets in this project we want to make visible to the rest of the world.
262 # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup"
263 SET(_${PROJECT_NAME}_exposed_targets
264 interpkernel medcouplingcpp medcouplingremapper)
266 IF(NOT MEDCOUPLING_MICROMED)
267 LIST(APPEND _${PROJECT_NAME}_exposed_targets medloader)
268 IF(MEDCOUPLING_ENABLE_RENUMBER)
269 LIST(APPEND _${PROJECT_NAME}_exposed_targets renumbercpp)
271 IF(MEDCOUPLING_ENABLE_PARTITIONER)
272 LIST(APPEND _${PROJECT_NAME}_exposed_targets medpartitionercpp)
273 IF(MEDCOUPLING_BUILD_TESTS)
274 LIST(APPEND _${PROJECT_NAME}_exposed_targets MEDPARTITIONERTest)
277 IF(MEDCOUPLING_BUILD_TESTS)
278 LIST(APPEND _${PROJECT_NAME}_exposed_targets InterpKernelTest InterpKernelTestUtils)
282 IF(MEDCOUPLING_USE_MPI)
283 LIST(APPEND _${PROJECT_NAME}_exposed_targets paramedmem)
284 IF(NOT MEDCOUPLING_MICROMED)
285 LIST(APPEND _${PROJECT_NAME}_exposed_targets paramedloader)
287 IF(MEDCOUPLING_BUILD_TESTS)
288 IF(NOT MEDCOUPLING_MICROMED)
289 LIST(APPEND _${PROJECT_NAME}_exposed_targets ParaMEDMEMTest)
294 # Add all targets to the build-tree export set
296 EXPORT(TARGETS ${_${PROJECT_NAME}_exposed_targets}
297 FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake)
299 # Create the configuration files:
301 # Ensure the variables are always defined for the configure (even if empty):
302 SET(MEDFILE_ROOT_DIR "${MEDFILE_ROOT_DIR}")
303 SET(MPI_ROOT_DIR "${MPI_ROOT_DIR}")
304 SET(BOOST_ROOT_DIR "${BOOST_ROOT_DIR}")
305 SET(SWIG_ROOT_DIR "${SWIG_ROOT_DIR}")
306 SET(PYTHON_ROOT_DIR "${PYTHON_ROOT_DIR}")
307 SET(CPPUNIT_ROOT_DIR "${CPPUNIT_ROOT_DIR}")
308 SET(GRAPHVIZ_ROOT_DIR "${GRAPHVIZ_ROOT_DIR}")
309 SET(DOXYGEN_ROOT_DIR "${DOXYGEN_ROOT_DIR}")
310 SET(SPHINX_ROOT_DIR "${SPHINX_ROOT_DIR}")
312 SET(METIS_ROOT_DIR "${METIS_ROOT_DIR}")
313 SET(PARMETIS_ROOT_DIR "${PARMETIS_ROOT_DIR}")
314 SET(SCOTCH_ROOT_DIR "${SCOTCH_ROOT_DIR}")
315 SET(XDR_ROOT_DIR "${XDR_ROOT_DIR}")
317 SET(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}")
319 # Build variables that will be expanded when configuring Salome<MODULE>Config.cmake:
320 SALOME_CONFIGURE_PREPARE(MEDFile MPI Boost Swig Python CppUnit Graphviz Doxygen Sphinx
321 Metis ParMetis Scotch XDR)
323 CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in
324 ${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake
325 INSTALL_DESTINATION "${MEDCOUPLING_INSTALL_CMAKE_LOCAL}"
326 PATH_VARS CONF_INCLUDE_DIRS MEDCOUPLING_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX
327 MEDFILE_ROOT_DIR MPI_ROOT_DIR
328 BOOST_ROOT_DIR SWIG_ROOT_DIR PYTHON_ROOT_DIR CPPUNIT_ROOT_DIR GRAPHVIZ_ROOT_DIR DOXYGEN_ROOT_DIR
330 METIS_ROOT_DIR PARMETIS_ROOT_DIR SCOTCH_ROOT_DIR XDR_ROOT_DIR)
332 WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
333 VERSION ${${PROJECT_NAME_UC}_VERSION}
334 COMPATIBILITY AnyNewerVersion)
336 # Install the CMake configuration files:
338 "${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake"
339 "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
340 DESTINATION "${MEDCOUPLING_INSTALL_CMAKE_LOCAL}")
342 # Install the export set for use with the install-tree
343 INSTALL(EXPORT ${PROJECT_NAME}TargetGroup DESTINATION "${MEDCOUPLING_INSTALL_CMAKE_LOCAL}"
344 FILE ${PROJECT_NAME}Targets.cmake)