FindGmsh.cmake
Go to the documentation of this file.
1 # - Find Gmsh library
2 # Find the Gmsh includes and library
3 # This module defines
4 # Gmsh_INCLUDE_DIRS: where to find GmshGlobal.h
5 # Gmsh_LIBRARIES: the Gmsh library
6 # Gmsh_FOUND: if false, do not try to use Gmsh
7 # Gmsh_VERSION: The found version of Gmsh
8 # Gmsh::Gmsh: Imported target for the Gmsh library
9 
10 find_path(Gmsh_INCLUDE_DIR
11  NAMES
12  gmsh.h
13  PATHS
14  /usr/local/include
15  /usr/include
16  DOC "Gmsh include directory")
17 mark_as_advanced(Gmsh_INCLUDE_DIR)
18 
19 find_library(Gmsh_LIBRARY
20  NAMES
21  gmsh libgmsh
22  DOC "Gmsh library path")
23 mark_as_advanced(Gmsh_LIBRARY)
24 
25 if (Gmsh_INCLUDE_DIR)
26  if (EXISTS "${Gmsh_INCLUDE_DIR}/gmsh.h")
27  file(STRINGS "${Gmsh_INCLUDE_DIR}/gmsh.h" _gmsh_version
28  REGEX "GMSH_")
29  string(REGEX REPLACE ".*GMSH_API_VERSION_MAJOR *\([0-9]*\).*" "\\1" _gmsh_major "${_gmsh_version}")
30  string(REGEX REPLACE ".*GMSH_API_VERSION_MINOR *\([0-9]*\).*" "\\1" _gmsh_minor "${_gmsh_version}")
31  string(REGEX REPLACE ".*GMSH_API_VERSION_PATCH *\([0-9]*\).*" "\\1" _gmsh_patch "${_gmsh_version}")
32  unset(_gmsh_version)
33  if (NOT _gmsh_major STREQUAL "" AND
34  NOT _gmsh_minor STREQUAL "" AND
35  NOT _gmsh_patch STREQUAL "")
36  set(Gmsh_VERSION "${_gmsh_major}.${_gmsh_minor}.${_gmsh_patch}")
37  endif ()
38  unset(_gmsh_major)
39  unset(_gmsh_minor)
40  unset(_gmsh_patch)
41  else ()
42  set(Gmsh_VERSION Gmsh_VERSION-NOTFOUND)
43  endif ()
44 endif ()
45 
46 include(FindPackageHandleStandardArgs)
47 find_package_handle_standard_args(Gmsh
48  REQUIRED_VARS Gmsh_LIBRARY Gmsh_INCLUDE_DIR
49  VERSION_VAR Gmsh_VERSION)
50 
51 if (Gmsh_FOUND)
52  set(Gmsh_LIBRARIES "${Gmsh_LIBRARY}")
53  set(Gmsh_INCLUDE_DIRS "${Gmsh_INCLUDE_DIR}")
54  if (NOT TARGET Gmsh::Gmsh)
55  add_library(Gmsh::Gmsh UNKNOWN IMPORTED)
56  set_target_properties(Gmsh::Gmsh
57  PROPERTIES
58  IMPORTED_LOCATION "${Gmsh_LIBRARY}"
59  INTERFACE_INCLUDE_DIRECTORIES "${Gmsh_INCLUDE_DIR}")
60  endif ()
61 endif ()
string