FindSM.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #国密加解密库
  2. message(STATUS "***** Find SM Library *****")
  3. #寻找头文件
  4. unset(SM_INCLUDE_DIR CACHE)
  5. find_path(SM_INCLUDE_DIR
  6. NAMES smclass.h
  7. PATHS ${CMAKE_CURRENT_LIST_DIR}/inc
  8. NO_DEFAULT_PATH
  9. )
  10. #查找源文件
  11. # find_path(SM_SOURCES_DIR
  12. # NAMES smclass.cpp
  13. # PATHS ${CMAKE_CURRENT_LIST_DIR}/src
  14. # NO_DEFAULT_PATH
  15. # )
  16. unset(SM_SOURCES CACHE)
  17. list(APPEND SM_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/smclass.cpp)
  18. #查找库文件,需要判断操作系统,位数
  19. if(CMAKE_SYSTEM_NAME MATCHES "Windows")
  20. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  21. if(CMAKE_BUILD_TYPE MATCHES "Debug")
  22. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/with_debug_info/libSM_DLL.lib)
  23. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/ucrtbased.dll)
  24. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/vcruntime140d.dll)
  25. else()
  26. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/libSM_DLL.lib)
  27. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/ucrtbase.dll)
  28. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/vcruntime140.dll)
  29. endif()
  30. elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
  31. if(CMAKE_BUILD_TYPE MATCHES "Debug")
  32. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/with_debug_info/libSM_DLL.lib)
  33. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/ucrtbased.dll)
  34. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/vcruntime140d.dll)
  35. else()
  36. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/libSM_DLL.lib)
  37. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/ucrtbase.dll)
  38. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/vcruntime140.dll)
  39. endif()
  40. endif()
  41. #添加Linux版本
  42. elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
  43. if(CMAKE_BUILD_TYPE MATCHES "Debug")
  44. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/linux/x64/libSM_Dll.so)
  45. else()
  46. list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/linux/x64/libSM_Dll.so)
  47. endif()
  48. endif()
  49. # message(STATUS "SM_LIB_LIBRARY: ${SM_LIB_LIBRARY}")
  50. # message(STATUS "SM_INCLUDE_DIR: ${SM_INCLUDE_DIR}")
  51. # message(STATUS "SM_SOURCES: ${SM_SOURCES}")
  52. # message(STATUS "SM_LIB_LIBRARY: ${SM_LIB_LIBRARY}")
  53. #设置查找到后的变量
  54. if(SM_INCLUDE_DIR AND SM_SOURCES AND SM_LIB_LIBRARY)
  55. set(SM_FOUND TRUE)
  56. set(SM_VERSION "1.1.0")
  57. # message(STATUS "include : SM_INCLUDE_DIR")
  58. # message(STATUS "source : SM_SOURCES_DIR")
  59. # message(STATUS "Library : SM_LIB_LIBRARY")
  60. message(STATUS "target_link_directories(External::sm)")
  61. else()
  62. set(SM_FOUND FALSE)
  63. endif()
  64. message(STATUS "SM_LIBRARY FOUND: ${SM_FOUND}")
  65. message(STATUS "SM_LIBRARY Version: ${SM_VERSION}")
  66. message(STATUS "--------------------------------------------------")
  67. #导入目标
  68. if(SM_FOUND)
  69. if(NOT TARGET External::sm)
  70. add_library(External::sm UNKNOWN IMPORTED)
  71. #添加头文件
  72. set_target_properties(External::sm PROPERTIES
  73. INTERFACE_INCLUDE_DIRECTORIES "${SM_INCLUDE_DIR}")
  74. #添加库文件
  75. set_target_properties(External::sm PROPERTIES
  76. IMPORTED_LOCATION "${SM_LIB_LIBRARY}")
  77. #添加spdlog需要的依赖库
  78. # set_target_properties(External::sm PROPERTIES
  79. # INTERFACE_LINK_LIBRARIES "pthread")
  80. #添加源文件
  81. set_target_properties(External::sm PROPERTIES
  82. INTERFACE_SOURCES "${SM_SOURCES}")
  83. endif()
  84. endif()
  85. # 标记这些变量为高级变量
  86. mark_as_advanced(
  87. SM_INCLUDE_DIR
  88. SM_LIB_LIBRARY
  89. SM_SOURCES
  90. )