FindSM.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #国密加解密库
  2. message(STATUS "***** Find SM Library *****")
  3. #寻找头文件
  4. find_path(SM_INCLUDE_DIR
  5. NAMES smclass.h
  6. PATHS ${CMAKE_CURRENT_LIST_DIR}/inc
  7. NO_DEFAULT_PATH
  8. )
  9. #查找源文件
  10. find_path(SM_SOURCE_DIR
  11. NAMES smclass.cpp
  12. PATHS ${CMAKE_CURRENT_LIST_DIR}/src
  13. NO_DEFAULT_PATH
  14. )
  15. #find_linrary查找的是“.lib”,“.a”,“.so”文件,不会查找.dll文件
  16. #因此,在这里无法使用,直接使用list添加路径
  17. # unset(SM_LIB CACHE)
  18. # find_library(SM_LIB
  19. # NAMES SM_DLL
  20. # HINTS ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64
  21. # NO_DEFAULT_PATH)
  22. # list(APPEND SM_LIB_LIBRARY ${SM_LIB})
  23. # message(STATUS "SM_LIB: ${SM_LIB}")
  24. #查找库文件,需要判断操作系统,位数
  25. if(CMAKE_SYSTEM_NAME MATCHES "Windows")
  26. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  27. if(CMAKE_BUILD_TYPE MATCHES "Debug")
  28. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/with_debug_info/libSM_DLL.lib)
  29. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/ucrtbased.dll)
  30. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/vcruntime140d.dll)
  31. else()
  32. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/libSM_DLL.lib)
  33. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/ucrtbase.dll)
  34. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/vcruntime140.dll)
  35. endif()
  36. elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
  37. if(CMAKE_BUILD_TYPE MATCHES "Debug")
  38. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/with_debug_info/libSM_DLL.lib)
  39. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/ucrtbased.dll)
  40. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/vcruntime140d.dll)
  41. else()
  42. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/libSM_DLL.lib)
  43. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/ucrtbase.dll)
  44. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/vcruntime140.dll)
  45. endif()
  46. endif()
  47. #添加Linux版本
  48. elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
  49. if(CMAKE_BUILD_TYPE MATCHES "Debug")
  50. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/linux/x64/libSM_Dll.so)
  51. else()
  52. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/linux/x64/libSM_Dll.so)
  53. endif()
  54. endif()
  55. # message(STATUS "SM_LIB_LIBRARY: ${SM_LIB_LIBRARY}")
  56. # message(STATUS "SM_INCLUDE_DIR: ${SM_INCLUDE_DIR}")
  57. # message(STATUS "SM_SOURCE_DIR: ${SM_SOURCE_DIR}")
  58. # message(STATUS "SM_LIB_LIBRARY: ${SM_LIB_LIBRARY}")
  59. #设置查找到后的变量
  60. if(SM_INCLUDE_DIR AND SM_SOURCE_DIR AND SM_LIB_LIBRARY)
  61. set(SM_FOUND TRUE)
  62. set(SM_VERSION "1.1.0")
  63. message(STATUS "include : SM_INCLUDE_DIR")
  64. message(STATUS "source : SM_SOURCE_DIR")
  65. message(STATUS "Library : SM_LIB_LIBRARY")
  66. else()
  67. set(SM_FOUND FALSE)
  68. endif()
  69. message(STATUS "---------------------------------")