FindCGNS.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # FindCGNS
  2. # --------
  3. #
  4. # Find the CGNS libraries(Only for CGNS provided by FastCAE)
  5. #
  6. # Result Variables
  7. # ^^^^^^^^^^^^^^^^
  8. #
  9. # The following variables will be defined:
  10. #
  11. # ``CGNS_FOUND`` True if CGNS found on the local system
  12. #
  13. # ``CGNS_VERSION`` CGNS Version(x.x.x)
  14. #
  15. # ``CGNS_VERSION_MAJOR`` CGNS Major Version
  16. #
  17. # ``CGNS_VERSION_MINOR`` CGNS Minor Version
  18. #
  19. # ``CGNS_VERSION_PATCH`` CGNS Patch Version
  20. #
  21. # ``CGNS_DIRS`` Location of CGNS(root dir)
  22. #
  23. # ``CGNS_INCLUDE_DIRS`` Location of CGNS header files
  24. #
  25. # ``CGNS_LIBRARY_DIRS`` Location of CGNS libraries
  26. #
  27. # ``CGNS_LIBRARIES`` List of the CGNS libraries found
  28. #
  29. # 防止重复引入
  30. if(GJDM_CGNS_ALREADY_INCLUDED)
  31. return()
  32. endif()
  33. set(GJDM_CGNS_ALREADY_INCLUDED 1)
  34. # find_path 搜索包含某个文件的路径
  35. # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
  36. find_path(CGNS_DIRS
  37. NAMES
  38. include/cgnslib.h
  39. PATHS
  40. ${CMAKE_SOURCE_DIR}/extlib/CGNS
  41. NO_SYSTEM_ENVIRONMENT_PATH
  42. NO_CMAKE_SYSTEM_PATH
  43. )
  44. set(CGNS_VERSION_MAJOR 4)
  45. set(CGNS_VERSION_MINOR 3)
  46. set(CGNS_VERSION_PATCH 0)
  47. set(CGNS_VERSION "${CGNS_VERSION_MAJOR}.${CGNS_VERSION_MINOR}.${CGNS_VERSION_PATCH}")
  48. find_path(CGNS_INCLUDE_DIRS
  49. NAMES
  50. cgnslib.h
  51. HINTS
  52. ${CGNS_DIRS}/include
  53. )
  54. find_path(CGNS_LIBRARY_DIRS
  55. NAMES
  56. cgnsdll.lib libcgns.so
  57. HINTS
  58. ${CGNS_DIRS}/lib
  59. )
  60. set(CGNS_LIBRARIES GJDM::CGNS)
  61. add_library(GJDM::CGNS SHARED IMPORTED)
  62. set_property(TARGET GJDM::CGNS PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CGNS_INCLUDE_DIRS})
  63. set_property(TARGET GJDM::CGNS APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  64. set_property(TARGET GJDM::CGNS PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  65. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  66. set_target_properties(GJDM::CGNS PROPERTIES
  67. IMPORTED_LOCATION_RELEASE "${CGNS_LIBRARY_DIRS}/libcgns.so.${CGNS_VERSION_MAJOR}.${CGNS_VERSION_MINOR}"
  68. IMPORTED_SONAME_RELEASE "libcgns.so"
  69. )
  70. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  71. set_target_properties(GJDM::CGNS PROPERTIES
  72. IMPORTED_IMPLIB_RELEASE "${CGNS_LIBRARY_DIRS}/cgnsdll.lib"
  73. IMPORTED_LOCATION_RELEASE "${CGNS_DIRS}/bin/cgnsdll.dll"
  74. )
  75. endif()
  76. include(FindPackageHandleStandardArgs)
  77. # 如果找到所有需要的变量,并且版本匹配,则将CGNS_FOUND变量设置为TRUE
  78. find_package_handle_standard_args(CGNS
  79. FOUND_VAR
  80. CGNS_FOUND
  81. REQUIRED_VARS
  82. CGNS_DIRS
  83. CGNS_INCLUDE_DIRS
  84. CGNS_LIBRARY_DIRS
  85. CGNS_LIBRARIES
  86. VERSION_VAR
  87. CGNS_VERSION
  88. )