FindGmsh.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # 防止重复引入
  2. if(Gmsh_ALREADY_INCLUDED)
  3. return()
  4. endif()
  5. set(Gmsh_ALREADY_INCLUDED 1)
  6. # find_path 搜索包含某个文件的路径
  7. # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
  8. find_path(Gmsh_DIRS
  9. NAMES
  10. include/gmsh.h
  11. PATHS
  12. ${CMAKE_SOURCE_DIR}/extlib/Gmsh
  13. NO_SYSTEM_ENVIRONMENT_PATH
  14. NO_CMAKE_SYSTEM_PATH
  15. )
  16. set(Gmsh_VERSION_MAJOR 4)
  17. set(Gmsh_VERSION_MINOR 11)
  18. set(Gmsh_VERSION_PATCH 1)
  19. set(Gmsh_VERSION "${Gmsh_VERSION_MAJOR}.${Gmsh_VERSION_MINOR}.${Gmsh_VERSION_PATCH}")
  20. find_path(Gmsh_INCLUDE_DIRS
  21. NAMES
  22. gmsh.h
  23. HINTS
  24. ${Gmsh_DIRS}/include
  25. )
  26. find_path(Gmsh_LIBRARY_DIRS
  27. NAMES
  28. gmsh.lib
  29. HINTS
  30. ${Gmsh_DIRS}/bin
  31. )
  32. find_path(Gmsh_BINARY_DIRS
  33. NAMES
  34. gmsh-4.12.dll
  35. HINTS
  36. ${Gmsh_DIRS}/bin
  37. )
  38. set(Gmsh_LIBRARIES GJDM::Gmsh)
  39. add_library(GJDM::Gmsh SHARED IMPORTED)
  40. set_property(TARGET GJDM::Gmsh PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Gmsh_INCLUDE_DIRS})
  41. set_property(TARGET GJDM::Gmsh APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  42. set_property(TARGET GJDM::Gmsh APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  43. set_target_properties(GJDM::Gmsh PROPERTIES
  44. IMPORTED_IMPLIB_DEBUG "${Gmsh_DIRS}/bin/gmsh.lib"
  45. IMPORTED_LOCATION_DEBUG "${Gmsh_DIRS}/bin/gmsh-4.12.dll"
  46. IMPORTED_IMPLIB_RELEASE "${Gmsh_DIRS}/bin/gmsh.lib"
  47. IMPORTED_LOCATION_RELEASE "${Gmsh_DIRS}/bin/gmsh-4.12.dll"
  48. )
  49. # if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  50. # set(Gmsh_EXECUTABLE "${Gmsh_DIRS}/bin/gmsh.exe")
  51. # else()
  52. # set(Gmsh_EXECUTABLE "${Gmsh_DIRS}/bin/gmsh")
  53. # endif()
  54. include(FindPackageHandleStandardArgs)
  55. # 如果找到所有需要的变量,并且版本匹配,则将Gmsh_FOUND变量设置为TRUE
  56. find_package_handle_standard_args(Gmsh
  57. FOUND_VAR
  58. Gmsh_FOUND
  59. REQUIRED_VARS
  60. Gmsh_DIRS
  61. Gmsh_INCLUDE_DIRS
  62. Gmsh_BINARY_DIRS
  63. Gmsh_LIBRARY_DIRS
  64. # Gmsh_EXECUTABLE
  65. Gmsh_LIBRARIES
  66. VERSION_VAR
  67. Gmsh_VERSION
  68. )