Salome HOME
750f0de78d245016fcbfd958c1828ef0f7c3638e
[tools/configuration.git] / cmake / FindSalomeMEDFile.cmake
1 # Copyright (C) 2013-2021  CEA/DEN, EDF R&D, OPEN CASCADE
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 # Author: Adrien Bruneton
20 #
21
22 # Medfile detection for Salome
23 #
24 #  !! Please read the generic detection procedure in SalomeMacros.cmake !!
25 #
26
27 SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(MEDFile MEDFILE_INCLUDE_DIRS 1)
28 #MARK_AS_ADVANCED()
29
30 SET(MED_INT_IS_LONG FALSE) # fallback value
31 IF(MEDFile_FOUND) 
32   SALOME_ACCUMULATE_HEADERS(MEDFILE_INCLUDE_DIRS)
33   SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${MEDFILE_LIBRARIES})
34
35   # Check size of med_int
36   SET(_med_int_cxx ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_med_int_size.cxx)
37   FILE(WRITE ${_med_int_cxx}
38        "#include <med.h>\n#include <stdio.h>\nint main(){printf(\"%d\", sizeof(med_int)); return 0;}")
39   TRY_RUN(_med_int_run_result _med_int_compile_results
40           ${CMAKE_BINARY_DIR} ${_med_int_cxx}
41           CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MEDFILE_INCLUDE_DIRS};${HDF5_INCLUDE_DIR}"
42           LINK_LIBRARIES ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES}
43           RUN_OUTPUT_VARIABLE _med_int_output)
44   IF(_med_int_compile_results)
45     SET(MED_INT_SIZE ${_med_int_output})
46   ELSE()
47     SET(MED_INT_SIZE UNKNOWN)
48   ENDIF()
49   IF(MED_INT_SIZE EQUAL 8)
50     SET(MED_INT_IS_LONG TRUE)
51   ELSE()
52     SET(MED_INT_IS_LONG FALSE)
53   ENDIF()
54   MESSAGE(STATUS "MEDFile: size of med_int is ${MED_INT_SIZE}")
55   UNSET(_med_int_cxx)
56   UNSET(_med_int_run_result)
57   UNSET(_med_int_compile_results)
58   UNSET(_med_int_output)
59 ENDIF()