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 1)
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 IF(MEDCOUPLING_PARTITIONER_PARMETIS)
143 FIND_PACKAGE(SalomeParMetis)
144 SALOME_LOG_OPTIONAL_PACKAGE(ParMetis MEDCOUPLING_PARTITIONER_PARMETIS)
145 IF (SalomeParMetis_FOUND)
146 ADD_DEFINITIONS("-DMED_ENABLE_PARMETIS")
148 ENDIF(MEDCOUPLING_PARTITIONER_PARMETIS)
149 IF(MEDCOUPLING_PARTITIONER_PTSCOTCH)
150 FIND_PACKAGE(SalomePTScotch)
151 SALOME_LOG_OPTIONAL_PACKAGE(PTScotch MEDCOUPLING_PARTITIONER_PTSCOTCH)
152 IF(SalomePTScotch_FOUND)
153 ADD_DEFINITIONS("-DMED_ENABLE_PTSCOTCH")
154 ENDIF(SalomePTScotch_FOUND)
155 ENDIF(MEDCOUPLING_PARTITIONER_PTSCOTCH)
156 ENDIF(MEDCOUPLING_USE_MPI)
158 IF(MEDCOUPLING_ENABLE_RENUMBER)
159 FIND_PACKAGE(SalomeBoost)
160 SALOME_LOG_OPTIONAL_PACKAGE(Boost MEDCOUPLING_ENABLE_RENUMBER)
161 ENDIF(MEDCOUPLING_ENABLE_RENUMBER)
163 IF(MEDCOUPLING_ENABLE_PYTHON)
164 FIND_PACKAGE(SalomePythonInterp)
165 FIND_PACKAGE(SalomePythonLibs)
166 FIND_PACKAGE(SalomeNumPySciPy)
167 FIND_PACKAGE(SalomeSWIG)
168 SALOME_LOG_OPTIONAL_PACKAGE(PythonInterp MEDCOUPLING_ENABLE_PYTHON)
169 SALOME_LOG_OPTIONAL_PACKAGE(PythonLibs MEDCOUPLING_ENABLE_PYTHON)
170 SALOME_LOG_OPTIONAL_PACKAGE(SWIG MEDCOUPLING_ENABLE_PYTHON)
171 IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "2")
172 IF("${PYTHON_VERSION_MINOR}" LESS "7")
173 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")
176 IF ("${PYTHON_VERSION_MAJOR}" STREQUAL "3")
177 MESSAGE(STATUS "Using Python 3")
179 ENDIF(MEDCOUPLING_ENABLE_PYTHON)
181 IF(MEDCOUPLING_BUILD_DOC)
182 FIND_PACKAGE(SalomeDoxygen)
183 FIND_PACKAGE(SalomeGraphviz)
184 FIND_PACKAGE(SalomeSphinx)
185 SALOME_LOG_OPTIONAL_PACKAGE(Doxygen MEDCOUPLING_BUILD_DOC)
186 SALOME_LOG_OPTIONAL_PACKAGE(Graphviz MEDCOUPLING_BUILD_DOC)
187 SALOME_LOG_OPTIONAL_PACKAGE(Sphinx MEDCOUPLING_BUILD_DOC)
188 ENDIF(MEDCOUPLING_BUILD_DOC)
191 SALOME_PACKAGE_REPORT_AND_CHECK()
195 # Directories have to be given after prerequisites (to be able to use
196 # Python version string for example).
198 SET(MEDCOUPLING_INSTALL_BINS bin CACHE PATH "Install path: MEDCoupling binaries")
199 SET(MEDCOUPLING_INSTALL_LIBS lib CACHE PATH "Install path: MEDCoupling libs")
200 SET(MEDCOUPLING_INSTALL_HEADERS include CACHE PATH "Install path: MEDCoupling headers")
201 SET(MEDCOUPLING_INSTALL_SCRIPT_SCRIPTS ${MEDCOUPLING_INSTALL_BINS} CACHE PATH "Install path: MEDCoupling scripts")
202 SET(MEDCOUPLING_INSTALL_TESTS tests CACHE PATH "Install path: MEDCoupling tests")
203 # SET(MEDCOUPLING_INSTALL_SCRIPT_DATA ${MEDCOUPLING_INSTALL_BINS} CACHE PATH "Install path: MEDCoupling script data")
204 SET(MEDCOUPLING_INSTALL_SCRIPT_PYTHON ${MEDCOUPLING_INSTALL_BINS} CACHE PATH "Install path: MEDCoupling Python scripts")
205 SET(MEDCOUPLING_INSTALL_CMAKE_LOCAL cmake_files CACHE PATH "Install path: local MEDCoupling CMake files")
207 IF(MEDCOUPLING_ENABLE_PYTHON)
208 SET(_pydir lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
209 SET(MEDCOUPLING_INSTALL_PYTHON ${_pydir} CACHE PATH "Install path: MEDCoupling Python stuff")
210 SET(MEDCOUPLING_INSTALL_PYTHON_SHARED ${MEDCOUPLING_INSTALL_PYTHON}/shared_modules CACHE PATH
211 "Install path: MEDCoupling Python shared modules")
212 ENDIF(MEDCOUPLING_ENABLE_PYTHON)
214 SET(MEDCOUPLING_INSTALL_RES share/resources CACHE PATH "Install path: MEDCoupling resources")
215 SET(MEDCOUPLING_INSTALL_DOC share/doc CACHE PATH "Install path: MEDCoupling documentation")
219 SET(MEDCOUPLING_INSTALL_RES_DATA "${MEDCOUPLING_INSTALL_RES}/med" CACHE PATH "Install path: MEDCoupling specific data")
220 #SET(MEDCOUPLING_INSTALL_RES_SCRIPTS "${MEDCOUPLING_INSTALL_RES}/med" CACHE PATH "Install path: MEDCouplng specific scripts")
222 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_BINS MEDCOUPLING_INSTALL_LIBS MEDCOUPLING_INSTALL_IDLS MEDCOUPLING_INSTALL_HEADERS)
223 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_SCRIPT_SCRIPTS MEDCOUPLING_INSTALL_SCRIPT_DATA MEDCOUPLING_INSTALL_SCRIPT_PYTHON)
224 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_APPLISKEL_SCRIPTS MEDCOUPLING_INSTALL_APPLISKEL_PYTHON MEDCOUPLING_INSTALL_CMAKE MEDCOUPLING_INSTALL_CMAKE_LOCAL MEDCOUPLING_INSTALL_RES)
225 MARK_AS_ADVANCED(MEDCOUPLING_INSTALL_PYTHON MEDCOUPLING_INSTALL_PYTHON_SHARED MEDCOUPLING_INSTALL_RES_DATA MEDCOUPLING_INSTALL_DOC)
227 # Header configuration
228 # ====================
229 SALOME_XVERSION(${PROJECT_NAME})
230 SALOME_CONFIGURE_FILE(MEDCoupling_version.h.in MEDCoupling_version.h INSTALL ${MEDCOUPLING_INSTALL_HEADERS})
232 # Accumulate environment variables for MED module
233 #SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${MEDCOUPLING_INSTALL_BINS}
234 # ${CMAKE_INSTALL_PREFIX}/${MEDCOUPLING_INSTALL_PYTHON})
235 #SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${MEDCOUPLING_INSTALL_LIBS})
241 ADD_DEFINITIONS("-D_USE_MATH_DEFINES")
244 ADD_SUBDIRECTORY(src)
245 ADD_SUBDIRECTORY(adm_local)
247 IF(MEDCOUPLING_BUILD_DOC)
248 ADD_SUBDIRECTORY(doc)
249 ENDIF(MEDCOUPLING_BUILD_DOC)
251 ADD_SUBDIRECTORY(resources)
252 IF(MEDCOUPLING_ENABLE_PYTHON)
253 ADD_SUBDIRECTORY(v8_work)
256 # Configuration export
257 # ====================
258 INCLUDE(CMakePackageConfigHelpers)
260 # List of targets in this project we want to make visible to the rest of the world.
261 # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup"
262 SET(_${PROJECT_NAME}_exposed_targets
263 interpkernel medcouplingcpp medcouplingremapper)
265 IF(NOT MEDCOUPLING_MICROMED)
266 LIST(APPEND _${PROJECT_NAME}_exposed_targets medloader)
267 IF(MEDCOUPLING_ENABLE_RENUMBER)
268 LIST(APPEND _${PROJECT_NAME}_exposed_targets renumbercpp)
270 IF(MEDCOUPLING_ENABLE_PARTITIONER)
271 LIST(APPEND _${PROJECT_NAME}_exposed_targets medpartitionercpp)
272 IF(MEDCOUPLING_BUILD_TESTS)
273 LIST(APPEND _${PROJECT_NAME}_exposed_targets MEDPARTITIONERTest)
276 IF(MEDCOUPLING_BUILD_TESTS)
277 LIST(APPEND _${PROJECT_NAME}_exposed_targets InterpKernelTest InterpKernelTestUtils)
281 IF(MEDCOUPLING_USE_MPI)
282 LIST(APPEND _${PROJECT_NAME}_exposed_targets paramedmem)
283 IF(NOT MEDCOUPLING_MICROMED)
284 LIST(APPEND _${PROJECT_NAME}_exposed_targets paramedloader)
286 IF(MEDCOUPLING_BUILD_TESTS)
287 IF(NOT MEDCOUPLING_MICROMED)
288 LIST(APPEND _${PROJECT_NAME}_exposed_targets ParaMEDMEMTest)
293 # Add all targets to the build-tree export set
295 EXPORT(TARGETS ${_${PROJECT_NAME}_exposed_targets}
296 FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake)
298 # Create the configuration files:
300 # Ensure the variables are always defined for the configure (even if empty):
301 SET(MEDFILE_ROOT_DIR "${MEDFILE_ROOT_DIR}")
302 SET(MPI_ROOT_DIR "${MPI_ROOT_DIR}")
303 SET(BOOST_ROOT_DIR "${BOOST_ROOT_DIR}")
304 SET(SWIG_ROOT_DIR "${SWIG_ROOT_DIR}")
305 SET(PYTHON_ROOT_DIR "${PYTHON_ROOT_DIR}")
306 SET(CPPUNIT_ROOT_DIR "${CPPUNIT_ROOT_DIR}")
307 SET(GRAPHVIZ_ROOT_DIR "${GRAPHVIZ_ROOT_DIR}")
308 SET(DOXYGEN_ROOT_DIR "${DOXYGEN_ROOT_DIR}")
309 SET(SPHINX_ROOT_DIR "${SPHINX_ROOT_DIR}")
311 SET(METIS_ROOT_DIR "${METIS_ROOT_DIR}")
312 SET(PARMETIS_ROOT_DIR "${PARMETIS_ROOT_DIR}")
313 SET(SCOTCH_ROOT_DIR "${SCOTCH_ROOT_DIR}")
314 SET(XDR_ROOT_DIR "${XDR_ROOT_DIR}")
316 SET(CONF_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}")
318 # Build variables that will be expanded when configuring Salome<MODULE>Config.cmake:
319 SALOME_CONFIGURE_PREPARE(MEDFile MPI Boost Swig Python CppUnit Graphviz Doxygen Sphinx
320 Metis ParMetis Scotch XDR)
322 CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in
323 ${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake
324 INSTALL_DESTINATION "${MEDCOUPLING_INSTALL_CMAKE_LOCAL}"
325 PATH_VARS CONF_INCLUDE_DIRS MEDCOUPLING_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX
326 MEDFILE_ROOT_DIR MPI_ROOT_DIR
327 BOOST_ROOT_DIR SWIG_ROOT_DIR PYTHON_ROOT_DIR CPPUNIT_ROOT_DIR GRAPHVIZ_ROOT_DIR DOXYGEN_ROOT_DIR
329 METIS_ROOT_DIR PARMETIS_ROOT_DIR SCOTCH_ROOT_DIR XDR_ROOT_DIR)
331 WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
332 VERSION ${${PROJECT_NAME_UC}_VERSION}
333 COMPATIBILITY AnyNewerVersion)
335 # Install the CMake configuration files:
337 "${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake"
338 "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
339 DESTINATION "${MEDCOUPLING_INSTALL_CMAKE_LOCAL}")
341 # Install the export set for use with the install-tree
342 INSTALL(EXPORT ${PROJECT_NAME}TargetGroup DESTINATION "${MEDCOUPLING_INSTALL_CMAKE_LOCAL}"
343 FILE ${PROJECT_NAME}Targets.cmake)