FindCGNS.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # 防止重复引入
  2. if(GJDM_CGNS_ALREADY_INCLUDED)
  3. return()
  4. endif()
  5. set(GJDM_CGNS_ALREADY_INCLUDED 1)
  6. # find_path 搜索包含某个文件的路径
  7. # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
  8. find_path(CGNS_DIRS
  9. NAMES
  10. include/cgnslib.h
  11. PATHS
  12. ${CMAKE_SOURCE_DIR}/extlib/CGNS
  13. NO_SYSTEM_ENVIRONMENT_PATH
  14. NO_CMAKE_SYSTEM_PATH
  15. )
  16. set(CGNS_VERSION_MAJOR 4)
  17. set(CGNS_VERSION_MINOR 3)
  18. set(CGNS_VERSION_PATCH 0)
  19. set(CGNS_VERSION "${CGNS_VERSION_MAJOR}.${CGNS_VERSION_MINOR}.${CGNS_VERSION_PATCH}")
  20. find_path(CGNS_INCLUDE_DIRS
  21. NAMES
  22. cgnslib.h
  23. HINTS
  24. ${CGNS_DIRS}/include
  25. )
  26. find_path(CGNS_LIBRARY_DIRS
  27. NAMES
  28. cgnsdll.lib libcgns.so
  29. HINTS
  30. ${CGNS_DIRS}/lib
  31. )
  32. set(CGNS_LIBRARIES GJDM::CGNS)
  33. add_library(GJDM::CGNS SHARED IMPORTED)
  34. set_property(TARGET GJDM::CGNS PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CGNS_INCLUDE_DIRS})
  35. set_property(TARGET GJDM::CGNS APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  36. set_property(TARGET GJDM::CGNS PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  37. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  38. set_target_properties(GJDM::CGNS PROPERTIES
  39. IMPORTED_LOCATION_RELEASE "${CGNS_LIBRARY_DIRS}/libcgns.so.${CGNS_VERSION_MAJOR}.${CGNS_VERSION_MINOR}"
  40. IMPORTED_SONAME_RELEASE "libcgns.so"
  41. )
  42. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  43. set_target_properties(GJDM::CGNS PROPERTIES
  44. IMPORTED_IMPLIB_RELEASE "${CGNS_LIBRARY_DIRS}/cgnsdll.lib"
  45. IMPORTED_LOCATION_RELEASE "${CGNS_DIRS}/bin/cgnsdll.dll"
  46. )
  47. endif()
  48. include(FindPackageHandleStandardArgs)
  49. # 如果找到所有需要的变量,并且版本匹配,则将CGNS_FOUND变量设置为TRUE
  50. find_package_handle_standard_args(CGNS
  51. FOUND_VAR
  52. CGNS_FOUND
  53. REQUIRED_VARS
  54. CGNS_DIRS
  55. CGNS_INCLUDE_DIRS
  56. CGNS_LIBRARY_DIRS
  57. CGNS_LIBRARIES
  58. VERSION_VAR
  59. CGNS_VERSION
  60. )